regmap: replace kmalloc with kmalloc_array
authorlixiubo <lixiubo@cmss.chinamobile.com>
Fri, 20 Nov 2015 10:06:30 +0000 (18:06 +0800)
committerMark Brown <broonie@kernel.org>
Fri, 20 Nov 2015 12:27:59 +0000 (12:27 +0000)
Replace kmalloc with specialized function kmalloc_array when the size
is a multiplication of : number * size

Signed-off-by: lixiubo <lixiubo@cmss.chinamobile.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/base/regmap/regcache-lzo.c
drivers/base/regmap/regcache-rbtree.c
drivers/base/regmap/regmap-irq.c

index 52f69381c0700a24c3253fdbb1dff89fe8e74a89..6f77d7319fc6dd35182fecefcaa56a4650fed65f 100644 (file)
@@ -152,8 +152,8 @@ static int regcache_lzo_init(struct regmap *map)
         * that register.
         */
        bmp_size = map->num_reg_defaults_raw;
-       sync_bmp = kmalloc(BITS_TO_LONGS(bmp_size) * sizeof(long),
-                          GFP_KERNEL);
+       sync_bmp = kmalloc_array(BITS_TO_LONGS(bmp_size), sizeof(long),
+                                GFP_KERNEL);
        if (!sync_bmp) {
                ret = -ENOMEM;
                goto err;
index 3b6cfede2fd9f0b2a5f69d5ed786a7100f6b23a0..9d7ced559cba88fbd001be71393fb67f5a7e4d32 100644 (file)
@@ -361,8 +361,8 @@ regcache_rbtree_node_alloc(struct regmap *map, unsigned int reg)
                rbnode->base_reg = reg;
        }
 
-       rbnode->block = kmalloc(rbnode->blklen * map->cache_word_size,
-                               GFP_KERNEL);
+       rbnode->block = kmalloc_array(rbnode->blklen, map->cache_word_size,
+                                     GFP_KERNEL);
        if (!rbnode->block)
                goto err_free;
 
index 4ebbe21ded822e9c4261b0d069fbb4c5bc744ee6..4d2cb21254aaca8cfe64eba1333ac28a8902a49e 100644 (file)
@@ -422,8 +422,9 @@ int regmap_add_irq_chip(struct regmap *map, int irq, int irq_flags,
 
        if (!map->use_single_read && map->reg_stride == 1 &&
            d->irq_reg_stride == 1) {
-               d->status_reg_buf = kmalloc(map->format.val_bytes *
-                                           chip->num_regs, GFP_KERNEL);
+               d->status_reg_buf = kmalloc_array(chip->num_regs,
+                                                 map->format.val_bytes,
+                                                 GFP_KERNEL);
                if (!d->status_reg_buf)
                        goto err_alloc;
        }