mt7601u: check memory allocation failure
authorChristophe Jaillet <christophe.jaillet@wanadoo.fr>
Mon, 21 Aug 2017 22:06:17 +0000 (00:06 +0200)
committerKalle Valo <kvalo@codeaurora.org>
Thu, 24 Aug 2017 09:54:33 +0000 (12:54 +0300)
Check memory allocation failure and return -ENOMEM in such a case, as
already done a few lines below.

As 'dev->tx_q' can be NULL, we also need to check for that in
'mt7601u_free_tx()', and return early.

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Acked-by: Jakub Kicinski <kubakici@wp.pl>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
drivers/net/wireless/mediatek/mt7601u/dma.c

index 660267b359e48d7b0cd85011d3f2e406c9bd64df..7f3e3983b781d72af83b0fc47006b1a2ff34078c 100644 (file)
@@ -457,6 +457,9 @@ static void mt7601u_free_tx(struct mt7601u_dev *dev)
 {
        int i;
 
+       if (!dev->tx_q)
+               return;
+
        for (i = 0; i < __MT_EP_OUT_MAX; i++)
                mt7601u_free_tx_queue(&dev->tx_q[i]);
 }
@@ -484,6 +487,8 @@ static int mt7601u_alloc_tx(struct mt7601u_dev *dev)
 
        dev->tx_q = devm_kcalloc(dev->dev, __MT_EP_OUT_MAX,
                                 sizeof(*dev->tx_q), GFP_KERNEL);
+       if (!dev->tx_q)
+               return -ENOMEM;
 
        for (i = 0; i < __MT_EP_OUT_MAX; i++)
                if (mt7601u_alloc_tx_queue(dev, &dev->tx_q[i]))