xshm: release misc device on error
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
Hi Dan,
Quoted 9 lines
Smatch complains that we don't release the misc device on error.
1055 if (mutex_lock_interruptible(&dev->mutex)) {
1056xdev_dbg(dev, "mutex_lock_interruptible got signalled\n");-> if result is 0 here we should release it. Should we call
xshmchr_put()ormisc_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