linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 wireless-drivers] mt76: mt7663u: fix memory leaks in mt7663u_probe
@ 2020-06-21 16:03 Lorenzo Bianconi
  2020-06-22 14:20 ` Kalle Valo
  2020-06-23  8:43 ` Kalle Valo
  0 siblings, 2 replies; 6+ messages in thread
From: Lorenzo Bianconi @ 2020-06-21 16:03 UTC (permalink / raw)
  To: kvalo; +Cc: linux-wireless, nbd, lorenzo.bianconi, sean.wang

Fix the two following memory leaks in mt7663u_probe:
1- if device power-own times out, remove ieee80211 hw device.
2- if mt76u queues allocation fails, remove pending urbs.

Fixes: eb99cc95c3b65 ("mt76: mt7615: introduce mt7663u support")
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
Changes since v1:
- properly set return value if device power-own fails
---
 .../net/wireless/mediatek/mt76/mt7615/usb.c   | 11 +++++-----
 drivers/net/wireless/mediatek/mt76/usb.c      | 22 ++++++++++++++-----
 2 files changed, 23 insertions(+), 10 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/usb.c b/drivers/net/wireless/mediatek/mt76/mt7615/usb.c
index a50077eb24d7..c7763e209e00 100644
--- a/drivers/net/wireless/mediatek/mt76/mt7615/usb.c
+++ b/drivers/net/wireless/mediatek/mt76/mt7615/usb.c
@@ -329,25 +329,26 @@ static int mt7663u_probe(struct usb_interface *usb_intf,
 	if (!mt76_poll_msec(dev, MT_CONN_ON_MISC, MT_TOP_MISC2_FW_PWR_ON,
 			    FW_STATE_PWR_ON << 1, 500)) {
 		dev_err(dev->mt76.dev, "Timeout for power on\n");
-		return -EIO;
+		ret = -EIO;
+		goto error;
 	}
 
 alloc_queues:
 	ret = mt76u_alloc_mcu_queue(&dev->mt76);
 	if (ret)
-		goto error;
+		goto error_free_q;
 
 	ret = mt76u_alloc_queues(&dev->mt76);
 	if (ret)
-		goto error;
+		goto error_free_q;
 
 	ret = mt7663u_register_device(dev);
 	if (ret)
-		goto error_freeq;
+		goto error_free_q;
 
 	return 0;
 
-error_freeq:
+error_free_q:
 	mt76u_queues_deinit(&dev->mt76);
 error:
 	mt76u_deinit(&dev->mt76);
diff --git a/drivers/net/wireless/mediatek/mt76/usb.c b/drivers/net/wireless/mediatek/mt76/usb.c
index fb97ea25b4d4..2e89b0514ff6 100644
--- a/drivers/net/wireless/mediatek/mt76/usb.c
+++ b/drivers/net/wireless/mediatek/mt76/usb.c
@@ -1066,11 +1066,16 @@ static int mt76u_alloc_tx(struct mt76_dev *dev)
 
 static void mt76u_free_tx(struct mt76_dev *dev)
 {
-	struct mt76_queue *q;
-	int i, j;
+	int i;
 
 	for (i = 0; i < IEEE80211_NUM_ACS; i++) {
+		struct mt76_queue *q;
+		int j;
+
 		q = dev->q_tx[i].q;
+		if (!q)
+			continue;
+
 		for (j = 0; j < q->ndesc; j++)
 			usb_free_urb(q->entry[j].urb);
 	}
@@ -1078,17 +1083,22 @@ static void mt76u_free_tx(struct mt76_dev *dev)
 
 void mt76u_stop_tx(struct mt76_dev *dev)
 {
-	struct mt76_queue_entry entry;
-	struct mt76_queue *q;
-	int i, j, ret;
+	int ret;
 
 	ret = wait_event_timeout(dev->tx_wait, !mt76_has_tx_pending(&dev->phy),
 				 HZ / 5);
 	if (!ret) {
+		struct mt76_queue_entry entry;
+		struct mt76_queue *q;
+		int i, j;
+
 		dev_err(dev->dev, "timed out waiting for pending tx\n");
 
 		for (i = 0; i < IEEE80211_NUM_ACS; i++) {
 			q = dev->q_tx[i].q;
+			if (!q)
+				continue;
+
 			for (j = 0; j < q->ndesc; j++)
 				usb_kill_urb(q->entry[j].urb);
 		}
@@ -1100,6 +1110,8 @@ void mt76u_stop_tx(struct mt76_dev *dev)
 		 */
 		for (i = 0; i < IEEE80211_NUM_ACS; i++) {
 			q = dev->q_tx[i].q;
+			if (!q)
+				continue;
 
 			/* Assure we are in sync with killed tasklet. */
 			spin_lock_bh(&q->lock);
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 wireless-drivers] mt76: mt7663u: fix memory leaks in mt7663u_probe
  2020-06-21 16:03 [PATCH v2 wireless-drivers] mt76: mt7663u: fix memory leaks in mt7663u_probe Lorenzo Bianconi
@ 2020-06-22 14:20 ` Kalle Valo
  2020-06-22 14:40   ` Lorenzo Bianconi
  2020-06-23  8:43 ` Kalle Valo
  1 sibling, 1 reply; 6+ messages in thread
From: Kalle Valo @ 2020-06-22 14:20 UTC (permalink / raw)
  To: Lorenzo Bianconi; +Cc: linux-wireless, nbd, lorenzo.bianconi, sean.wang

Lorenzo Bianconi <lorenzo@kernel.org> writes:

> Fix the two following memory leaks in mt7663u_probe:
> 1- if device power-own times out, remove ieee80211 hw device.
> 2- if mt76u queues allocation fails, remove pending urbs.

One logical change per patch, please. If you have to create a list of
changes in the commit log that's a good sign that you need to split the
patch :)

-- 
https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 wireless-drivers] mt76: mt7663u: fix memory leaks in mt7663u_probe
  2020-06-22 14:20 ` Kalle Valo
@ 2020-06-22 14:40   ` Lorenzo Bianconi
  2020-06-22 14:58     ` Kalle Valo
  0 siblings, 1 reply; 6+ messages in thread
From: Lorenzo Bianconi @ 2020-06-22 14:40 UTC (permalink / raw)
  To: Kalle Valo; +Cc: Lorenzo Bianconi, linux-wireless, nbd, sean.wang

[-- Attachment #1: Type: text/plain, Size: 722 bytes --]

> Lorenzo Bianconi <lorenzo@kernel.org> writes:
> 
> > Fix the two following memory leaks in mt7663u_probe:
> > 1- if device power-own times out, remove ieee80211 hw device.
> > 2- if mt76u queues allocation fails, remove pending urbs.
> 
> One logical change per patch, please. If you have to create a list of
> changes in the commit log that's a good sign that you need to split the
> patch :)

Hi Kalle,

both of them are memory leaks in the error path of the same routine (mt7663u_probe()).
Do I need to split them even in this case? If so I am fine with it.
Do I need to send a v3?

Regards,
Lorenzo

> 
> -- 
> https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 wireless-drivers] mt76: mt7663u: fix memory leaks in mt7663u_probe
  2020-06-22 14:40   ` Lorenzo Bianconi
@ 2020-06-22 14:58     ` Kalle Valo
  2020-06-22 15:03       ` Lorenzo Bianconi
  0 siblings, 1 reply; 6+ messages in thread
From: Kalle Valo @ 2020-06-22 14:58 UTC (permalink / raw)
  To: Lorenzo Bianconi; +Cc: Lorenzo Bianconi, linux-wireless, nbd, sean.wang

Lorenzo Bianconi <lorenzo.bianconi@redhat.com> writes:

>> Lorenzo Bianconi <lorenzo@kernel.org> writes:
>> 
>> > Fix the two following memory leaks in mt7663u_probe:
>> > 1- if device power-own times out, remove ieee80211 hw device.
>> > 2- if mt76u queues allocation fails, remove pending urbs.
>> 
>> One logical change per patch, please. If you have to create a list of
>> changes in the commit log that's a good sign that you need to split the
>> patch :)
>
> both of them are memory leaks in the error path of the same routine (mt7663u_probe()).
> Do I need to split them even in this case? If so I am fine with it.
> Do I need to send a v3?

Oh, I didn't notice that they were in the same function. So I guess this
sort of gray area and no need to send v3 because of this.

-- 
https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 wireless-drivers] mt76: mt7663u: fix memory leaks in mt7663u_probe
  2020-06-22 14:58     ` Kalle Valo
@ 2020-06-22 15:03       ` Lorenzo Bianconi
  0 siblings, 0 replies; 6+ messages in thread
From: Lorenzo Bianconi @ 2020-06-22 15:03 UTC (permalink / raw)
  To: Kalle Valo; +Cc: Lorenzo Bianconi, linux-wireless, nbd, sean.wang

[-- Attachment #1: Type: text/plain, Size: 1016 bytes --]

> Lorenzo Bianconi <lorenzo.bianconi@redhat.com> writes:
> 
> >> Lorenzo Bianconi <lorenzo@kernel.org> writes:
> >> 
> >> > Fix the two following memory leaks in mt7663u_probe:
> >> > 1- if device power-own times out, remove ieee80211 hw device.
> >> > 2- if mt76u queues allocation fails, remove pending urbs.
> >> 
> >> One logical change per patch, please. If you have to create a list of
> >> changes in the commit log that's a good sign that you need to split the
> >> patch :)
> >
> > both of them are memory leaks in the error path of the same routine (mt7663u_probe()).
> > Do I need to split them even in this case? If so I am fine with it.
> > Do I need to send a v3?
> 
> Oh, I didn't notice that they were in the same function. So I guess this
> sort of gray area and no need to send v3 because of this.

ack, I will take into account for the next time, thanks :)

Regards,
Lorenzo

> 
> -- 
> https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 wireless-drivers] mt76: mt7663u: fix memory leaks in mt7663u_probe
  2020-06-21 16:03 [PATCH v2 wireless-drivers] mt76: mt7663u: fix memory leaks in mt7663u_probe Lorenzo Bianconi
  2020-06-22 14:20 ` Kalle Valo
@ 2020-06-23  8:43 ` Kalle Valo
  1 sibling, 0 replies; 6+ messages in thread
From: Kalle Valo @ 2020-06-23  8:43 UTC (permalink / raw)
  To: Lorenzo Bianconi; +Cc: linux-wireless, nbd, lorenzo.bianconi, sean.wang

Lorenzo Bianconi <lorenzo@kernel.org> wrote:

> Fix the two following memory leaks in mt7663u_probe:
> 1- if device power-own times out, remove ieee80211 hw device.
> 2- if mt76u queues allocation fails, remove pending urbs.
> 
> Fixes: eb99cc95c3b65 ("mt76: mt7615: introduce mt7663u support")
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>

Patch applied to wireless-drivers.git, thanks.

b1e79d105516 mt76: mt7663u: fix memory leaks in mt7663u_probe

-- 
https://patchwork.kernel.org/patch/11616619/

https://wireless.wiki.kernel.org/en/developers/documentation/submittingpatches


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-06-23  8:43 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-21 16:03 [PATCH v2 wireless-drivers] mt76: mt7663u: fix memory leaks in mt7663u_probe Lorenzo Bianconi
2020-06-22 14:20 ` Kalle Valo
2020-06-22 14:40   ` Lorenzo Bianconi
2020-06-22 14:58     ` Kalle Valo
2020-06-22 15:03       ` Lorenzo Bianconi
2020-06-23  8:43 ` Kalle Valo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).