* [smatch stuff] xshm: release misc device on error
@ 2011-12-08 19:24 Dan Carpenter
2011-12-09 12:39 ` Sjur BRENDELAND
0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2011-12-08 19:24 UTC (permalink / raw)
To: kernel-janitors
Hi Sjur,
Smatch complains that we don't release the misc device on error.
drivers/xshm/xshm_chr.c +1057 cfshm_probe(75)
warn: '&dev->misc' was not released on error
1043 /* Register the device. */
1044 dev->misc.parent = &xshm->pdev.dev;
1045 result = misc_register(&dev->misc);
1046
1047 /* Lock in order to try to stop someone from opening the device
1048 * too early. The misc device has its own lock. We cannot take our
1049 * lock until misc_register() is finished, because in open() the
1050 * locks are taken in this order (misc first and then dev).
1051 * So anyone managing to open the device between the misc_register
1052 * and the mutex_lock will get a "device not found" error. Don't
1053 * think it can be avoided.
1054 */
1055 if (mutex_lock_interruptible(&dev->mutex)) {
1056 xdev_dbg(dev, "mutex_lock_interruptible got signalled\n");
-> if result is 0 here we should release it. Should we call
xshmchr_put() or misc_deregister()?
1057 return -ERESTARTSYS;
1058 }
1059
1060 if (result < 0) {
1061 pr_warn("XSHMCHR: chnl_chr: error - %d, can't register misc.\n",
1062 result);
1063 mutex_unlock(&dev->mutex);
1064 goto err_failed;
1065 }
regards,
dan carpenter
^ permalink raw reply [flat|nested] 2+ messages in thread
* RE: [smatch stuff] xshm: release misc device on error
2011-12-08 19:24 [smatch stuff] xshm: release misc device on error Dan Carpenter
@ 2011-12-09 12:39 ` Sjur BRENDELAND
0 siblings, 0 replies; 2+ messages in thread
From: Sjur BRENDELAND @ 2011-12-09 12:39 UTC (permalink / raw)
To: kernel-janitors
Hi Dan,
>Smatch complains that we don't release the misc device on error.
> 1055 if (mutex_lock_interruptible(&dev->mutex)) {
> 1056 xdev_dbg(dev, "mutex_lock_interruptible got signalled\n");
>
>-> if result is 0 here we should release it. Should we call
>xshmchr_put() or misc_deregister()?
>
> 1057 return -ERESTARTSYS;
> 1058 }
Thank you for spotting this!
If we take the mutex before registering the misc device it's
impossible for anyone else to take the mutex.
So I think I will simply call mutex_lock() before misc_register().
I will fix this in my next patch-set,
Thanks,
Sjur
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-12-09 12:39 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-08 19:24 [smatch stuff] xshm: release misc device on error Dan Carpenter
2011-12-09 12:39 ` Sjur BRENDELAND
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox