Hi Robert, On Sat, May 28, 2011 at 5:15 PM, Robert P. J. Day <rpjday@xxxxxxxxxxxxxx> wrote: > > Âfrom drivers/base/core.c, we have the fairly unambiguous advice: > > * NOTE: _Never_ directly free @dev after calling this function, even > * if it returned an error! Always use put_device() to give up the > * reference initialized in this function instead. > */ > int device_register(struct device *dev) > { >    Âdevice_initialize(dev); >    Âreturn device_add(dev); > } > > Âand yet, there appears to be driver code that does exactly that, > such as this snippet from drivers/w1/w1_int.c (line 86): > >    Â... snip ... >    Âerr = device_register(&dev->dev); >    Âif (err) { >        Âprintk(KERN_ERR "Failed to register master device. err=%d\n", err); >        Âmemset(dev, 0, sizeof(struct w1_master)); >        Âkfree(dev); >        Âdev = NULL; >    Â} Free is for allocated dev not for struct device so it is OK. IMO thi snippet should look like: err = device_register(&dev->dev); if (err) { printk(KERN_ERR "Failed to register master device. err=%d\n", err); put_device(&dev->dev); memset(dev, 0, sizeof(struct w1_master)); kfree(dev); dev = NULL; } > >    Âreturn dev; > > Âisn't the above doing just that -- directly freeing the dev > structure without first calling put_device()? Âor am i misreading > something? > > rday > > -- > > ======================================================================== > Robert P. J. Day                 Ottawa, Ontario, CANADA >            Âhttp://crashcourse.ca > > Twitter:                    http://twitter.com/rpjday > LinkedIn:                http://ca.linkedin.com/in/rpjday > ======================================================================== > > > _______________________________________________ > Kernelnewbies mailing list > Kernelnewbies@xxxxxxxxxxxxxxxxx > http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies > regards, marek -- as simple and primitive as possible ------------------------------------------------- Marek Belisko - OPEN-NANDRA Freelance Developer Ruska Nova Ves 219 | Presov, 08005 Slovak Republic Tel: +421 915 052 184 skype: marekwhite icq: 290551086 web: http://open-nandra.com _______________________________________________ Kernelnewbies mailing list Kernelnewbies@xxxxxxxxxxxxxxxxx http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies