batman-adv: prefer kmalloc_array to kmalloc when possible
authorAntonio Quartulli <antonio@meshcoding.com>
Sat, 24 May 2014 04:43:47 +0000 (06:43 +0200)
committerAntonio Quartulli <antonio@meshcoding.com>
Mon, 4 Aug 2014 14:02:10 +0000 (16:02 +0200)
Reported by checkpatch with the following warning:
WARNING: Prefer kmalloc_array over kmalloc with multiply

Signed-off-by: Antonio Quartulli <antonio@meshcoding.com>
Signed-off-by: Marek Lindner <mareklindner@neomailbox.ch>
net/batman-adv/bat_iv_ogm.c
net/batman-adv/distributed-arp-table.c
net/batman-adv/hash.c

index f04224c32005aa9a732622805915fe9aead9ee3e..1e8053976e83dd8bcb03ee37b029fe6f7140d3e5 100644 (file)
@@ -108,14 +108,15 @@ static int batadv_iv_ogm_orig_add_if(struct batadv_orig_node *orig_node,
                                     int max_if_num)
 {
        void *data_ptr;
-       size_t data_size, old_size;
+       size_t old_size;
        int ret = -ENOMEM;
 
        spin_lock_bh(&orig_node->bat_iv.ogm_cnt_lock);
 
-       data_size = max_if_num * sizeof(unsigned long) * BATADV_NUM_WORDS;
        old_size = (max_if_num - 1) * sizeof(unsigned long) * BATADV_NUM_WORDS;
-       data_ptr = kmalloc(data_size, GFP_ATOMIC);
+       data_ptr = kmalloc_array(max_if_num,
+                                BATADV_NUM_WORDS * sizeof(unsigned long),
+                                GFP_ATOMIC);
        if (!data_ptr)
                goto unlock;
 
@@ -123,7 +124,7 @@ static int batadv_iv_ogm_orig_add_if(struct batadv_orig_node *orig_node,
        kfree(orig_node->bat_iv.bcast_own);
        orig_node->bat_iv.bcast_own = data_ptr;
 
-       data_ptr = kmalloc(max_if_num * sizeof(uint8_t), GFP_ATOMIC);
+       data_ptr = kmalloc_array(max_if_num, sizeof(uint8_t), GFP_ATOMIC);
        if (!data_ptr) {
                kfree(orig_node->bat_iv.bcast_own);
                goto unlock;
@@ -164,7 +165,7 @@ static int batadv_iv_ogm_orig_del_if(struct batadv_orig_node *orig_node,
                goto free_bcast_own;
 
        chunk_size = sizeof(unsigned long) * BATADV_NUM_WORDS;
-       data_ptr = kmalloc(max_if_num * chunk_size, GFP_ATOMIC);
+       data_ptr = kmalloc_array(max_if_num, chunk_size, GFP_ATOMIC);
        if (!data_ptr)
                goto unlock;
 
@@ -183,7 +184,7 @@ free_bcast_own:
        if (max_if_num == 0)
                goto free_own_sum;
 
-       data_ptr = kmalloc(max_if_num * sizeof(uint8_t), GFP_ATOMIC);
+       data_ptr = kmalloc_array(max_if_num, sizeof(uint8_t), GFP_ATOMIC);
        if (!data_ptr) {
                kfree(orig_node->bat_iv.bcast_own);
                goto unlock;
index f2c066b2171640c4092a60bc6fc8ef603baa5c09..b5981113c9a77a3d7546246dcec813545e6afdbf 100644 (file)
@@ -537,7 +537,8 @@ batadv_dat_select_candidates(struct batadv_priv *bat_priv, __be32 ip_dst)
        if (!bat_priv->orig_hash)
                return NULL;
 
-       res = kmalloc(BATADV_DAT_CANDIDATES_NUM * sizeof(*res), GFP_ATOMIC);
+       res = kmalloc_array(BATADV_DAT_CANDIDATES_NUM, sizeof(*res),
+                           GFP_ATOMIC);
        if (!res)
                return NULL;
 
index 63bdf7e94f1ef59964ee39f51a0d0b802b2ca586..7c1c63080e20362cd628251b37f44da446cdbdba 100644 (file)
@@ -46,12 +46,12 @@ struct batadv_hashtable *batadv_hash_new(uint32_t size)
        if (!hash)
                return NULL;
 
-       hash->table = kmalloc(sizeof(*hash->table) * size, GFP_ATOMIC);
+       hash->table = kmalloc_array(size, sizeof(*hash->table), GFP_ATOMIC);
        if (!hash->table)
                goto free_hash;
 
-       hash->list_locks = kmalloc(sizeof(*hash->list_locks) * size,
-                                  GFP_ATOMIC);
+       hash->list_locks = kmalloc_array(size, sizeof(*hash->list_locks),
+                                        GFP_ATOMIC);
        if (!hash->list_locks)
                goto free_table;