From mboxrd@z Thu Jan 1 00:00:00 1970 From: marek.belisko@gmail.com (Belisko Marek) Date: Sat, 28 May 2011 22:22:20 +0200 Subject: should failed calls to device_register() always call put_device()? In-Reply-To: References: Message-ID: To: kernelnewbies@lists.kernelnewbies.org List-Id: kernelnewbies.lists.kernelnewbies.org On Sat, May 28, 2011 at 9:43 PM, Robert P. J. Day wrote: > On Sat, 28 May 2011, Belisko Marek wrote: > >> On Sat, May 28, 2011 at 6:29 PM, Robert P. J. Day wrote: >> > >> > ?i agree that there should be a "put_device(&dev->dev);" statement >> > as you show above. ?however, i still don't see how this can be >> > just a stylistic improvement as you seem to suggest. ?based on the >> > warning from the kernel source file, it would seem that you *must* >> > do a put_device() in that situation -- it's not optional. > >> Sure you're right. You can send a patch to fix this problem. Good >> catch. > > ?i didn't want to submit anything until i verified what correct code > should look like. ?and it's not like that's the only example -- others > are trivially easy to find, like this in > drivers/media/video/bt8xx/bttv-gpio.c (line 97): > > ?err = device_register(&sub->dev); > ?if (0 != err) { > ? ? ? ? ? kfree(sub); > ? ? ? ? ? return err; > ?} I'm little bit confused. If you look at device_add which is part of device_register if something in device_add failed it will always call put_device (in any error case) so why then is necessary to call it again when device_register return error? As you said on some places put_device is used on some not. Assume device_register in normal conditions don't fail so this code is not called anyway or? > > that would seem to be incorrect as well, no? > > rday > > -- > > ======================================================================== > Robert P. J. Day ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Ottawa, Ontario, CANADA > ? ? ? ? ? ? ? ? ? ? ? ?http://crashcourse.ca > > Twitter: ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? http://twitter.com/rpjday > LinkedIn: ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? http://ca.linkedin.com/in/rpjday > ======================================================================== 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