Skip to content

Commit

Permalink
drivers/net/wireless/p54/eeprom.c: Return -ENOMEM on memory allocatio…
Browse files Browse the repository at this point in the history
…n failure

In this code, 0 is returned on memory allocation failure, even though other
failures return -ENOMEM or other similar values.

A simplified version of the semantic match that finds this problem is as
follows: (http://coccinelle.lip6.fr/)

// <smpl>
@@
expression ret;
expression x,e1,e2,e3;
@@

ret = 0
... when != ret = e1
*x = \(kmalloc\|kcalloc\|kzalloc\)(...)
... when != ret = e2
if (x == NULL) { ... when != ret = e3
  return ret;
}
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>
Cc: <stable@kernel.org>
Acked-by: Christian Lamparter <chunkeey@googlemail.com>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
  • Loading branch information
Julia Lawall authored and John W. Linville committed Oct 15, 2010
1 parent 6cf9e99 commit 0d91f22
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion drivers/net/wireless/p54/eeprom.c
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,10 @@ static int p54_generate_channel_lists(struct ieee80211_hw *dev)
list->max_entries = max_channel_num;
list->channels = kzalloc(sizeof(struct p54_channel_entry) *
max_channel_num, GFP_KERNEL);
if (!list->channels)
if (!list->channels) {
ret = -ENOMEM;
goto free;
}

for (i = 0; i < max_channel_num; i++) {
if (i < priv->iq_autocal_len) {
Expand Down

0 comments on commit 0d91f22

Please sign in to comment.