diff mbox series

[v2] Btrfs: use correct args for kcalloc in btrfsic_read_block

Message ID 1536352900-125878-1-git-send-email-bo.liu@linux.alibaba.com (mailing list archive)
State New, archived
Headers show
Series [v2] Btrfs: use correct args for kcalloc in btrfsic_read_block | expand

Commit Message

Liu Bo Sept. 7, 2018, 8:41 p.m. UTC
kcalloc is defined as
kcalloc(size_t n, size_t size, gfp_t flags)

Although this won't cause problems in practice, btrfsic_read_block()
has switched n with size.

This updates btrfsic_read_block() to be correct in using kcalloc.

Reviewed-by: Omar Sandoval <osandov@fb.com>
Signed-off-by: Liu Bo <bo.liu@linux.alibaba.com>
---
v2: use size_t to be consistent with kcalloc()'s prototype.

 fs/btrfs/check-integrity.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

David Sterba Sept. 10, 2018, 6:30 p.m. UTC | #1
On Sat, Sep 08, 2018 at 04:41:40AM +0800, Liu Bo wrote:
> kcalloc is defined as
> kcalloc(size_t n, size_t size, gfp_t flags)
> 
> Although this won't cause problems in practice, btrfsic_read_block()
> has switched n with size.
> 
> This updates btrfsic_read_block() to be correct in using kcalloc.
> 
> Reviewed-by: Omar Sandoval <osandov@fb.com>
> Signed-off-by: Liu Bo <bo.liu@linux.alibaba.com>
> ---
> v2: use size_t to be consistent with kcalloc()'s prototype.

Added to misc-next, thanks.

>  fs/btrfs/check-integrity.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
> index 833cf3c35b4d..2e43fba44035 100644
> --- a/fs/btrfs/check-integrity.c
> +++ b/fs/btrfs/check-integrity.c
> @@ -1594,6 +1594,7 @@ static int btrfsic_read_block(struct btrfsic_state *state,
>  {
>  	unsigned int num_pages;
>  	unsigned int i;
> +	size_t size;
>  	u64 dev_bytenr;
>  	int ret;
>  
> @@ -1608,9 +1609,8 @@ static int btrfsic_read_block(struct btrfsic_state *state,
>  
>  	num_pages = (block_ctx->len + (u64)PAGE_SIZE - 1) >>
>  		    PAGE_SHIFT;
> -	block_ctx->mem_to_free = kcalloc(sizeof(*block_ctx->datav) +
> -						sizeof(*block_ctx->pagev),
> -					 num_pages, GFP_NOFS);
> +	size = sizeof(*block_ctx->datav) + sizeof(*block_ctx->pagev);

Though the use of a temporary variable is not necessary, it looks a bit
better than the long expression in the arguments.
diff mbox series

Patch

diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
index 833cf3c35b4d..2e43fba44035 100644
--- a/fs/btrfs/check-integrity.c
+++ b/fs/btrfs/check-integrity.c
@@ -1594,6 +1594,7 @@  static int btrfsic_read_block(struct btrfsic_state *state,
 {
 	unsigned int num_pages;
 	unsigned int i;
+	size_t size;
 	u64 dev_bytenr;
 	int ret;
 
@@ -1608,9 +1609,8 @@  static int btrfsic_read_block(struct btrfsic_state *state,
 
 	num_pages = (block_ctx->len + (u64)PAGE_SIZE - 1) >>
 		    PAGE_SHIFT;
-	block_ctx->mem_to_free = kcalloc(sizeof(*block_ctx->datav) +
-						sizeof(*block_ctx->pagev),
-					 num_pages, GFP_NOFS);
+	size = sizeof(*block_ctx->datav) + sizeof(*block_ctx->pagev);
+	block_ctx->mem_to_free = kcalloc(num_pages, size, GFP_NOFS);
 	if (!block_ctx->mem_to_free)
 		return -ENOMEM;
 	block_ctx->datav = block_ctx->mem_to_free;