Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1716881 > unrolled thread

[PATCH] mt7601u: check memory allocation failure

Started byChristophe JAILLET <christophe.jaillet@wanadoo.fr>
First post2017-08-21 23:10 +0200
Last post2017-08-22 00:10 +0200
Articles 4 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] mt7601u: check memory allocation failure Christophe JAILLET <christophe.jaillet@wanadoo.fr> - 2017-08-21 23:10 +0200
    Re: [PATCH] mt7601u: check memory allocation failure Jakub Kicinski <kubakici@wp.pl> - 2017-08-21 23:40 +0200
      Re: [PATCH] mt7601u: check memory allocation failure Jakub Kicinski <kubakici@wp.pl> - 2017-08-21 23:50 +0200
        Re: [PATCH] mt7601u: check memory allocation failure Christophe JAILLET <christophe.jaillet@wanadoo.fr> - 2017-08-22 00:10 +0200

#1716881 — [PATCH] mt7601u: check memory allocation failure

FromChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Date2017-08-21 23:10 +0200
Subject[PATCH] mt7601u: check memory allocation failure
Message-ID<uh27n-12T-15@gated-at.bofh.it>
Check memory allocation failure and return -ENOMEM in such a case, as
already done a few lines below

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
 drivers/net/wireless/mediatek/mt7601u/dma.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/net/wireless/mediatek/mt7601u/dma.c b/drivers/net/wireless/mediatek/mt7601u/dma.c
index 660267b359e4..fa0173579d32 100644
--- a/drivers/net/wireless/mediatek/mt7601u/dma.c
+++ b/drivers/net/wireless/mediatek/mt7601u/dma.c
@@ -484,6 +484,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]))
-- 
2.11.0

[toc] | [next] | [standalone]


#1716892

FromJakub Kicinski <kubakici@wp.pl>
Date2017-08-21 23:40 +0200
Message-ID<uh2Aq-1cx-21@gated-at.bofh.it>
In reply to#1716881
On Mon, 21 Aug 2017 22:59:56 +0200, Christophe JAILLET wrote:
> Check memory allocation failure and return -ENOMEM in such a case, as
> already done a few lines below
> 
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>

Acked-by: Jakub Kicinski <kubakici@wp.pl>

Thanks!

[toc] | [prev] | [next] | [standalone]


#1716899

FromJakub Kicinski <kubakici@wp.pl>
Date2017-08-21 23:50 +0200
Message-ID<uh2K6-1hN-21@gated-at.bofh.it>
In reply to#1716892
On Mon, 21 Aug 2017 14:34:30 -0700, Jakub Kicinski wrote:
> On Mon, 21 Aug 2017 22:59:56 +0200, Christophe JAILLET wrote:
> > Check memory allocation failure and return -ENOMEM in such a case, as
> > already done a few lines below
> > 
> > Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>  
> 
> Acked-by: Jakub Kicinski <kubakici@wp.pl>

Wait, I take that back.  This code is a bit weird.  We would return an
error, then mt7601u_dma_init() will call mt7601u_free_tx_queue() which
doesn't check for tx_q == NULL condition.

Looks like mt7601u_free_tx() has to check for dev->tx_q == NULL and
return early if that's the case.  Or mt7601u_alloc_tx() should really
clean things up on it's own on failure.  Ugh.

[toc] | [prev] | [next] | [standalone]


#1716909

FromChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Date2017-08-22 00:10 +0200
Message-ID<uh33r-1Dm-15@gated-at.bofh.it>
In reply to#1716899
Le 21/08/2017 à 23:41, Jakub Kicinski a écrit :
> On Mon, 21 Aug 2017 14:34:30 -0700, Jakub Kicinski wrote:
>> On Mon, 21 Aug 2017 22:59:56 +0200, Christophe JAILLET wrote:
>>> Check memory allocation failure and return -ENOMEM in such a case, as
>>> already done a few lines below
>>>
>>> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
>> Acked-by: Jakub Kicinski <kubakici@wp.pl>
> Wait, I take that back.  This code is a bit weird.  We would return an
> error, then mt7601u_dma_init() will call mt7601u_free_tx_queue() which
> doesn't check for tx_q == NULL condition.
>
> Looks like mt7601u_free_tx() has to check for dev->tx_q == NULL and
> return early if that's the case.  Or mt7601u_alloc_tx() should really
> clean things up on it's own on failure.  Ugh.
>
You are right. Thanks for the review.

I've sent a v2 which updates 'mt7601u_free_tx()'.
Doing so sounds more in line with the spirit of this code.

CJ

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web