svn commit: r239178 - in head/sys: kern sys
John Baldwin
jhb at freebsd.org
Tue Aug 14 12:59:24 UTC 2012
On Tuesday, August 14, 2012 01:31:58 AM Hans Petter Selasky wrote:
> On Monday 13 August 2012 23:00:25 John Baldwin wrote:
> > int
> > foo_attach(device_t dev)
> > {
> >
> > struct foo_softc *sc;
> >
> > sc = malloc(sizeof(struct foo_softc), M_BUS, M_WAITOK | M_ZERO);
> > device_set_softc(dev, sc);
> > ...
>
> Hi,
>
> Here you forget that there are alot of else/if's that need free(sc, M_BUS)
> for various failing cases! That's why I say +5 lines.
>
> BTW: If we do add device_free_softc, would it be an idea to add
> device_alloc_softc aswell, to make stuff more clear for the drivers?
No. I can't think of any reasonable use case for a driver to do that
(i.e. not let new-bus auto-allocate a softc) where they shouldn't just manage
the entire life cycle themselves.
Also, I still think an extra 5 lines is not too tall of a price to pay to
explicitly note that a given driver uses an abnormal softc life cycle.
However, I think having a device_claim/steal_softc() / device_free_softc() is
clearer than the current approach.
--
John Baldwin
More information about the svn-src-head
mailing list