[OPW,kernel] btrfs-progs: replace kmalloc with kmalloc_array
diff mbox

Message ID 20131102183352.GA3073@dev
State Changes Requested
Headers show

Commit Message

C. Koppelt Nov. 2, 2013, 6:33 p.m. UTC
this patch replaces replace kmalloc(size * nr, ) with kmalloc_array(nr,
size) in ctree.c

Signed-off-by: C. Koppelt <opw.chk@gmail.com>
---
 ctree.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Josh Triplett Nov. 2, 2013, 8:02 p.m. UTC | #1
On Sat, Nov 02, 2013 at 07:33:52PM +0100, C. Koppelt wrote:
> this patch replaces replace kmalloc(size * nr, ) with kmalloc_array(nr,
> size) in ctree.c
> 
> Signed-off-by: C. Koppelt <opw.chk@gmail.com>
> ---
>  ctree.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/ctree.c b/ctree.c
> index fdb1bcb..ae2c31c 100644
> --- a/ctree.c
> +++ b/ctree.c
> @@ -20,6 +20,7 @@
>  #include "transaction.h"
>  #include "print-tree.h"
>  #include "repair.h"
> +#include "slab.h"
>  
>  static int split_node(struct btrfs_trans_handle *trans, struct btrfs_root
>  		      *root, struct btrfs_path *path, int level);
> @@ -82,7 +83,7 @@ int btrfs_copy_root(struct btrfs_trans_handle *trans,
>  	struct btrfs_root *new_root;
>  	struct btrfs_disk_key disk_key;
>  
> -	new_root = kmalloc(sizeof(*new_root), GFP_NOFS);
> +	new_root = kmalloc_array(GFP_NOFS, sizeof(*new_root));

kmalloc_array takes three arguments, not two, and the first argument is
not the gfp_t.  Please *always* build-test your patches.

In any case, this doesn't look like an appropriate case to use
kmalloc_array; this isn't allocating an array, and there's no
multiplication here.

- Josh Triplett

Patch
diff mbox

diff --git a/ctree.c b/ctree.c
index fdb1bcb..ae2c31c 100644
--- a/ctree.c
+++ b/ctree.c
@@ -20,6 +20,7 @@ 
 #include "transaction.h"
 #include "print-tree.h"
 #include "repair.h"
+#include "slab.h"
 
 static int split_node(struct btrfs_trans_handle *trans, struct btrfs_root
 		      *root, struct btrfs_path *path, int level);
@@ -82,7 +83,7 @@  int btrfs_copy_root(struct btrfs_trans_handle *trans,
 	struct btrfs_root *new_root;
 	struct btrfs_disk_key disk_key;
 
-	new_root = kmalloc(sizeof(*new_root), GFP_NOFS);
+	new_root = kmalloc_array(GFP_NOFS, sizeof(*new_root));
 	if (!new_root)
 		return -ENOMEM;