diff mbox series

btrfs: scrub: use safer allocation function in init_scrub_stripe()

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

Commit Message

Dan Carpenter April 6, 2023, 8:56 a.m. UTC
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(-)

Comments

Qu Wenruo April 6, 2023, 9:10 a.m. UTC | #1
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;
David Sterba April 6, 2023, 2:37 p.m. UTC | #2
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.
Christoph Hellwig April 6, 2023, 3:13 p.m. UTC | #3
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.
David Sterba April 6, 2023, 4:06 p.m. UTC | #4
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 mbox series

Patch

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;