Skip to content

Commit

Permalink
ATM, Solos PCI ADSL2+: Don't deref NULL pointer if net_ratelimit() an…
Browse files Browse the repository at this point in the history
…d alloc_skb() interact badly.

If alloc_skb() fails to allocate memory and returns NULL then we want to
return -ENOMEM from drivers/atm/solos-pci.c::popen() regardless of the
value of net_ratelimit(). The way the code is today, we may not return if
net_ratelimit() returns 0, then we'll proceed to pass a NULL pointer to
skb_put() which will blow up in our face.
This patch ensures that we always return -ENOMEM on alloc_skb() failure
and only let the dev_warn() be controlled by the value of net_ratelimit().

Signed-off-by: Jesper Juhl <jj@chaosbits.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Jesper Juhl authored and David S. Miller committed Feb 14, 2011
1 parent 5b89db0 commit da1ab3e
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions drivers/atm/solos-pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -866,8 +866,9 @@ static int popen(struct atm_vcc *vcc)
}

skb = alloc_skb(sizeof(*header), GFP_ATOMIC);
if (!skb && net_ratelimit()) {
dev_warn(&card->dev->dev, "Failed to allocate sk_buff in popen()\n");
if (!skb) {
if (net_ratelimit())
dev_warn(&card->dev->dev, "Failed to allocate sk_buff in popen()\n");
return -ENOMEM;
}
header = (void *)skb_put(skb, sizeof(*header));
Expand Down

0 comments on commit da1ab3e

Please sign in to comment.