* [PATCH 1/1] nfc: nfcmrvl: Fix memory leak in nfcmrvl_play_deferred
@ 2022-06-05 8:14 Xiaohui Zhang
2022-06-06 10:46 ` Krzysztof Kozlowski
0 siblings, 1 reply; 7+ messages in thread
From: Xiaohui Zhang @ 2022-06-05 8:14 UTC (permalink / raw)
To: Xiaohui Zhang, Krzysztof Kozlowski, David S . Miller, netdev,
linux-kernel
From: xiaohuizhang98 <ruc_zhangxiaohui@163.com>
We detected a suspected bug with our code clone detection tool.
Similar to the handling of play_deferred in commit 19cfe912c37b
("Bluetooth: btusb: Fix memory leak in play_deferred"), we thought
a patch might be needed here as well.
Currently usb_submit_urb is called directly to submit deferred tx
urbs after unanchor them.
So the usb_giveback_urb_bh would failed to unref it in usb_unanchor_urb
and cause memory leak.
Put those urbs in tx_anchor to avoid the leak, and also fix the error
handling.
Signed-off-by: xiaohuizhang98 <ruc_zhangxiaohui@163.com>
---
drivers/nfc/nfcmrvl/usb.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/drivers/nfc/nfcmrvl/usb.c b/drivers/nfc/nfcmrvl/usb.c
index a99aedff795d..ea7309453096 100644
--- a/drivers/nfc/nfcmrvl/usb.c
+++ b/drivers/nfc/nfcmrvl/usb.c
@@ -388,13 +388,25 @@ static void nfcmrvl_play_deferred(struct nfcmrvl_usb_drv_data *drv_data)
int err;
while ((urb = usb_get_from_anchor(&drv_data->deferred))) {
+ usb_anchor_urb(urb, &drv_data->tx_anchor);
+
err = usb_submit_urb(urb, GFP_ATOMIC);
- if (err)
+ if (err) {
+ kfree(urb->setup_packet);
+ usb_unanchor_urb(urb);
+ usb_free_urb(urb);
break;
+ }
drv_data->tx_in_flight++;
+ usb_free_urb(urb);
+ }
+
+ /* Cleanup the rest deferred urbs. */
+ while ((urb = usb_get_from_anchor(&drv_data->deferred))) {
+ kfree(urb->setup_packet);
+ usb_free_urb(urb);
}
- usb_scuttle_anchored_urbs(&drv_data->deferred);
}
static int nfcmrvl_resume(struct usb_interface *intf)
--
2.17.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/1] nfc: nfcmrvl: Fix memory leak in nfcmrvl_play_deferred
2022-06-05 8:14 [PATCH 1/1] nfc: nfcmrvl: Fix memory leak in nfcmrvl_play_deferred Xiaohui Zhang
@ 2022-06-06 10:46 ` Krzysztof Kozlowski
0 siblings, 0 replies; 7+ messages in thread
From: Krzysztof Kozlowski @ 2022-06-06 10:46 UTC (permalink / raw)
To: Xiaohui Zhang, David S . Miller, netdev, linux-kernel
On 05/06/2022 10:14, Xiaohui Zhang wrote:
> From: xiaohuizhang98 <ruc_zhangxiaohui@163.com>
>
> We detected a suspected bug with our code clone detection tool.
>
> Similar to the handling of play_deferred in commit 19cfe912c37b
> ("Bluetooth: btusb: Fix memory leak in play_deferred"), we thought
> a patch might be needed here as well.
>
> Currently usb_submit_urb is called directly to submit deferred tx
> urbs after unanchor them.
>
> So the usb_giveback_urb_bh would failed to unref it in usb_unanchor_urb
> and cause memory leak.
>
> Put those urbs in tx_anchor to avoid the leak, and also fix the error
> handling.
>
> Signed-off-by: xiaohuizhang98 <ruc_zhangxiaohui@163.com>
This name still does not match your name used in email.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/1] nfc: nfcmrvl: Fix memory leak in nfcmrvl_play_deferred
2022-06-07 8:32 Xiaohui Zhang
2022-06-07 12:44 ` Krzysztof Kozlowski
@ 2022-06-08 18:00 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 7+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-06-08 18:00 UTC (permalink / raw)
To: Xiaohui Zhang; +Cc: krzysztof.kozlowski, davem, netdev, linux-kernel
Hello:
This patch was applied to netdev/net.git (master)
by Jakub Kicinski <kuba@kernel.org>:
On Tue, 7 Jun 2022 16:32:30 +0800 you wrote:
> Similar to the handling of play_deferred in commit 19cfe912c37b
> ("Bluetooth: btusb: Fix memory leak in play_deferred"), we thought
> a patch might be needed here as well.
>
> Currently usb_submit_urb is called directly to submit deferred tx
> urbs after unanchor them.
>
> [...]
Here is the summary with links:
- [1/1] nfc: nfcmrvl: Fix memory leak in nfcmrvl_play_deferred
https://git.kernel.org/netdev/net/c/8a4d480702b7
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/1] nfc: nfcmrvl: Fix memory leak in nfcmrvl_play_deferred
2022-06-07 8:32 Xiaohui Zhang
@ 2022-06-07 12:44 ` Krzysztof Kozlowski
2022-06-08 18:00 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 7+ messages in thread
From: Krzysztof Kozlowski @ 2022-06-07 12:44 UTC (permalink / raw)
To: Xiaohui Zhang, David S . Miller, netdev, linux-kernel
On 07/06/2022 10:32, Xiaohui Zhang wrote:
> Similar to the handling of play_deferred in commit 19cfe912c37b
> ("Bluetooth: btusb: Fix memory leak in play_deferred"), we thought
> a patch might be needed here as well.
>
> Currently usb_submit_urb is called directly to submit deferred tx
> urbs after unanchor them.
>
> So the usb_giveback_urb_bh would failed to unref it in usb_unanchor_urb
> and cause memory leak.
>
> Put those urbs in tx_anchor to avoid the leak, and also fix the error
> handling.
>
> Signed-off-by: Xiaohui Zhang <xiaohuizhang@ruc.edu.cn>
Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/1] nfc: nfcmrvl: Fix memory leak in nfcmrvl_play_deferred
@ 2022-06-07 8:32 Xiaohui Zhang
2022-06-07 12:44 ` Krzysztof Kozlowski
2022-06-08 18:00 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 7+ messages in thread
From: Xiaohui Zhang @ 2022-06-07 8:32 UTC (permalink / raw)
To: Xiaohui Zhang, Krzysztof Kozlowski, David S . Miller, netdev,
linux-kernel
Similar to the handling of play_deferred in commit 19cfe912c37b
("Bluetooth: btusb: Fix memory leak in play_deferred"), we thought
a patch might be needed here as well.
Currently usb_submit_urb is called directly to submit deferred tx
urbs after unanchor them.
So the usb_giveback_urb_bh would failed to unref it in usb_unanchor_urb
and cause memory leak.
Put those urbs in tx_anchor to avoid the leak, and also fix the error
handling.
Signed-off-by: Xiaohui Zhang <xiaohuizhang@ruc.edu.cn>
---
drivers/nfc/nfcmrvl/usb.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/drivers/nfc/nfcmrvl/usb.c b/drivers/nfc/nfcmrvl/usb.c
index a99aedff795d..ea7309453096 100644
--- a/drivers/nfc/nfcmrvl/usb.c
+++ b/drivers/nfc/nfcmrvl/usb.c
@@ -388,13 +388,25 @@ static void nfcmrvl_play_deferred(struct nfcmrvl_usb_drv_data *drv_data)
int err;
while ((urb = usb_get_from_anchor(&drv_data->deferred))) {
+ usb_anchor_urb(urb, &drv_data->tx_anchor);
+
err = usb_submit_urb(urb, GFP_ATOMIC);
- if (err)
+ if (err) {
+ kfree(urb->setup_packet);
+ usb_unanchor_urb(urb);
+ usb_free_urb(urb);
break;
+ }
drv_data->tx_in_flight++;
+ usb_free_urb(urb);
+ }
+
+ /* Cleanup the rest deferred urbs. */
+ while ((urb = usb_get_from_anchor(&drv_data->deferred))) {
+ kfree(urb->setup_packet);
+ usb_free_urb(urb);
}
- usb_scuttle_anchored_urbs(&drv_data->deferred);
}
static int nfcmrvl_resume(struct usb_interface *intf)
--
2.17.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/1] nfc: nfcmrvl: Fix memory leak in nfcmrvl_play_deferred
2022-06-03 16:31 Xiaohui Zhang
@ 2022-06-04 1:33 ` Jakub Kicinski
0 siblings, 0 replies; 7+ messages in thread
From: Jakub Kicinski @ 2022-06-04 1:33 UTC (permalink / raw)
To: Xiaohui Zhang
Cc: Krzysztof Kozlowski, David S . Miller, netdev, linux-kernel, hifoolno
On Sat, 4 Jun 2022 00:31:27 +0800 Xiaohui Zhang wrote:
> From: hifoolno <553441439@qq.com>
>
> Currently usb_submit_urb is called directly to submit deferred tx
> urbs after unanchor them.
>
> So the usb_giveback_urb_bh would failed to unref it in usb_unanchor_urb
> and cause memory leak.
>
> Put those urbs in tx_anchor to avoid the leak, and also fix the error
> handling.
>
> Signed-off-by: hifoolno <553441439@qq.com>
hifoolno is too close to "Hi Fool" for comfort. Is that really your
name?
Also the patch doesn't build.
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/1] nfc: nfcmrvl: Fix memory leak in nfcmrvl_play_deferred
@ 2022-06-03 16:31 Xiaohui Zhang
2022-06-04 1:33 ` Jakub Kicinski
0 siblings, 1 reply; 7+ messages in thread
From: Xiaohui Zhang @ 2022-06-03 16:31 UTC (permalink / raw)
To: Xiaohui Zhang, Krzysztof Kozlowski, David S . Miller, netdev,
linux-kernel
Cc: hifoolno
From: hifoolno <553441439@qq.com>
Currently usb_submit_urb is called directly to submit deferred tx
urbs after unanchor them.
So the usb_giveback_urb_bh would failed to unref it in usb_unanchor_urb
and cause memory leak.
Put those urbs in tx_anchor to avoid the leak, and also fix the error
handling.
Signed-off-by: hifoolno <553441439@qq.com>
---
drivers/nfc/nfcmrvl/usb.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/drivers/nfc/nfcmrvl/usb.c b/drivers/nfc/nfcmrvl/usb.c
index a99aedff795d..815255b8d72e 100644
--- a/drivers/nfc/nfcmrvl/usb.c
+++ b/drivers/nfc/nfcmrvl/usb.c
@@ -388,13 +388,27 @@ static void nfcmrvl_play_deferred(struct nfcmrvl_usb_drv_data *drv_data)
int err;
while ((urb = usb_get_from_anchor(&drv_data->deferred))) {
+ usb_anchor_urb(urb, &drv_data->tx_anchor);
+
err = usb_submit_urb(urb, GFP_ATOMIC);
- if (err)
+ if (err) {
+ if (err != -EPERM && err != -ENODEV)
+ BT_ERR("%s urb %p submission failed (%d)",
+ drv_data->hdev->name, urb, -err);
+ kfree(urb->setup_packet);
+ usb_unanchor_urb(urb);
+ usb_free_urb(urb);
break;
+ }
drv_data->tx_in_flight++;
+ usb_free_urb(urb);
+ }
+ /* Cleanup the rest deferred urbs. */
+ while ((urb = usb_get_from_anchor(&drv_data->deferred))) {
+ kfree(urb->setup_packet);
+ usb_free_urb(urb);
}
- usb_scuttle_anchored_urbs(&drv_data->deferred);
}
static int nfcmrvl_resume(struct usb_interface *intf)
--
2.17.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-06-08 18:00 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-05 8:14 [PATCH 1/1] nfc: nfcmrvl: Fix memory leak in nfcmrvl_play_deferred Xiaohui Zhang
2022-06-06 10:46 ` Krzysztof Kozlowski
-- strict thread matches above, loose matches on Subject: below --
2022-06-07 8:32 Xiaohui Zhang
2022-06-07 12:44 ` Krzysztof Kozlowski
2022-06-08 18:00 ` patchwork-bot+netdevbpf
2022-06-03 16:31 Xiaohui Zhang
2022-06-04 1:33 ` Jakub Kicinski
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).