Re: [PATCH 1/1] usb: gadget: f_hid: Conduct proper refcounting on shared f_hidg pointer

From: Alan Stern
Date: Fri Nov 18 2022 - 16:07:31 EST


On Fri, Nov 18, 2022 at 04:37:32PM +0000, John Keeping wrote:
> I don't think it's at all simple to fix this - I posted a series
> addressing the lifetime issues here a few years ago but didn't chase it
> up and there was no feedback:
>
> https://lore.kernel.org/linux-usb/20191028114228.3679219-1-john@xxxxxxxxxxxx/
>
> That includes a patch to remove the embedded struct cdev and manage its
> lifetime separately, which I think is needed as there are two different
> struct device objects here and we cannot tie their lifetimes together.

I still don't have a clear picture of what the real problem is. Lee's
original patch description just said "external references are presently
not tracked", with no details about what those external references are.
Why not add just proper cdev_get() and cdev_put() calls to whatever code
handles those external references, so that they _are_ tracked?

What are the two different struct device objects? Why do their
lifetimes need to be tied together? If you do need to tie their
lifetimes somehow, why not simply make one of them (the one which is
logically allowed to be shorter-lived) hold a reference to the other?

Alan Stern