* [PATCH] misc: powermate: update the reference count of the usb interface structure
@ 2021-07-24 21:20 Salah Triki
2021-07-24 23:08 ` Dmitry Torokhov
0 siblings, 1 reply; 4+ messages in thread
From: Salah Triki @ 2021-07-24 21:20 UTC (permalink / raw)
To: Dmitry Torokhov, gregkh; +Cc: linux-input, linux-kernel
Use usb_get_intf() and usb_put_intf() in order to update the reference
count of the usb interface structure.
Signed-off-by: Salah Triki <salah.triki@gmail.com>
---
drivers/input/misc/powermate.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/input/misc/powermate.c b/drivers/input/misc/powermate.c
index c4e0e1886061..69dc3347478a 100644
--- a/drivers/input/misc/powermate.c
+++ b/drivers/input/misc/powermate.c
@@ -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);
}
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] misc: powermate: update the reference count of the usb interface structure
2021-07-24 21:20 [PATCH] misc: powermate: update the reference count of the usb interface structure Salah Triki
@ 2021-07-24 23:08 ` Dmitry Torokhov
2021-07-24 23:56 ` Salah Triki
0 siblings, 1 reply; 4+ messages in thread
From: Dmitry Torokhov @ 2021-07-24 23:08 UTC (permalink / raw)
To: Salah Triki; +Cc: gregkh, linux-input, linux-kernel
Hi,
On Sat, Jul 24, 2021 at 10:20:16PM +0100, Salah Triki wrote:
> 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.
>
> Signed-off-by: Salah Triki <salah.triki@gmail.com>
> ---
> drivers/input/misc/powermate.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/input/misc/powermate.c b/drivers/input/misc/powermate.c
> index c4e0e1886061..69dc3347478a 100644
> --- a/drivers/input/misc/powermate.c
> +++ b/drivers/input/misc/powermate.c
> @@ -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);
> }
> --
> 2.25.1
>
Thanks.
--
Dmitry
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] misc: powermate: update the reference count of the usb interface structure
2021-07-24 23:08 ` Dmitry Torokhov
@ 2021-07-24 23:56 ` Salah Triki
2021-07-25 4:35 ` Dmitry Torokhov
0 siblings, 1 reply; 4+ messages in thread
From: Salah Triki @ 2021-07-24 23:56 UTC (permalink / raw)
To: Dmitry Torokhov; +Cc: gregkh, linux-input, linux-kernel
Hi,
On Sat, Jul 24, 2021 at 04:08:02PM -0700, Dmitry Torokhov wrote:
>
> On Sat, Jul 24, 2021 at 10:20:16PM +0100, Salah Triki wrote:
> > 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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] misc: powermate: update the reference count of the usb interface structure
2021-07-24 23:56 ` Salah Triki
@ 2021-07-25 4:35 ` Dmitry Torokhov
0 siblings, 0 replies; 4+ messages in thread
From: Dmitry Torokhov @ 2021-07-25 4:35 UTC (permalink / raw)
To: Salah Triki; +Cc: gregkh, linux-input, linux-kernel
On Sun, Jul 25, 2021 at 12:56:37AM +0100, Salah Triki wrote:
> Hi,
>
> On Sat, Jul 24, 2021 at 04:08:02PM -0700, Dmitry Torokhov wrote:
> >
> > On Sat, Jul 24, 2021 at 10:20:16PM +0100, Salah Triki wrote:
> > > 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]
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.
--
Dmitry
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-07-25 4:35 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-24 21:20 [PATCH] misc: powermate: update the reference count of the usb interface structure Salah Triki
2021-07-24 23:08 ` Dmitry Torokhov
2021-07-24 23:56 ` Salah Triki
2021-07-25 4:35 ` Dmitry Torokhov
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.