wifi: drop redundant USB device references
Subsystems (11)
cover wifi: drop redundant USB device references
Driver core holds a reference to the USB interface and its parent USB device while the interface is bound to a driver and there is no need to take additional references unless the structures are needed after disconnect.
Drop redundant device references to reduce cargo culting, make it easier to spot drivers where an extra reference is needed, and reduce the risk of memory leaks when drivers fail to release them.
Note that I sent an ath9k patch separately here:
https://lore.kernel.org/all/[email protected]/
but I guess these can all be picked up by Johannes.
Johan
Johan Hovold (13):
wifi: at76c50x: drop redundant device reference
wifi: libertas: drop redundant device reference
wifi: libertas_tf: drop redundant device reference
wifi: mwifiex: drop redundant device reference
wifi: mt76: drop redundant device reference
wifi: mt76x0u: drop redundant device reference
wifi: mt76x2u: drop redundant device reference
wifi: mt76: mt792xu: drop redundant device reference
wifi: mt7601u: drop redundant device reference
wifi: rt2x00: drop redundant device reference
wifi: rtl818x: drop redundant device reference
wifi: rtl8xxxu: drop redundant device reference
wifi: rtlwifi: usb: drop redundant device reference
drivers/net/wireless/atmel/at76c50x-usb.c | 12 ++++-------- drivers/net/wireless/marvell/libertas/if_usb.c | 3 --- drivers/net/wireless/marvell/libertas_tf/if_usb.c | 2 -- drivers/net/wireless/marvell/mwifiex/usb.c | 4 ---- drivers/net/wireless/mediatek/mt76/mt7615/usb.c | 3 --- drivers/net/wireless/mediatek/mt76/mt76x0/usb.c | 3 --- drivers/net/wireless/mediatek/mt76/mt76x2/usb.c | 4 ---- drivers/net/wireless/mediatek/mt76/mt7921/usb.c | 2 -- drivers/net/wireless/mediatek/mt76/mt7925/usb.c | 2 -- drivers/net/wireless/mediatek/mt76/mt792x_usb.c | 1 - drivers/net/wireless/mediatek/mt7601u/usb.c | 3 --- drivers/net/wireless/ralink/rt2x00/rt2x00usb.c | 12 +----------- drivers/net/wireless/realtek/rtl818x/rtl8187/dev.c | 4 ---- drivers/net/wireless/realtek/rtl8xxxu/core.c | 11 +++-------- drivers/net/wireless/realtek/rtlwifi/usb.c | 4 ---- 15 files changed, 8 insertions(+), 62 deletions(-)
Signature · 1 line
2.52.0
PATCH 1/13 wifi: at76c50x: drop redundant device reference
Driver core holds a reference to the USB interface and its parent USB device while the interface is bound to a driver and there is no need to take additional references unless the structures are needed after disconnect.
Drop the redundant device reference to reduce cargo culting, make it easier to spot drivers where an extra reference is needed, and reduce the risk of memory leaks when drivers fail to release it.
--- drivers/net/wireless/atmel/at76c50x-usb.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
drivers/net/wireless/atmel/at76c50x-usb.c +4 -8
@@ -2440,13 +2440,11 @@ static int at76_probe(struct usb_interface *interface,struct mib_fw_version *fwv;int board_type = (int )id->driver_info; - udev =usb_get_dev (interface_to_usbdev (interface)); + udev =interface_to_usbdev (interface); fwv =kmalloc_obj (*fwv); -if (!fwv) { - ret = -ENOMEM ; - goto exit; - } +if (!fwv) +return -ENOMEM ;/* Load firmware into kernel memory */ fwe =at76_load_firmware (udev, board_type);
@@ -2534,8 +2532,7 @@ static int at76_probe(struct usb_interface *interface, exit:kfree (fwv); -if (ret <0 ) -usb_put_dev (udev); +return ret; }
@@ -2552,7 +2549,6 @@ static void at76_disconnect(struct usb_interface *interface)wiphy_info (priv->hw->wiphy,"disconnecting\n" );at76_delete_device (priv); -usb_put_dev (interface_to_usbdev (interface));dev_info (&interface->dev,"disconnected\n" ); }
Signature · 1 line
2.52.0
PATCH 2/13 wifi: libertas: drop redundant device reference
In reply to Johan HovoldDriver core holds a reference to the USB interface and its parent USB device while the interface is bound to a driver and there is no need to take additional references unless the structures are needed after disconnect.
Drop the redundant device reference to reduce cargo culting, make it easier to spot drivers where an extra reference is needed, and reduce the risk of memory leaks when drivers fail to release it.
--- drivers/net/wireless/marvell/libertas/if_usb.c | 3 --- 1 file changed, 3 deletions(-)
drivers/net/wireless/marvell/libertas/if_usb.c +0 -3
@@ -276,7 +276,6 @@ static int if_usb_probe(struct usb_interface *intf, cardp->boot2_version = udev->descriptor.bcdDevice; -usb_get_dev (udev);usb_set_intfdata (intf, cardp); r = lbs_get_firmware_async(priv, &udev->dev, cardp->model,
@@ -287,7 +286,6 @@ static int if_usb_probe(struct usb_interface *intf,return 0 ; err_get_fw: -usb_put_dev (udev);lbs_remove_card (priv); err_add_card:if_usb_reset_device (cardp);
@@ -321,7 +319,6 @@ static void if_usb_disconnect(struct usb_interface *intf)kfree (cardp);usb_set_intfdata (intf,NULL ); -usb_put_dev (interface_to_usbdev (intf)); }/**
Signature · 1 line
2.52.0
PATCH 3/13 wifi: libertas_tf: drop redundant device reference
In reply to Johan HovoldDriver core holds a reference to the USB interface and its parent USB device while the interface is bound to a driver and there is no need to take additional references unless the structures are needed after disconnect.
Drop the redundant device reference to reduce cargo culting, make it easier to spot drivers where an extra reference is needed, and reduce the risk of memory leaks when drivers fail to release it.
--- drivers/net/wireless/marvell/libertas_tf/if_usb.c | 2 -- 1 file changed, 2 deletions(-)
drivers/net/wireless/marvell/libertas_tf/if_usb.c +0 -2
@@ -223,7 +223,6 @@ static int if_usb_probe(struct usb_interface *intf,if (!priv) goto dealloc; -usb_get_dev (udev);usb_set_intfdata (intf, cardp);return 0 ;
@@ -258,7 +257,6 @@ static void if_usb_disconnect(struct usb_interface *intf)kfree (cardp);usb_set_intfdata (intf,NULL ); -usb_put_dev (interface_to_usbdev (intf));lbtf_deb_leave (LBTF_DEB_MAIN ); }
Signature · 1 line
2.52.0
PATCH 4/13 wifi: mwifiex: drop redundant device reference
In reply to Johan HovoldDriver core holds a reference to the USB interface and its parent USB device while the interface is bound to a driver and there is no need to take additional references unless the structures are needed after disconnect.
Drop the redundant device reference to reduce cargo culting, make it easier to spot drivers where an extra reference is needed, and reduce the risk of memory leaks when drivers fail to release it.
--- drivers/net/wireless/marvell/mwifiex/usb.c | 4 ---- 1 file changed, 4 deletions(-)
drivers/net/wireless/marvell/mwifiex/usb.c +0 -4
@@ -520,8 +520,6 @@ static int mwifiex_usb_probe(struct usb_interface *intf,return ret; } -usb_get_dev (udev); -return 0 ; }
@@ -666,8 +664,6 @@ static void mwifiex_usb_disconnect(struct usb_interface *intf)mwifiex_dbg (adapter,FATAL ,"%s: removing card\n" , __func__);mwifiex_remove_card (adapter); - -usb_put_dev (interface_to_usbdev (intf)); }static void mwifiex_usb_coredump (struct device *dev)
Signature · 1 line
2.52.0
Re: [PATCH 04/13] wifi: mwifiex: drop redundant device reference
Quoted 10 lines · Johan Hovold
Driver core holds a reference to the USB interface and its parent USB device while the interface is bound to a driver and there is no need to take additional references unless the structures are needed after disconnect.
Drop the redundant device reference to reduce cargo culting, make it easier to spot drivers where an extra reference is needed, and reduce the risk of memory leaks when drivers fail to release it.
Signed-off-by Johan Hovold <[email protected]>
PATCH 5/13 wifi: mt76: drop redundant device reference
In reply to Johan HovoldDriver core holds a reference to the USB interface and its parent USB device while the interface is bound to a driver and there is no need to take additional references unless the structures are needed after disconnect.
Drop the redundant device reference to reduce cargo culting, make it easier to spot drivers where an extra reference is needed, and reduce the risk of memory leaks when drivers fail to release it.
--- drivers/net/wireless/mediatek/mt76/mt7615/usb.c | 3 --- 1 file changed, 3 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7615/usb.c +0 -3
@@ -151,7 +151,6 @@ static int mt7663u_probe(struct usb_interface *usb_intf,return -ENOMEM ; dev = container_of(mdev, struct mt7615_dev, mt76); - udev =usb_get_dev (udev);usb_reset_device (udev);usb_set_intfdata (usb_intf, dev);
@@ -193,7 +192,6 @@ static int mt7663u_probe(struct usb_interface *usb_intf, error:mt76u_queues_deinit (&dev->mt76);usb_set_intfdata (usb_intf,NULL ); -usb_put_dev (interface_to_usbdev (usb_intf));mt76_free_device (&dev->mt76);
@@ -211,7 +209,6 @@ static void mt7663u_disconnect(struct usb_interface *usb_intf)mt7663u_cleanup (dev);usb_set_intfdata (usb_intf,NULL ); -usb_put_dev (interface_to_usbdev (usb_intf));mt76_free_device (&dev->mt76); }
Signature · 1 line
2.52.0
PATCH 6/13 wifi: mt76x0u: drop redundant device reference
In reply to Johan HovoldDriver core holds a reference to the USB interface and its parent USB device while the interface is bound to a driver and there is no need to take additional references unless the structures are needed after disconnect.
Drop the redundant device reference to reduce cargo culting, make it easier to spot drivers where an extra reference is needed, and reduce the risk of memory leaks when drivers fail to release it.
--- drivers/net/wireless/mediatek/mt76/mt76x0/usb.c | 3 --- 1 file changed, 3 deletions(-)
drivers/net/wireless/mediatek/mt76/mt76x0/usb.c +0 -3
@@ -245,7 +245,6 @@ static int mt76x0u_probe(struct usb_interface *usb_intf,if (id->driver_info) dev->no_2ghz = true; - usb_dev =usb_get_dev (usb_dev);usb_reset_device (usb_dev);usb_set_intfdata (usb_intf, dev);
@@ -284,7 +283,6 @@ static int mt76x0u_probe(struct usb_interface *usb_intf, err:usb_set_intfdata (usb_intf,NULL ); -usb_put_dev (interface_to_usbdev (usb_intf));mt76u_queues_deinit (&dev->mt76);mt76_free_device (&dev->mt76);
@@ -303,7 +301,6 @@ static void mt76x0_disconnect(struct usb_interface *usb_intf)mt76x0u_cleanup (dev);usb_set_intfdata (usb_intf,NULL ); -usb_put_dev (interface_to_usbdev (usb_intf));mt76_free_device (&dev->mt76); }
Signature · 1 line
2.52.0
PATCH 7/13 wifi: mt76x2u: drop redundant device reference
In reply to Johan HovoldDriver core holds a reference to the USB interface and its parent USB device while the interface is bound to a driver and there is no need to take additional references unless the structures are needed after disconnect.
Drop the redundant device reference to reduce cargo culting, make it easier to spot drivers where an extra reference is needed, and reduce the risk of memory leaks when drivers fail to release it.
--- drivers/net/wireless/mediatek/mt76/mt76x2/usb.c | 4 ---- 1 file changed, 4 deletions(-)
drivers/net/wireless/mediatek/mt76/mt76x2/usb.c +0 -4
@@ -57,7 +57,6 @@ static int mt76x2u_probe(struct usb_interface *intf, dev = container_of(mdev, struct mt76x02_dev, mt76); - udev =usb_get_dev (udev);usb_reset_device (udev);usb_set_intfdata (intf, dev);
@@ -84,14 +83,12 @@ static int mt76x2u_probe(struct usb_interface *intf,mt76u_queues_deinit (&dev->mt76);mt76_free_device (&dev->mt76);usb_set_intfdata (intf,NULL ); -usb_put_dev (udev);return err; }static void mt76x2u_disconnect (struct usb_interface *intf) { -struct usb_device *udev =interface_to_usbdev (intf);struct mt76x02_dev *dev =usb_get_intfdata (intf);struct ieee80211_hw *hw =mt76_hw (dev);
@@ -100,7 +97,6 @@ static void mt76x2u_disconnect(struct usb_interface *intf)mt76x2u_cleanup (dev);mt76_free_device (&dev->mt76);usb_set_intfdata (intf,NULL ); -usb_put_dev (udev); } static int __maybe_unused mt76x2u_suspend(struct usb_interface *intf,
Signature · 1 line
2.52.0
PATCH 8/13 wifi: mt76: mt792xu: drop redundant device reference
In reply to Johan HovoldDriver core holds a reference to the USB interface and its parent USB device while the interface is bound to a driver and there is no need to take additional references unless the structures are needed after disconnect.
Drop the redundant device reference to reduce cargo culting, make it easier to spot drivers where an extra reference is needed, and reduce the risk of memory leaks when drivers fail to release it.
--- drivers/net/wireless/mediatek/mt76/mt7921/usb.c | 2 -- drivers/net/wireless/mediatek/mt76/mt7925/usb.c | 2 -- drivers/net/wireless/mediatek/mt76/mt792x_usb.c | 1 - 3 files changed, 5 deletions(-)
drivers/net/wireless/mediatek/mt76/mt7921/usb.c +0 -2
@@ -197,7 +197,6 @@ static int mt7921u_probe(struct usb_interface *usb_intf, dev->fw_features = features; dev->hif_ops = &hif_ops; - udev =usb_get_dev (udev);usb_reset_device (udev);usb_set_intfdata (usb_intf, dev);
@@ -246,7 +245,6 @@ static int mt7921u_probe(struct usb_interface *usb_intf,mt76u_queues_deinit (&dev->mt76);usb_set_intfdata (usb_intf,NULL ); -usb_put_dev (interface_to_usbdev (usb_intf));mt76_free_device (&dev->mt76);
drivers/net/wireless/mediatek/mt76/mt7925/usb.c +0 -2
@@ -185,7 +185,6 @@ static int mt7925u_probe(struct usb_interface *usb_intf, dev->fw_features = features; dev->hif_ops = &hif_ops; - udev =usb_get_dev (udev);usb_reset_device (udev);usb_set_intfdata (usb_intf, dev);
@@ -234,7 +233,6 @@ static int mt7925u_probe(struct usb_interface *usb_intf,mt76u_queues_deinit (&dev->mt76);usb_set_intfdata (usb_intf,NULL ); -usb_put_dev (interface_to_usbdev (usb_intf));mt76_free_device (&dev->mt76);
drivers/net/wireless/mediatek/mt76/mt792x_usb.c +0 -1
@@ -306,7 +306,6 @@ void mt792xu_disconnect(struct usb_interface *usb_intf)mt792xu_cleanup (dev);usb_set_intfdata (usb_intf,NULL ); -usb_put_dev (interface_to_usbdev (usb_intf));mt76_free_device (&dev->mt76); }
Signature · 1 line
2.52.0
PATCH 9/13 wifi: mt7601u: drop redundant device reference
In reply to Johan HovoldDriver core holds a reference to the USB interface and its parent USB device while the interface is bound to a driver and there is no need to take additional references unless the structures are needed after disconnect.
Drop the redundant device reference to reduce cargo culting, make it easier to spot drivers where an extra reference is needed, and reduce the risk of memory leaks when drivers fail to release it.
--- drivers/net/wireless/mediatek/mt7601u/usb.c | 3 --- 1 file changed, 3 deletions(-)
drivers/net/wireless/mediatek/mt7601u/usb.c +0 -3
@@ -274,7 +274,6 @@ static int mt7601u_probe(struct usb_interface *usb_intf,if (!dev)return -ENOMEM ; - usb_dev =usb_get_dev (usb_dev);usb_reset_device (usb_dev);usb_set_intfdata (usb_intf, dev);
@@ -319,7 +318,6 @@ static int mt7601u_probe(struct usb_interface *usb_intf,mt7601u_cleanup (dev); err:usb_set_intfdata (usb_intf,NULL ); -usb_put_dev (interface_to_usbdev (usb_intf));destroy_workqueue (dev->stat_wq);ieee80211_free_hw (dev->hw);
@@ -334,7 +332,6 @@ static void mt7601u_disconnect(struct usb_interface *usb_intf)mt7601u_cleanup (dev);usb_set_intfdata (usb_intf,NULL ); -usb_put_dev (interface_to_usbdev (usb_intf));destroy_workqueue (dev->stat_wq);ieee80211_free_hw (dev->hw);
Signature · 1 line
2.52.0
PATCH 10/13 wifi: rt2x00: drop redundant device reference
In reply to Johan HovoldDriver core holds a reference to the USB interface and its parent USB device while the interface is bound to a driver and there is no need to take additional references unless the structures are needed after disconnect.
Drop the redundant device reference to reduce cargo culting, make it easier to spot drivers where an extra reference is needed, and reduce the risk of memory leaks when drivers fail to release it.
--- drivers/net/wireless/ralink/rt2x00/rt2x00usb.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-)
drivers/net/wireless/ralink/rt2x00/rt2x00usb.c +1 -11
@@ -802,14 +802,12 @@ int rt2x00usb_probe(struct usb_interface *usb_intf,struct rt2x00_dev *rt2x00dev;int retval; - usb_dev =usb_get_dev (usb_dev);usb_reset_device (usb_dev); hw =ieee80211_alloc_hw (sizeof (struct rt2x00_dev ), ops->hw);if (!hw) {rt2x00_probe_err ("Failed to allocate hardware\n" ); - retval = -ENOMEM ; - goto exit_put_device; +return -ENOMEM ; }usb_set_intfdata (usb_intf, hw);
@@ -851,10 +849,6 @@ int rt2x00usb_probe(struct usb_interface *usb_intf, exit_free_device:ieee80211_free_hw (hw); - -exit_put_device: -usb_put_dev (usb_dev); -usb_set_intfdata (usb_intf,NULL );return retval;
@@ -873,11 +867,7 @@ void rt2x00usb_disconnect(struct usb_interface *usb_intf)rt2x00usb_free_reg (rt2x00dev);ieee80211_free_hw (hw); -/* -* Free the USB device data. -*/ usb_set_intfdata (usb_intf,NULL ); -usb_put_dev (interface_to_usbdev (usb_intf)); }EXPORT_SYMBOL_GPL (rt2x00usb_disconnect);
Signature · 1 line
2.52.0
Stanislaw Gruszka
maintainerRe: [PATCH 10/13] wifi: rt2x00: drop redundant device reference
Quoted 6 lines · Johan Hovold
Driver core holds a reference to the USB interface and its parent USB device while the interface is bound to a driver and there is no need to take additional references unless the structures are needed after disconnect.
Drop the redundant device reference to reduce cargo culting, make it
Getting the reference in probe() and drop it in disconnect() was not a cargo cult. That was requirement from usb_get_dev() comment, that later it was changed by below commit:
commit f6a9a2d64dd168b7d71076c0e6b2be7db7cb7399
Author: Alan Stern <[email protected]> Date: Fri Feb 25 09:38:25 2022 -0500
USB: core: Update kerneldoc for usb_get_dev() and usb_get_intf()
The kerneldoc for usb_get_dev() and usb_get_intf() says that drivers should always refcount the references they hold for the usb_device or usb_interface structure, respectively. But this is an overstatement:
In many cases drivers do not access these references after they have been unbound, and in such cases refcounting is unnecessary.
This patch updates the kerneldoc for the two routines, explaining when a driver does not need to increment and decrement the refcount. This should help dispel misconceptions which might otherwise afflict programmers new to the USB subsystem.
Regards
Stanislaw
Quoted 54 lines
easier to spot drivers where an extra reference is needed, and reduce the risk of memory leaks when drivers fail to release it.
Signed-off-by Johan Hovold <[email protected]>--- drivers/net/wireless/ralink/rt2x00/rt2x00usb.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-)drivers/net/wireless/ralink/rt2x00/rt2x00usb.c +1
-11@@ -802,14 +802,12 @@ int rt2x00usb_probe(struct usb_interface *usb_intf,struct rt2x00_dev *rt2x00dev;int retval; - usb_dev =usb_get_dev (usb_dev);usb_reset_device (usb_dev); hw =ieee80211_alloc_hw (sizeof (struct rt2x00_dev ), ops->hw);if (!hw) {rt2x00_probe_err ("Failed to allocate hardware\n" ); - retval = -ENOMEM ; - goto exit_put_device; +return -ENOMEM ; }usb_set_intfdata (usb_intf, hw);@@ -851,10 +849,6 @@ int rt2x00usb_probe(struct usb_interface *usb_intf, exit_free_device:ieee80211_free_hw (hw); - -exit_put_device: -usb_put_dev (usb_dev); -usb_set_intfdata (usb_intf,NULL );return retval;@@ -873,11 +867,7 @@ void rt2x00usb_disconnect(struct usb_interface *usb_intf)rt2x00usb_free_reg (rt2x00dev);ieee80211_free_hw (hw); -/* -* Free the USB device data. -*/ usb_set_intfdata (usb_intf,NULL ); -usb_put_dev (interface_to_usbdev (usb_intf)); }EXPORT_SYMBOL_GPL (rt2x00usb_disconnect);Signature · 1 line
2.52.0
Re: [PATCH 10/13] wifi: rt2x00: drop redundant device reference
Quoted 24 lines · Stanislaw Gruszka
Quoted 6 lines · Johan Hovold
Driver core holds a reference to the USB interface and its parent USB device while the interface is bound to a driver and there is no need to take additional references unless the structures are needed after disconnect.
Drop the redundant device reference to reduce cargo culting, make it
Getting the reference in
probe()and drop it indisconnect()was not a cargo cult. That was requirement fromusb_get_dev()comment, that later it was changed by below commit:commit
f6a9a2d64dd168b7d71076c0e6b2be7db7cb7399Author: Alan Stern <[email protected]> Date: Fri Feb 25 09:38:25 2022 -0500USB: core: Update kerneldoc for
usb_get_dev()andusb_get_intf()The kerneldoc for
usb_get_dev()andusb_get_intf()says that drivers should always refcount the references they hold for theusb_deviceorusb_interfacestructure, respectively. But this is an overstatement:
In many cases drivers do not access these references after they have been unbound, and in such cases refcounting is unnecessary.
Quoted 4 lines
This patch updates the kerneldoc for the two routines, explaining when a driver does not need to increment and decrement the refcount. This should help dispel misconceptions which might otherwise afflict programmers new to the USB subsystem.
Yeah, the documentation indeed was misleading for a very long time. That reference comment even predates the driver model.
Many authors base their work on existing drivers so we still get new ones that take such references even after the docs were amended.
Johan
Re: [PATCH 10/13] wifi: rt2x00: drop redundant device reference
In reply to Johan HovoldQuoted 10 lines · Johan Hovold
Driver core holds a reference to the USB interface and its parent USB device while the interface is bound to a driver and there is no need to take additional references unless the structures are needed after disconnect.
Drop the redundant device reference to reduce cargo culting, make it easier to spot drivers where an extra reference is needed, and reduce the risk of memory leaks when drivers fail to release it.
Signed-off-by Johan Hovold <[email protected]>
Quoted 50 lines
--- drivers/net/wireless/ralink/rt2x00/rt2x00usb.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-)drivers/net/wireless/ralink/rt2x00/rt2x00usb.c +1
-11@@ -802,14 +802,12 @@ int rt2x00usb_probe(struct usb_interface *usb_intf,struct rt2x00_dev *rt2x00dev;int retval; - usb_dev =usb_get_dev (usb_dev);usb_reset_device (usb_dev); hw =ieee80211_alloc_hw (sizeof (struct rt2x00_dev ), ops->hw);if (!hw) {rt2x00_probe_err ("Failed to allocate hardware\n" ); - retval = -ENOMEM ; - goto exit_put_device; +return -ENOMEM ; }usb_set_intfdata (usb_intf, hw);@@ -851,10 +849,6 @@ int rt2x00usb_probe(struct usb_interface *usb_intf, exit_free_device:ieee80211_free_hw (hw); - -exit_put_device: -usb_put_dev (usb_dev); -usb_set_intfdata (usb_intf,NULL );return retval;@@ -873,11 +867,7 @@ void rt2x00usb_disconnect(struct usb_interface *usb_intf)rt2x00usb_free_reg (rt2x00dev);ieee80211_free_hw (hw); -/* -* Free the USB device data. -*/ usb_set_intfdata (usb_intf,NULL ); -usb_put_dev (interface_to_usbdev (usb_intf)); }EXPORT_SYMBOL_GPL (rt2x00usb_disconnect);Signature · 1 line
2.52.0
PATCH 11/13 wifi: rtl818x: drop redundant device reference
In reply to Johan HovoldDriver core holds a reference to the USB interface and its parent USB device while the interface is bound to a driver and there is no need to take additional references unless the structures are needed after disconnect.
Drop the redundant device reference to reduce cargo culting, make it easier to spot drivers where an extra reference is needed, and reduce the risk of memory leaks when drivers fail to release it.
--- drivers/net/wireless/realtek/rtl818x/rtl8187/dev.c | 4 ---- 1 file changed, 4 deletions(-)
drivers/net/wireless/realtek/rtl818x/rtl8187/dev.c +0 -4
@@ -1475,8 +1475,6 @@ static int rtl8187_probe(struct usb_interface *intf,usb_set_intfdata (intf, dev); priv->udev = udev; -usb_get_dev (udev); -skb_queue_head_init (&priv->rx_queue);BUILD_BUG_ON (sizeof (priv->channels) !=sizeof (rtl818x_channels));
@@ -1663,7 +1661,6 @@ static int rtl8187_probe(struct usb_interface *intf, err_free_dmabuf:kfree (priv->io_dmabuf);usb_set_intfdata (intf,NULL ); -usb_put_dev (udev); err_free_dev:ieee80211_free_hw (dev);return err;
@@ -1685,7 +1682,6 @@ static void rtl8187_disconnect(struct usb_interface *intf) priv = dev->priv;usb_reset_device (priv->udev); -usb_put_dev (interface_to_usbdev (intf));kfree (priv->io_dmabuf);ieee80211_free_hw (dev); }
Signature · 1 line
2.52.0
PATCH 12/13 wifi: rtl8xxxu: drop redundant device reference
In reply to Johan HovoldDriver core holds a reference to the USB interface and its parent USB device while the interface is bound to a driver and there is no need to take additional references unless the structures are needed after disconnect.
Drop the redundant device reference to reduce cargo culting, make it easier to spot drivers where an extra reference is needed, and reduce the risk of memory leaks when drivers fail to release it.
--- drivers/net/wireless/realtek/rtl8xxxu/core.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-)
drivers/net/wireless/realtek/rtl8xxxu/core.c +3 -8
@@ -7698,7 +7698,7 @@ static int rtl8xxxu_probe(struct usb_interface *interface,int ret;int untested =1 ; - udev =usb_get_dev (interface_to_usbdev (interface)); + udev =interface_to_usbdev (interface);switch (id->idVendor) {case USB_VENDOR_ID_REALTEK :
@@ -7756,10 +7756,8 @@ static int rtl8xxxu_probe(struct usb_interface *interface, } hw =ieee80211_alloc_hw (sizeof (struct rtl8xxxu_priv ), &rtl8xxxu_ops); -if (!hw) { - ret = -ENOMEM ; - goto err_put_dev; - } +if (!hw) +return -ENOMEM ; priv = hw->priv; priv->hw = hw;
@@ -7901,8 +7899,6 @@ static int rtl8xxxu_probe(struct usb_interface *interface,mutex_destroy (&priv->h2c_mutex);ieee80211_free_hw (hw); -err_put_dev: -usb_put_dev (udev);return ret; }
@@ -7935,7 +7931,6 @@ static void rtl8xxxu_disconnect(struct usb_interface *interface) "Device still attached, trying to reset\n");usb_reset_device (priv->udev); } -usb_put_dev (priv->udev);ieee80211_free_hw (hw); }
Signature · 1 line
2.52.0
PATCH 13/13 wifi: rtlwifi: usb: drop redundant device reference
In reply to Johan HovoldDriver core holds a reference to the USB interface and its parent USB device while the interface is bound to a driver and there is no need to take additional references unless the structures are needed after disconnect.
Drop the redundant device reference to reduce cargo culting, make it easier to spot drivers where an extra reference is needed, and reduce the risk of memory leaks when drivers fail to release it.
--- drivers/net/wireless/realtek/rtlwifi/usb.c | 4 ---- 1 file changed, 4 deletions(-)
drivers/net/wireless/realtek/rtlwifi/usb.c +0 -4
@@ -986,7 +986,6 @@ int rtl_usb_probe(struct usb_interface *intf,init_completion (&rtlpriv->firmware_loading_complete);SET_IEEE80211_DEV (hw, &intf->dev); udev =interface_to_usbdev (intf); -usb_get_dev (udev); usb_priv =rtl_usbpriv (hw);memset (usb_priv,0 ,sizeof (*usb_priv)); usb_priv->dev.intf = intf;
@@ -1038,7 +1037,6 @@ int rtl_usb_probe(struct usb_interface *intf,rtl_deinit_core (hw); error_out2:_rtl_usb_io_handler_release (hw); -usb_put_dev (udev);kfree (rtlpriv->usb_data);ieee80211_free_hw (hw);return -ENODEV ;
@@ -1050,7 +1048,6 @@ void rtl_usb_disconnect(struct usb_interface *intf)struct ieee80211_hw *hw =usb_get_intfdata (intf);struct rtl_priv *rtlpriv =rtl_priv (hw);struct rtl_mac *rtlmac =rtl_mac (rtl_priv (hw)); -struct rtl_usb *rtlusb =rtl_usbdev (rtl_usbpriv (hw));if (unlikely (!rtlpriv))return ;
@@ -1072,7 +1069,6 @@ void rtl_usb_disconnect(struct usb_interface *intf)kfree (rtlpriv->usb_data); rtlpriv->cfg->ops->deinit_sw_vars (hw);_rtl_usb_io_handler_release (hw); -usb_put_dev (rtlusb->udev);usb_set_intfdata (intf,NULL );ieee80211_free_hw (hw); }
Signature · 1 line
2.52.0
Ping-Ke Shih
maintainer// +Cc Greg
Hi Johan,
Johan Hovold <[email protected]> wrote:
[...]
Quoted 3 lines
drivers/net/wireless/realtek/rtl818x/rtl8187/dev.c | 4 ---- drivers/net/wireless/realtek/rtl8xxxu/core.c | 11 +++-------- drivers/net/wireless/realtek/rtlwifi/usb.c | 4 ----
Acked to changes of these Realtek WiFi drivers. But I'd like to know why rtw88/rtw89 aren't included in this patchset? Greg sent a patch [1] to correct error path of USB probe for rtw88. In the discussion, he also mentioned the simplest way is to drop usb_get_dev()/usb_put_dev() like this patchset does. Will you share patches for rtw88/rtw89? I so, I'd drop Greg's patch and apply yours.
[1] https://lore.kernel.org/linux-wireless/2026022333-periscope-unusual-f0a0@gregkh/
Ping-Ke
Quoted 6 lines · Ping-Ke Shih
// +Cc Greg
Hi Johan,
Johan Hovold <[email protected]> wrote:
Quoted 8 lines
[...]
Quoted 3 lines
drivers/net/wireless/realtek/rtl818x/rtl8187/dev.c | 4 ---- drivers/net/wireless/realtek/rtl8xxxu/core.c | 11 +++-------- drivers/net/wireless/realtek/rtlwifi/usb.c | 4 ----Acked to changes of these Realtek WiFi drivers. But I'd like to know why rtw88/rtw89 aren't included in this patchset?
I used a more specific grep pattern to catch driver releasing references in disconnect() and therefore missed a few that dropped the reference in helper functions (or used non-standard names for their disconnect function such as ath10k, I see now).
Quoted 7 lines
Greg sent a patch [1] to
correct error path of USB probe for rtw88. In the discussion, he also mentioned the simplest way is to drop usb_get_dev()/usb_put_dev() like this patchset does. Will you share patches for rtw88/rtw89? I so, I'd drop Greg's patch and apply yours.[1] https://lore.kernel.org/linux-wireless/2026022333-periscope-unusual-f0a0@gregkh/
Sure, I can include rtw88 (and ath10k and ath6kl) in a v2.
Do you really prefer replacing Greg's fix or shall I send an incremental patch on top?
Johan
Ping-Ke Shih
maintainerQuoted 27 lines · Johan Hovold
Quoted 6 lines · Ping-Ke Shih
// +Cc Greg
Hi Johan,
Johan Hovold <[email protected]> wrote:
Quoted 8 lines
[...]
Quoted 3 lines
drivers/net/wireless/realtek/rtl818x/rtl8187/dev.c | 4 ---- drivers/net/wireless/realtek/rtl8xxxu/core.c | 11 +++-------- drivers/net/wireless/realtek/rtlwifi/usb.c | 4 ----Acked to changes of these Realtek WiFi drivers. But I'd like to know why rtw88/rtw89 aren't included in this patchset?
I used a more specific grep pattern to catch driver releasing references in
disconnect()and therefore missed a few that dropped the reference in helper functions (or used non-standard names for their disconnect function such as ath10k, I see now).Quoted 6 lines
Greg sent a patch [1] to
correct error path of USB probe for rtw88. In the discussion, he also mentioned the simplest way is to drop usb_get_dev()/usb_put_dev() like this patchset does. Will you share patches for rtw88/rtw89? I so, I'd drop Greg's patch and apply yours.
Quoted 3 lines
Sure, I can include rtw88 (and ath10k and ath6kl) in a v2.
Can you please also include rtw89? (I saw you have sent v2 though)
Quoted 3 lines
Do you really prefer replacing Greg's fix or shall I send an incremental patch on top?
No. I'd drop Gerg's fix from my tree.
Ping-Ke
Quoted 5 lines · Ping-Ke Shih
Quoted 1 line · Johan Hovold
Sure, I can include rtw88 (and ath10k and ath6kl) in a v2.
Can you please also include rtw89? (I saw you have sent v2 though)
Ah, sorry about that. I was sure I had grepped for usb_get_dev in wireless before sending v2 but apparently I did not.
I just sent a separate follow-up for rtw89 here:
https://lore.kernel.org/r/[email protected]
Johan
Ping-Ke Shih
maintainerQuoted 5 lines · Johan Hovold
Quoted 4 lines · Ping-Ke Shih
Quoted 1 line · Johan Hovold
Sure, I can include rtw88 (and ath10k and ath6kl) in a v2.
Quoted 8 lines
Quoted 1 line
Can you please also include rtw89? (I saw you have sent v2 though)
Ah, sorry about that. I was sure I had grepped for
usb_get_devin wireless before sending v2 but apparently I did not.I just sent a separate follow-up for rtw89 here:
https://lore.kernel.org/r/[email protected]
Got it & thank you. :)
Ping-Ke
Quoted 32 lines · Ping-Ke Shih
Quoted 27 lines · Johan Hovold
Quoted 6 lines · Ping-Ke Shih
// +Cc Greg
Hi Johan,
Johan Hovold <[email protected]> wrote:
Quoted 8 lines
[...]
Quoted 3 lines
drivers/net/wireless/realtek/rtl818x/rtl8187/dev.c | 4 ---- drivers/net/wireless/realtek/rtl8xxxu/core.c | 11 +++-------- drivers/net/wireless/realtek/rtlwifi/usb.c | 4 ----Acked to changes of these Realtek WiFi drivers. But I'd like to know why rtw88/rtw89 aren't included in this patchset?
I used a more specific grep pattern to catch driver releasing references in
disconnect()and therefore missed a few that dropped the reference in helper functions (or used non-standard names for their disconnect function such as ath10k, I see now).Quoted 6 lines
Greg sent a patch [1] to
correct error path of USB probe for rtw88. In the discussion, he also mentioned the simplest way is to drop usb_get_dev()/usb_put_dev() like this patchset does. Will you share patches for rtw88/rtw89? I so, I'd drop Greg's patch and apply yours.Quoted 3 lines
Sure, I can include rtw88 (and ath10k and ath6kl) in a v2.
Quoted 7 lines
Can you please also include rtw89? (I saw you have sent v2 though)
Quoted 3 lines
Do you really prefer replacing Greg's fix or shall I send an incremental patch on top?
No. I'd drop Gerg's fix from my tree.
I have no objection for my changes being dropped, thanks for making these changes.
greg k-h