Re: [PATCH 10/13] wifi: rt2x00: drop redundant device reference
From: Johan Hovold
Date: Thu Mar 05 2026 - 09:15:58 EST
On Thu, Mar 05, 2026 at 02:37:55PM +0100, Stanislaw Gruszka wrote:
> On Thu, Mar 05, 2026 at 12:07:10PM +0100, Johan Hovold wrote:
> > 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 <stern@xxxxxxxxxxxxxxxxxxx>
> 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.
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