Message ID | 3174f3bc-f83f-4009-b062-45eadb5c73d6@kili.mountain (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | btrfs: scrub: use safer allocation function in init_scrub_stripe() | expand |
On 2023/4/6 16:56, Dan Carpenter wrote: > It's just always better to use kcalloc() instead of open coding the > size calculation. > > Signed-off-by: Dan Carpenter <error27@gmail.com> Reviewed-by: Qu Wenruo <wqu@suse.com> Another thing I always forgot... Thanks, Qu > --- > fs/btrfs/scrub.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c > index ccb4f58ae307..6afb0abc83ce 100644 > --- a/fs/btrfs/scrub.c > +++ b/fs/btrfs/scrub.c > @@ -254,7 +254,7 @@ static int init_scrub_stripe(struct btrfs_fs_info *fs_info, > if (!stripe->sectors) > goto error; > > - stripe->csums = kzalloc((BTRFS_STRIPE_LEN >> fs_info->sectorsize_bits) * > + stripe->csums = kcalloc((BTRFS_STRIPE_LEN >> fs_info->sectorsize_bits), > fs_info->csum_size, GFP_KERNEL); > if (!stripe->csums) > goto error;
On Thu, Apr 06, 2023 at 11:56:44AM +0300, Dan Carpenter wrote: > It's just always better to use kcalloc() instead of open coding the > size calculation. > > Signed-off-by: Dan Carpenter <error27@gmail.com> Folded to the patch, thanks.
On Thu, Apr 06, 2023 at 11:56:44AM +0300, Dan Carpenter wrote: > It's just always better to use kcalloc() instead of open coding the > + stripe->csums = kcalloc((BTRFS_STRIPE_LEN >> fs_info->sectorsize_bits), The inner braces can and should go away now.
On Thu, Apr 06, 2023 at 08:13:17AM -0700, Christoph Hellwig wrote: > On Thu, Apr 06, 2023 at 11:56:44AM +0300, Dan Carpenter wrote: > > It's just always better to use kcalloc() instead of open coding the > > + stripe->csums = kcalloc((BTRFS_STRIPE_LEN >> fs_info->sectorsize_bits), > > The inner braces can and should go away now. Right, thanks, commit updated.
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c index ccb4f58ae307..6afb0abc83ce 100644 --- a/fs/btrfs/scrub.c +++ b/fs/btrfs/scrub.c @@ -254,7 +254,7 @@ static int init_scrub_stripe(struct btrfs_fs_info *fs_info, if (!stripe->sectors) goto error; - stripe->csums = kzalloc((BTRFS_STRIPE_LEN >> fs_info->sectorsize_bits) * + stripe->csums = kcalloc((BTRFS_STRIPE_LEN >> fs_info->sectorsize_bits), fs_info->csum_size, GFP_KERNEL); if (!stripe->csums) goto error;
It's just always better to use kcalloc() instead of open coding the size calculation. Signed-off-by: Dan Carpenter <error27@gmail.com> --- fs/btrfs/scrub.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)