Skip to contentSkip to conversation

Btrfs: use correct args for kcalloc in btrfsic_read_block

PATCH Superseded Liu Bo 3 participants 4 messages Sep 7, 2018 – Sep 8, 2018 Btrfs file system

lore
Share & tools
lore

Liu Bo

author
#0 lore raw

PATCH 1/1 Btrfs: use correct args for kcalloc in btrfsic_read_block

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.

---
 fs/btrfs/check-integrity.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/btrfs/check-integrity.c +3 -3
index 833cf3c35b4d..651b75939ce9 100644
@@ -1594,6 +1594,7 @@ static int btrfsic_read_block(struct btrfsic_state *state,
 {
 	unsigned int num_pages;
 	unsigned int i;
+	u64 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;
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 18 lines · Liu Bo

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.

---
 fs/btrfs/check-integrity.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/btrfs/check-integrity.c +0 -0
index 833cf3c35b4d..651b75939ce9 100644

fs/btrfs/check-integrity.c static int btrfsic_read_block(struct btrfsic_state *state, · line 1597

Quoted 4 lines
fs/btrfs/check-integrity.c +1 -0
@@ -1594,6 +1594,7 @@ static int btrfsic_read_block(struct btrfsic_state *state,
 {
 	unsigned int num_pages;
 	unsigned int i;
+	u64 size;

size_t?

Besides that, Reviewed-by: Omar Sandoval <[email protected]>

Quoted 18 lines
fs/btrfs/check-integrity.c +2 -3
 	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;
Signature · 1 line
1.8.3.1
#2 lore raw
Quoted 14 lines · Omar Sandoval
Quoted 13 lines · Liu Bo

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.

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

fs/btrfs/check-integrity.c static int btrfsic_read_block(struct btrfsic_state *state, · line 1597

Quoted 9 lines
fs/btrfs/check-integrity.c +1 -0
index 833cf3c35b4d..651b75939ce9 100644
@@ -1594,6 +1594,7 @@ static int btrfsic_read_block(struct btrfsic_state *state,
 {
      unsigned int num_pages;
      unsigned int i;
+     u64 size;

size_t?

oops, will update it.

thanks,
liubo

Quoted 20 lines

Besides that, Reviewed-by: Omar Sandoval <[email protected]>

Quoted 18 lines
fs/btrfs/check-integrity.c +2 -4
      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;
--

1.8.3.1

author
#3 lore raw

PATCH v2 1/1 Btrfs: use correct args for kcalloc in btrfsic_read_block

In reply to Liu Bo

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.

---
v2: use size_t to be consistent with kcalloc()'s prototype.

 fs/btrfs/check-integrity.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/btrfs/check-integrity.c +3 -3
index 833cf3c35b4d..2e43fba44035 100644
@@ -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;
Signature · 1 line
1.8.3.1