Skip to contentSkip to conversation

wifi: rt2x00usb: fix devres lifetime

PATCH In review Johan Hovold 3 participants 3 messages Mar 27

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 wifi: rt2x00usb: fix devres lifetime

USB drivers bind to USB interfaces and any device managed resources should have their lifetime tied to the interface rather than parent USB device. This avoids issues like memory leaks when drivers are unbound without their devices being physically disconnected (e.g. on probe deferral or configuration changes).

Fix the USB anchor lifetime so that it is released on driver unbind.

Fixes 8b4c0009313f ("rt2x00usb: Use usb anchor to manage URB")
Cc Vishal Thanki <[email protected]>
---
 drivers/net/wireless/ralink/rt2x00/rt2x00usb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/ralink/rt2x00/rt2x00usb.c +1 -1
index 83d00b6baf64..174d89b0b1d7 100644
@@ -826,7 +826,7 @@ int rt2x00usb_probe(struct usb_interface *usb_intf,
 	if (retval)
 		goto exit_free_device;
 
-	rt2x00dev->anchor = devm_kmalloc(&usb_dev->dev,
+	rt2x00dev->anchor = devm_kmalloc(&usb_intf->dev,
 					sizeof(struct usb_anchor),
 					GFP_KERNEL);
 	if (!rt2x00dev->anchor) {
Signature · 1 line
2.52.0
maintainer Acked-by on v2 1/1
#1 lore raw
Quoted 6 lines · Johan Hovold

USB drivers bind to USB interfaces and any device managed resources should have their lifetime tied to the interface rather than parent USB device. This avoids issues like memory leaks when drivers are unbound without their devices being physically disconnected (e.g. on probe deferral or configuration changes).

Quoted 6 lines

Fix the USB anchor lifetime so that it is released on driver unbind.

Fixes 8b4c0009313f ("rt2x00usb: Use usb anchor to manage URB")
Cc Vishal Thanki <[email protected]>
Quoted 20 lines
---
 drivers/net/wireless/ralink/rt2x00/rt2x00usb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/ralink/rt2x00/rt2x00usb.c +1 -1
index 83d00b6baf64..174d89b0b1d7 100644
@@ -826,7 +826,7 @@ int rt2x00usb_probe(struct usb_interface *usb_intf,
 	if (retval)
 		goto exit_free_device;
 
-	rt2x00dev->anchor = devm_kmalloc(&usb_dev->dev,
+	rt2x00dev->anchor = devm_kmalloc(&usb_intf->dev,
 					sizeof(struct usb_anchor),
 					GFP_KERNEL);
 	if (!rt2x00dev->anchor) {
Signature · 1 line
2.52.0
maintainer Reviewed-by on v2 1/1
#2 lore raw
In reply to Johan Hovold
Quoted 33 lines · Johan Hovold

USB drivers bind to USB interfaces and any device managed resources should have their lifetime tied to the interface rather than parent USB device. This avoids issues like memory leaks when drivers are unbound without their devices being physically disconnected (e.g. on probe deferral or configuration changes).

Fix the USB anchor lifetime so that it is released on driver unbind.

Fixes 8b4c0009313f ("rt2x00usb: Use usb anchor to manage URB")
Cc Vishal Thanki <[email protected]>
---
 drivers/net/wireless/ralink/rt2x00/rt2x00usb.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/wireless/ralink/rt2x00/rt2x00usb.c +1 -1
index 83d00b6baf64..174d89b0b1d7 100644
@@ -826,7 +826,7 @@ int rt2x00usb_probe(struct usb_interface *usb_intf,
 	if (retval)
 		goto exit_free_device;
 
-	rt2x00dev->anchor = devm_kmalloc(&usb_dev->dev,
+	rt2x00dev->anchor = devm_kmalloc(&usb_intf->dev,
 					sizeof(struct usb_anchor),
 					GFP_KERNEL);
 	if (!rt2x00dev->anchor) {
Signature · 1 line
2.52.0