Re: [PATCH] driver core: fix race between bus_remove_driver() and dev_driver_uevent()

From: Dmitry Torokhov

Date: Wed Nov 04 2026 - 21:29:22 EST


Hi Greg,

On Wed, Oct 14, 2026 at 02:16:50PM +0200, Greg Kroah-Hartman wrote:
> On Tue, Oct 13, 2026 at 11:11:33PM -0700, Dmitry Torokhov wrote:
> > On Wed, Oct 14, 2026 at 07:31:19AM +0200, Greg Kroah-Hartman wrote:
> > > On Tue, Oct 13, 2026 at 08:24:20PM -0700, Dmitry Torokhov wrote:
> > > > @@ -830,6 +830,15 @@ void bus_remove_driver(struct device_driver *drv)
> > > > driver_remove_file(drv, &driver_attr_uevent);
> > > > klist_remove(&drv->p->knode_bus);
> > > > driver_detach(drv);
> > > > +
> > > > + /*
> > > > + * Ensure that any concurrent dev_driver_uevent() that observed
> > > > + * dev->driver before driver_detach() cleared it, finishes
> > > > + * accessing drv->name.
> > > > + */
> > > > + scoped_guard(spinlock, &sp->klist_drivers.k_lock) {
> > > > + }
> > >
> > > Shouldn't the compiler just no-op this away into nothing?
> >
> > It better not. Why would it?
>
> Sorry, early morning before my coffee had kicked in, I was thinking a
> simple lock/unlock pair without any data in the middle might be compiled
> away...
>
> Still feels odd though I don't have a better idea.

Just a gentle ping on this patch. Could it be picked up, or would you
prefer a plain spin_lock()/spin_unlock() pair instead of the empty
scoped_guard() block?

Thanks.

--
Dmitry