Skip to contentSkip to conversation

misc: powermate: update the reference count of the usb interface structure

PATCH Superseded Salah Triki 2 participants 4 messages Jul 24, 2021 – Jul 25, 2021

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 misc: powermate: update the reference count of the usb interface structure

Use usb_get_intf() and usb_put_intf() in order to update the reference count of the usb interface structure.

---
 drivers/input/misc/powermate.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/input/misc/powermate.c +2 -1
index c4e0e1886061..69dc3347478a 100644
@@ -337,7 +337,7 @@ static int powermate_probe(struct usb_interface *intf, const struct usb_device_i
 		goto fail3;
 
 	pm->udev = udev;
-	pm->intf = intf;
+	pm->intf = usb_get_intf(intf);
 	pm->input = input_dev;
 
 	usb_make_path(udev, pm->phys, sizeof(pm->phys));
@@ -428,6 +428,7 @@ static void powermate_disconnect(struct usb_interface *intf)
 		usb_free_urb(pm->irq);
 		usb_free_urb(pm->config);
 		powermate_free_buffers(interface_to_usbdev(intf), pm);
+		usb_put_intf(pm->intf);
 
 		kfree(pm);
 	}
Signature · 1 line
2.25.1
maintainer
#1 lore raw

Hi,

Quoted 2 lines · Salah Triki

Use usb_get_intf() and usb_put_intf() in order to update the reference count of the usb interface structure.

This is quite pointless as the driver will be unbound from the interface before interface is deleted.

Quoted 30 lines
---
 drivers/input/misc/powermate.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/input/misc/powermate.c +2 -1
index c4e0e1886061..69dc3347478a 100644
@@ -337,7 +337,7 @@ static int powermate_probe(struct usb_interface *intf, const struct usb_device_i
 		goto fail3;
 
 	pm->udev = udev;
-	pm->intf = intf;
+	pm->intf = usb_get_intf(intf);
 	pm->input = input_dev;
 
 	usb_make_path(udev, pm->phys, sizeof(pm->phys));
@@ -428,6 +428,7 @@ static void powermate_disconnect(struct usb_interface *intf)
 		usb_free_urb(pm->irq);
 		usb_free_urb(pm->config);
 		powermate_free_buffers(interface_to_usbdev(intf), pm);
+		usb_put_intf(pm->intf);
 
 		kfree(pm);
 	}
Signature · 1 line
2.25.1

Thanks.

Signature · 1 line
Dmitry
#2 lore raw

Hi,

Quoted 7 lines · Dmitry Torokhov
Quoted 2 lines · Salah Triki

Use usb_get_intf() and usb_put_intf() in order to update the reference count of the usb interface structure.

This is quite pointless as the driver will be unbound from the interface before interface is deleted.

From the documentation of usb_get_intf():

[quote]

Each live reference to a interface must be refcounted.

Drivers for USB interfaces should normally record such references in their probe() methods, when they bind to an interface, and release them by calling usb_put_intf(), in their disconnect() methods.

[/quote]

Thanx

maintainer
#3 lore raw
Quoted 15 lines · Salah Triki

Hi,

Quoted 7 lines · Dmitry Torokhov
Quoted 2 lines · Salah Triki

Use usb_get_intf() and usb_put_intf() in order to update the reference count of the usb interface structure.

This is quite pointless as the driver will be unbound from the interface before interface is deleted.

From the documentation of usb_get_intf():

[quote]

Quoted 7 lines

Each live reference to a interface must be refcounted.

Drivers for USB interfaces should normally record such references in their probe() methods, when they bind to an interface, and release them by calling usb_put_intf(), in their disconnect() methods.

[/quote]

I see. In this case I recommend you submit a patch to the documentation clarifying this, as taking a reference when binding to an interface makes sense when dealing with a secondary interface, but not primary one. See for example drivers/usb/class/cdc-acm.c where it binds to the data interface, but also locates control interface and bumps up reference to that.

As you may notice there is only a handful of drivers that use this API, and as I am looking at them most do not actually need to use it.

Thanks.

Signature · 1 line
Dmitry