UPSTREAM: media: lirc: do not call close() or open() on unregistered devices

If a lirc chardev is held open after a device is unplugged, rc_close()
will be called after rc_unregister_device(). The driver is not expecting
any calls at this point, and the iguanair driver causes an oops in
this scenario.

rc_open() can be called when the device is removed too, by calling open
on the chardev whilst the device is being removed.

Signed-off-by: Sean Young <sean@mess.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
(cherry picked from commit cb84343fce)
Signed-off-by: Ziyuan Xu <xzy.xu@rock-chips.com>
This commit is contained in:
Sean Young
2017-09-23 17:44:03 -04:00
committed by Tao Huang
parent 414df6823c
commit 9c761aedd1

View File

@@ -862,11 +862,15 @@ int rc_open(struct rc_dev *rdev)
mutex_lock(&rdev->lock);
if (!rdev->users++ && rdev->open != NULL)
rval = rdev->open(rdev);
if (!rdev->registered) {
rval = -ENODEV;
} else {
if (!rdev->users++ && rdev->open)
rval = rdev->open(rdev);
if (rval)
rdev->users--;
if (rval)
rdev->users--;
}
mutex_unlock(&rdev->lock);
@@ -885,7 +889,7 @@ void rc_close(struct rc_dev *rdev)
if (rdev) {
mutex_lock(&rdev->lock);
if (!--rdev->users && rdev->close != NULL)
if (!--rdev->users && rdev->close && rdev->registered)
rdev->close(rdev);
mutex_unlock(&rdev->lock);