]> git.ipfire.org Git - people/ms/linux.git/commitdiff
net: lantiq_xrx200: confirm skb is allocated before using
authorAleksander Jan Bajkowski <olek2@wp.pl>
Wed, 24 Aug 2022 21:54:06 +0000 (23:54 +0200)
committerJakub Kicinski <kuba@kernel.org>
Thu, 25 Aug 2022 19:41:38 +0000 (12:41 -0700)
xrx200_hw_receive() assumes build_skb() always works and goes straight
to skb_reserve(). However, build_skb() can fail under memory pressure.

Add a check in case build_skb() failed to allocate and return NULL.

Fixes: e015593573b3 ("net: lantiq_xrx200: convert to build_skb")
Reported-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: Aleksander Jan Bajkowski <olek2@wp.pl>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/lantiq_xrx200.c

index 5edb68a8aab1ececb61a652ca6163a4302beabd7..89314b645c822b851a1b6bc981079f48f412e97b 100644 (file)
@@ -239,6 +239,12 @@ static int xrx200_hw_receive(struct xrx200_chan *ch)
        }
 
        skb = build_skb(buf, priv->rx_skb_size);
+       if (!skb) {
+               skb_free_frag(buf);
+               net_dev->stats.rx_dropped++;
+               return -ENOMEM;
+       }
+
        skb_reserve(skb, NET_SKB_PAD);
        skb_put(skb, len);