should failed calls to device_register() always call put_device()?

Robert P. J. Day rpjday at crashcourse.ca
Sun May 29 08:49:31 EDT 2011


On Sun, 29 May 2011, Greg KH wrote:

> On Sun, May 29, 2011 at 07:21:10AM -0400, Robert P. J. Day wrote:

> >   what is apparently *not* OK is to either call kfree() *before*
> > calling put_device(), or to call kfree() and nothing else upon a
> > failed device_register() call.  some apparently broken code from
> > the current drivers/ directory:
>
> no, again, never call kfree, you already did that in your release
> callback that the final put_device() call called.

  ah, that's the part i was missing -- that the enclosing structure
would have been freed already via the kfree() in the release callback.
i'll look at that code later.

> >   so as you can see, there's numerous examples of failed calls to
> > device_register() that never call put_device() and simply bail or
> > call kfree().  do these examples represent bad code?  because it's
> > not hard to find lots of examples of it.
>
> Yes, that's wrong.  I'm sure you can write a spatch rule to catch
> and fix these automatically.

  i was already looking into that.

rday

-- 

========================================================================
Robert P. J. Day                                 Ottawa, Ontario, CANADA
                        http://crashcourse.ca

Twitter:                                       http://twitter.com/rpjday
LinkedIn:                               http://ca.linkedin.com/in/rpjday
========================================================================



More information about the Kernelnewbies mailing list