diff options
author | Antonio Quartulli <antonio@meshcoding.com> | 2014-05-24 00:43:47 -0400 |
---|---|---|
committer | Antonio Quartulli <antonio@meshcoding.com> | 2014-08-04 10:02:10 -0400 |
commit | 0185dda640a704ce41ca1489c6775451c5ff3dcf (patch) | |
tree | fd50f60be3bc3c506618f13c14d4a1794414ff19 /net/batman-adv | |
parent | e6b92c25d20c64c271ef429bba8febeefb848b5b (diff) |
batman-adv: prefer kmalloc_array to kmalloc when possible
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>
Diffstat (limited to 'net/batman-adv')
-rw-r--r-- | net/batman-adv/bat_iv_ogm.c | 13 | ||||
-rw-r--r-- | net/batman-adv/distributed-arp-table.c | 3 | ||||
-rw-r--r-- | net/batman-adv/hash.c | 6 |
3 files changed, 12 insertions, 10 deletions
diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c index f04224c32005..1e8053976e83 100644 --- a/net/batman-adv/bat_iv_ogm.c +++ b/net/batman-adv/bat_iv_ogm.c | |||
@@ -108,14 +108,15 @@ static int batadv_iv_ogm_orig_add_if(struct batadv_orig_node *orig_node, | |||
108 | int max_if_num) | 108 | int max_if_num) |
109 | { | 109 | { |
110 | void *data_ptr; | 110 | void *data_ptr; |
111 | size_t data_size, old_size; | 111 | size_t old_size; |
112 | int ret = -ENOMEM; | 112 | int ret = -ENOMEM; |
113 | 113 | ||
114 | spin_lock_bh(&orig_node->bat_iv.ogm_cnt_lock); | 114 | spin_lock_bh(&orig_node->bat_iv.ogm_cnt_lock); |
115 | 115 | ||
116 | data_size = max_if_num * sizeof(unsigned long) * BATADV_NUM_WORDS; | ||
117 | old_size = (max_if_num - 1) * sizeof(unsigned long) * BATADV_NUM_WORDS; | 116 | old_size = (max_if_num - 1) * sizeof(unsigned long) * BATADV_NUM_WORDS; |
118 | data_ptr = kmalloc(data_size, GFP_ATOMIC); | 117 | data_ptr = kmalloc_array(max_if_num, |
118 | BATADV_NUM_WORDS * sizeof(unsigned long), | ||
119 | GFP_ATOMIC); | ||
119 | if (!data_ptr) | 120 | if (!data_ptr) |
120 | goto unlock; | 121 | goto unlock; |
121 | 122 | ||
@@ -123,7 +124,7 @@ static int batadv_iv_ogm_orig_add_if(struct batadv_orig_node *orig_node, | |||
123 | kfree(orig_node->bat_iv.bcast_own); | 124 | kfree(orig_node->bat_iv.bcast_own); |
124 | orig_node->bat_iv.bcast_own = data_ptr; | 125 | orig_node->bat_iv.bcast_own = data_ptr; |
125 | 126 | ||
126 | data_ptr = kmalloc(max_if_num * sizeof(uint8_t), GFP_ATOMIC); | 127 | data_ptr = kmalloc_array(max_if_num, sizeof(uint8_t), GFP_ATOMIC); |
127 | if (!data_ptr) { | 128 | if (!data_ptr) { |
128 | kfree(orig_node->bat_iv.bcast_own); | 129 | kfree(orig_node->bat_iv.bcast_own); |
129 | goto unlock; | 130 | goto unlock; |
@@ -164,7 +165,7 @@ static int batadv_iv_ogm_orig_del_if(struct batadv_orig_node *orig_node, | |||
164 | goto free_bcast_own; | 165 | goto free_bcast_own; |
165 | 166 | ||
166 | chunk_size = sizeof(unsigned long) * BATADV_NUM_WORDS; | 167 | chunk_size = sizeof(unsigned long) * BATADV_NUM_WORDS; |
167 | data_ptr = kmalloc(max_if_num * chunk_size, GFP_ATOMIC); | 168 | data_ptr = kmalloc_array(max_if_num, chunk_size, GFP_ATOMIC); |
168 | if (!data_ptr) | 169 | if (!data_ptr) |
169 | goto unlock; | 170 | goto unlock; |
170 | 171 | ||
@@ -183,7 +184,7 @@ free_bcast_own: | |||
183 | if (max_if_num == 0) | 184 | if (max_if_num == 0) |
184 | goto free_own_sum; | 185 | goto free_own_sum; |
185 | 186 | ||
186 | data_ptr = kmalloc(max_if_num * sizeof(uint8_t), GFP_ATOMIC); | 187 | data_ptr = kmalloc_array(max_if_num, sizeof(uint8_t), GFP_ATOMIC); |
187 | if (!data_ptr) { | 188 | if (!data_ptr) { |
188 | kfree(orig_node->bat_iv.bcast_own); | 189 | kfree(orig_node->bat_iv.bcast_own); |
189 | goto unlock; | 190 | goto unlock; |
diff --git a/net/batman-adv/distributed-arp-table.c b/net/batman-adv/distributed-arp-table.c index f2c066b21716..b5981113c9a7 100644 --- a/net/batman-adv/distributed-arp-table.c +++ b/net/batman-adv/distributed-arp-table.c | |||
@@ -537,7 +537,8 @@ batadv_dat_select_candidates(struct batadv_priv *bat_priv, __be32 ip_dst) | |||
537 | if (!bat_priv->orig_hash) | 537 | if (!bat_priv->orig_hash) |
538 | return NULL; | 538 | return NULL; |
539 | 539 | ||
540 | res = kmalloc(BATADV_DAT_CANDIDATES_NUM * sizeof(*res), GFP_ATOMIC); | 540 | res = kmalloc_array(BATADV_DAT_CANDIDATES_NUM, sizeof(*res), |
541 | GFP_ATOMIC); | ||
541 | if (!res) | 542 | if (!res) |
542 | return NULL; | 543 | return NULL; |
543 | 544 | ||
diff --git a/net/batman-adv/hash.c b/net/batman-adv/hash.c index 63bdf7e94f1e..7c1c63080e20 100644 --- a/net/batman-adv/hash.c +++ b/net/batman-adv/hash.c | |||
@@ -46,12 +46,12 @@ struct batadv_hashtable *batadv_hash_new(uint32_t size) | |||
46 | if (!hash) | 46 | if (!hash) |
47 | return NULL; | 47 | return NULL; |
48 | 48 | ||
49 | hash->table = kmalloc(sizeof(*hash->table) * size, GFP_ATOMIC); | 49 | hash->table = kmalloc_array(size, sizeof(*hash->table), GFP_ATOMIC); |
50 | if (!hash->table) | 50 | if (!hash->table) |
51 | goto free_hash; | 51 | goto free_hash; |
52 | 52 | ||
53 | hash->list_locks = kmalloc(sizeof(*hash->list_locks) * size, | 53 | hash->list_locks = kmalloc_array(size, sizeof(*hash->list_locks), |
54 | GFP_ATOMIC); | 54 | GFP_ATOMIC); |
55 | if (!hash->list_locks) | 55 | if (!hash->list_locks) |
56 | goto free_table; | 56 | goto free_table; |
57 | 57 | ||