From: Kari Argillander kari.argillander@gmail.com
mainline inclusion from mainline-v5.15 commit 345482bc431f6492beb464696341626057f67771 category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I4G67J?from=project-issue CVE: NA
----------------------------------------------------------------------
Use kcalloc/kmalloc_array over kzalloc/kmalloc when we allocate array. Checkpatch found these after we did not use our own defined allocation wrappers.
Reviewed-by: Christoph Hellwig hch@lst.de Signed-off-by: Kari Argillander kari.argillander@gmail.com Signed-off-by: Konstantin Komarov almaz.alexandrovich@paragon-software.com Signed-off-by: Yin Xiujiang yinxiujiang@kylinos.cn --- fs/ntfs3/bitmap.c | 2 +- fs/ntfs3/file.c | 2 +- fs/ntfs3/frecord.c | 7 +++---- 3 files changed, 5 insertions(+), 6 deletions(-)
diff --git a/fs/ntfs3/bitmap.c b/fs/ntfs3/bitmap.c index d502bba323d0..2de05062c78b 100644 --- a/fs/ntfs3/bitmap.c +++ b/fs/ntfs3/bitmap.c @@ -683,7 +683,7 @@ int wnd_init(struct wnd_bitmap *wnd, struct super_block *sb, size_t nbits) if (!wnd->bits_last) wnd->bits_last = wbits;
- wnd->free_bits = kzalloc(wnd->nwnd * sizeof(u16), GFP_NOFS); + wnd->free_bits = kcalloc(wnd->nwnd, sizeof(u16), GFP_NOFS); if (!wnd->free_bits) return -ENOMEM;
diff --git a/fs/ntfs3/file.c b/fs/ntfs3/file.c index 8d27c520bec5..a959f6197c99 100644 --- a/fs/ntfs3/file.c +++ b/fs/ntfs3/file.c @@ -900,7 +900,7 @@ static ssize_t ntfs_compress_write(struct kiocb *iocb, struct iov_iter *from) return -EOPNOTSUPP; }
- pages = kmalloc(pages_per_frame * sizeof(struct page *), GFP_NOFS); + pages = kmalloc_array(pages_per_frame, sizeof(struct page *), GFP_NOFS); if (!pages) return -ENOMEM;
diff --git a/fs/ntfs3/frecord.c b/fs/ntfs3/frecord.c index 2f7d16543530..329bc76dfb09 100644 --- a/fs/ntfs3/frecord.c +++ b/fs/ntfs3/frecord.c @@ -2054,7 +2054,7 @@ int ni_readpage_cmpr(struct ntfs_inode *ni, struct page *page) idx = (vbo - frame_vbo) >> PAGE_SHIFT;
pages_per_frame = frame_size >> PAGE_SHIFT; - pages = kzalloc(pages_per_frame * sizeof(struct page *), GFP_NOFS); + pages = kcalloc(pages_per_frame, sizeof(struct page *), GFP_NOFS); if (!pages) { err = -ENOMEM; goto out; @@ -2137,7 +2137,7 @@ int ni_decompress_file(struct ntfs_inode *ni) frame_bits = ni_ext_compress_bits(ni); frame_size = 1u << frame_bits; pages_per_frame = frame_size >> PAGE_SHIFT; - pages = kzalloc(pages_per_frame * sizeof(struct page *), GFP_NOFS); + pages = kcalloc(pages_per_frame, sizeof(struct page *), GFP_NOFS); if (!pages) { err = -ENOMEM; goto out; @@ -2709,8 +2709,7 @@ int ni_write_frame(struct ntfs_inode *ni, struct page **pages, goto out; }
- pages_disk = kzalloc(pages_per_frame * sizeof(struct page *), - GFP_NOFS); + pages_disk = kcalloc(pages_per_frame, sizeof(struct page *), GFP_NOFS); if (!pages_disk) { err = -ENOMEM; goto out;