Date: Mon, 27 Feb 2012 12:31:33 -0700 From: Warner Losh <imp@bsdimp.com> To: John Baldwin <jhb@freebsd.org> Cc: Warner Losh <imp@freebsd.org>, new-bus@freebsd.org, des@freebsd.org Subject: Re: device_detach() never clears devclasses Message-ID: <DCABE43A-BA2D-4A6A-9743-A87827FF8013@bsdimp.com> In-Reply-To: <201202271208.15664.jhb@freebsd.org> References: <201202271208.15664.jhb@freebsd.org>
next in thread | previous in thread | raw e-mail | index | archive | help
This looks good to me. I think I should have had !=3D here anyway. :) Warner On Feb 27, 2012, at 10:08 AM, John Baldwin wrote: > I haven't reproduced this, I just have a hunch based on code-reading = while=20 > fixing another bug. Ah, looking in SVN history it looks like this was = broken=20 > in 129711 when device_attach() was split out of = device_probe_and_attach(). =20 > Specifically, if DEVICE_ATTACH() fails then this: >=20 > /* Unset the class; set in device_probe_child */ > if (dev->devclass =3D=3D NULL) > (void)device_set_devclass(dev, NULL); >=20 > is wrong. dev->devclass is always non-NULL at this point. However, = we should=20 > be clearing the devclass for any device that doesn't have a fixed = device=20 > class. And in fact that is what device_detach() does: >=20 > if (!(dev->flags & DF_FIXEDCLASS)) > devclass_delete_device(dev->devclass, dev); >=20 > The patch below fixes this: >=20 > Index: subr_bus.c > =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D > --- subr_bus.c (revision 232218) > +++ subr_bus.c (working copy) > @@ -2732,9 +2732,8 @@ device_attach(device_t dev) > if ((error =3D DEVICE_ATTACH(dev)) !=3D 0) { > printf("device_attach: %s%d attach returned %d\n", > dev->driver->name, dev->unit, error); > - /* Unset the class; set in device_probe_child */ > - if (dev->devclass =3D=3D NULL) > - (void)device_set_devclass(dev, NULL); > + if (!(dev->flags & DF_FIXEDCLASS)) > + devclass_delete_device(dev->devclass, dev); > (void)device_set_driver(dev, NULL); > device_sysctl_fini(dev); > dev->state =3D DS_NOTPRESENT; >=20 >=20 > --=20 > John Baldwin >=20 >=20
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?DCABE43A-BA2D-4A6A-9743-A87827FF8013>