* [PATCH net v1 1/2] net: usb: lan78xx: Fix double free issue with interrupt buffer allocation
@ 2024-11-16 13:05 Oleksij Rempel
2024-11-16 13:05 ` [PATCH net v1 2/2] net: usb: lan78xx: Fix memory leak on device unplug by freeing PHY device Oleksij Rempel
2024-11-25 0:40 ` [PATCH net v1 1/2] net: usb: lan78xx: Fix double free issue with interrupt buffer allocation patchwork-bot+netdevbpf
0 siblings, 2 replies; 3+ messages in thread
From: Oleksij Rempel @ 2024-11-16 13:05 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Woojung Huh, Andrew Lunn
Cc: Oleksij Rempel, John Efstathiades, kernel, linux-kernel, netdev,
UNGLinuxDriver, Phil Elwell
In lan78xx_probe(), the buffer `buf` was being freed twice: once
implicitly through `usb_free_urb(dev->urb_intr)` with the
`URB_FREE_BUFFER` flag and again explicitly by `kfree(buf)`. This caused
a double free issue.
To resolve this, reordered `kmalloc()` and `usb_alloc_urb()` calls to
simplify the initialization sequence and removed the redundant
`kfree(buf)`. Now, `buf` is allocated after `usb_alloc_urb()`, ensuring
it is correctly managed by `usb_fill_int_urb()` and freed by
`usb_free_urb()` as intended.
Fixes: a6df95cae40b ("lan78xx: Fix memory allocation bug")
Cc: John Efstathiades <john.efstathiades@pebblebay.com>
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
drivers/net/usb/lan78xx.c | 29 ++++++++++++++---------------
1 file changed, 14 insertions(+), 15 deletions(-)
diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c
index 8adf77e3557e..094a47b8b97e 100644
--- a/drivers/net/usb/lan78xx.c
+++ b/drivers/net/usb/lan78xx.c
@@ -4414,29 +4414,30 @@ static int lan78xx_probe(struct usb_interface *intf,
period = ep_intr->desc.bInterval;
maxp = usb_maxpacket(dev->udev, dev->pipe_intr);
- buf = kmalloc(maxp, GFP_KERNEL);
- if (!buf) {
+
+ dev->urb_intr = usb_alloc_urb(0, GFP_KERNEL);
+ if (!dev->urb_intr) {
ret = -ENOMEM;
goto out5;
}
- dev->urb_intr = usb_alloc_urb(0, GFP_KERNEL);
- if (!dev->urb_intr) {
+ buf = kmalloc(maxp, GFP_KERNEL);
+ if (!buf) {
ret = -ENOMEM;
- goto out6;
- } else {
- usb_fill_int_urb(dev->urb_intr, dev->udev,
- dev->pipe_intr, buf, maxp,
- intr_complete, dev, period);
- dev->urb_intr->transfer_flags |= URB_FREE_BUFFER;
+ goto free_urbs;
}
+ usb_fill_int_urb(dev->urb_intr, dev->udev,
+ dev->pipe_intr, buf, maxp,
+ intr_complete, dev, period);
+ dev->urb_intr->transfer_flags |= URB_FREE_BUFFER;
+
dev->maxpacket = usb_maxpacket(dev->udev, dev->pipe_out);
/* Reject broken descriptors. */
if (dev->maxpacket == 0) {
ret = -ENODEV;
- goto out6;
+ goto free_urbs;
}
/* driver requires remote-wakeup capability during autosuspend. */
@@ -4444,7 +4445,7 @@ static int lan78xx_probe(struct usb_interface *intf,
ret = lan78xx_phy_init(dev);
if (ret < 0)
- goto out7;
+ goto free_urbs;
ret = register_netdev(netdev);
if (ret != 0) {
@@ -4466,10 +4467,8 @@ static int lan78xx_probe(struct usb_interface *intf,
out8:
phy_disconnect(netdev->phydev);
-out7:
+free_urbs:
usb_free_urb(dev->urb_intr);
-out6:
- kfree(buf);
out5:
lan78xx_unbind(dev, intf);
out4:
--
2.39.5
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH net v1 2/2] net: usb: lan78xx: Fix memory leak on device unplug by freeing PHY device
2024-11-16 13:05 [PATCH net v1 1/2] net: usb: lan78xx: Fix double free issue with interrupt buffer allocation Oleksij Rempel
@ 2024-11-16 13:05 ` Oleksij Rempel
2024-11-25 0:40 ` [PATCH net v1 1/2] net: usb: lan78xx: Fix double free issue with interrupt buffer allocation patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: Oleksij Rempel @ 2024-11-16 13:05 UTC (permalink / raw)
To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
Woojung Huh, Andrew Lunn
Cc: Oleksij Rempel, Raghuram Chary J, kernel, linux-kernel, netdev,
UNGLinuxDriver, Phil Elwell
Add calls to `phy_device_free` after `fixed_phy_unregister` to fix a
memory leak that occurs when the device is unplugged. This ensures
proper cleanup of pseudo fixed-link PHYs.
Fixes: 89b36fb5e532 ("lan78xx: Lan7801 Support for Fixed PHY")
Cc: Raghuram Chary J <raghuramchary.jallipalli@microchip.com>
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
drivers/net/usb/lan78xx.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/net/usb/lan78xx.c b/drivers/net/usb/lan78xx.c
index 094a47b8b97e..9f191b6ce821 100644
--- a/drivers/net/usb/lan78xx.c
+++ b/drivers/net/usb/lan78xx.c
@@ -2380,6 +2380,7 @@ static int lan78xx_phy_init(struct lan78xx_net *dev)
if (dev->chipid == ID_REV_CHIP_ID_7801_) {
if (phy_is_pseudo_fixed_link(phydev)) {
fixed_phy_unregister(phydev);
+ phy_device_free(phydev);
} else {
phy_unregister_fixup_for_uid(PHY_KSZ9031RNX,
0xfffffff0);
@@ -4246,8 +4247,10 @@ static void lan78xx_disconnect(struct usb_interface *intf)
phy_disconnect(net->phydev);
- if (phy_is_pseudo_fixed_link(phydev))
+ if (phy_is_pseudo_fixed_link(phydev)) {
fixed_phy_unregister(phydev);
+ phy_device_free(phydev);
+ }
usb_scuttle_anchored_urbs(&dev->deferred);
--
2.39.5
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH net v1 1/2] net: usb: lan78xx: Fix double free issue with interrupt buffer allocation
2024-11-16 13:05 [PATCH net v1 1/2] net: usb: lan78xx: Fix double free issue with interrupt buffer allocation Oleksij Rempel
2024-11-16 13:05 ` [PATCH net v1 2/2] net: usb: lan78xx: Fix memory leak on device unplug by freeing PHY device Oleksij Rempel
@ 2024-11-25 0:40 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-11-25 0:40 UTC (permalink / raw)
To: Oleksij Rempel
Cc: davem, edumazet, kuba, pabeni, woojung.huh, andrew+netdev,
john.efstathiades, kernel, linux-kernel, netdev, UNGLinuxDriver,
phil
Hello:
This series was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:
On Sat, 16 Nov 2024 14:05:57 +0100 you wrote:
> In lan78xx_probe(), the buffer `buf` was being freed twice: once
> implicitly through `usb_free_urb(dev->urb_intr)` with the
> `URB_FREE_BUFFER` flag and again explicitly by `kfree(buf)`. This caused
> a double free issue.
>
> To resolve this, reordered `kmalloc()` and `usb_alloc_urb()` calls to
> simplify the initialization sequence and removed the redundant
> `kfree(buf)`. Now, `buf` is allocated after `usb_alloc_urb()`, ensuring
> it is correctly managed by `usb_fill_int_urb()` and freed by
> `usb_free_urb()` as intended.
>
> [...]
Here is the summary with links:
- [net,v1,1/2] net: usb: lan78xx: Fix double free issue with interrupt buffer allocation
https://git.kernel.org/netdev/net/c/03819abbeb11
- [net,v1,2/2] net: usb: lan78xx: Fix memory leak on device unplug by freeing PHY device
https://git.kernel.org/netdev/net/c/ae7370e61c5d
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] 3+ messages in thread
end of thread, other threads:[~2024-11-25 0:40 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-11-16 13:05 [PATCH net v1 1/2] net: usb: lan78xx: Fix double free issue with interrupt buffer allocation Oleksij Rempel
2024-11-16 13:05 ` [PATCH net v1 2/2] net: usb: lan78xx: Fix memory leak on device unplug by freeing PHY device Oleksij Rempel
2024-11-25 0:40 ` [PATCH net v1 1/2] net: usb: lan78xx: Fix double free issue with interrupt buffer allocation patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®