Re: [PATCH v2] fs/ntfs3: Use kcalloc/kmalloc_array over kzalloc/kmalloc

Kari Argillander
2021-08-17T23:44:03Z

On Tue, Aug 17, 2021 at 04:12:08PM -0700, Joe Perches wrote:
> On 2021-08-17 12:38, Kari Argillander wrote:
> > Use kcalloc/kmalloc_array over kzalloc/kmalloc when we allocate array.
> > Checkpatch found these after we did not use our own defined allocation
> > wrappers.
> []
> > diff --git 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 = kcalloc(pages_per_frame, sizeof(struct page *), GFP_NOFS);
>
> This is not an exact transformation.
> This allocates zeroed memory.
> Use kmalloc_array here instead.

Yeah. Thank you so much. I actually use kmalloc_array, but mistakes were
made and this was result. Thank you for reviewing.