btrfs: Replace kmalloc with kmalloc_array
authorDulshani Gunawardhana <dulshani.gunawardhana89@gmail.com>
Thu, 31 Oct 2013 05:02:18 +0000 (10:32 +0530)
committerChris Mason <chris.mason@fusionio.com>
Tue, 12 Nov 2013 03:12:22 +0000 (22:12 -0500)
Replace kmalloc(size * nr, ) with kmalloc_array(nr, size), thus making
it easier to check is that the calculation doesn't wrap or return a smaller allocation

Signed-off-by: Dulshani Gunawardhana <dulshani.gunawardhana89@gmail.com>
Reviewed-by: Zach Brown <zab@redhat.com>
Signed-off-by: Josef Bacik <jbacik@fusionio.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
fs/btrfs/delayed-inode.c
fs/btrfs/ioctl.c
fs/btrfs/super.c
fs/btrfs/volumes.c

index 2bb8e1a988a1f2b62923416be59201bf803a885f..8d292fbae659eff6a65bd7a8c255d741d998635e 100644 (file)
@@ -770,13 +770,13 @@ static int btrfs_batch_insert_items(struct btrfs_root *root,
         */
        btrfs_set_path_blocking(path);
 
-       keys = kmalloc(sizeof(struct btrfs_key) * nitems, GFP_NOFS);
+       keys = kmalloc_array(nitems, sizeof(struct btrfs_key), GFP_NOFS);
        if (!keys) {
                ret = -ENOMEM;
                goto out;
        }
 
-       data_size = kmalloc(sizeof(u32) * nitems, GFP_NOFS);
+       data_size = kmalloc_array(nitems, sizeof(u32), GFP_NOFS);
        if (!data_size) {
                ret = -ENOMEM;
                goto error;
index 78d20482b72a2d247af8a53f574d7ca4f0b246c5..3712ef86ca82fb46df6a0b121b5bd70989e49489 100644 (file)
@@ -1198,7 +1198,7 @@ int btrfs_defrag_file(struct inode *inode, struct file *file,
                ra = &file->f_ra;
        }
 
-       pages = kmalloc(sizeof(struct page *) * max_cluster,
+       pages = kmalloc_array(max_cluster, sizeof(struct page *),
                        GFP_NOFS);
        if (!pages) {
                ret = -ENOMEM;
index c9079db7441e6878ec1fed0b554ff8ca0360cca4..1de6d4d67431cfe589f3301b55fb30b73d785ac0 100644 (file)
@@ -1470,7 +1470,7 @@ static int btrfs_calc_avail_data_space(struct btrfs_root *root, u64 *free_bytes)
        nr_devices = fs_info->fs_devices->open_devices;
        BUG_ON(!nr_devices);
 
-       devices_info = kmalloc(sizeof(*devices_info) * nr_devices,
+       devices_info = kmalloc_array(nr_devices, sizeof(*devices_info),
                               GFP_NOFS);
        if (!devices_info)
                return -ENOMEM;
index 3c16da51348fa28ee1e250d178ca9c06fee95af3..0db63709786291731aa3e465dd20c46830890311 100644 (file)
@@ -4901,7 +4901,7 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw,
                        num_stripes = map->num_stripes;
                        max_errors = nr_parity_stripes(map);
 
-                       raid_map = kmalloc(sizeof(u64) * num_stripes,
+                       raid_map = kmalloc_array(num_stripes, sizeof(u64),
                                           GFP_NOFS);
                        if (!raid_map) {
                                ret = -ENOMEM;