[media] v4l: Make sure we hold a reference to the v4l2_device before using it
v4l2_device_disconnect() calls dev_get_drvdata() and dev_set_drvdata() on the device it received in v4l2_device_register(). Get a reference to the device in v4l2_device_register() to make sure it won't disappear as long as we need it. Reported-by: Sitsofe Wheeler <sitsofe@yahoo.com> Signed-off-by: Dave Young <hidave.darkstar@gmail.com> Tested-by: Sitsofe Wheeler <sitsofe@yahoo.com> Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
This commit is contained in:
parent
8280b662df
commit
236c5441d7
|
@ -38,6 +38,7 @@ int v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev)
|
||||||
mutex_init(&v4l2_dev->ioctl_lock);
|
mutex_init(&v4l2_dev->ioctl_lock);
|
||||||
v4l2_prio_init(&v4l2_dev->prio);
|
v4l2_prio_init(&v4l2_dev->prio);
|
||||||
kref_init(&v4l2_dev->ref);
|
kref_init(&v4l2_dev->ref);
|
||||||
|
get_device(dev);
|
||||||
v4l2_dev->dev = dev;
|
v4l2_dev->dev = dev;
|
||||||
if (dev == NULL) {
|
if (dev == NULL) {
|
||||||
/* If dev == NULL, then name must be filled in by the caller */
|
/* If dev == NULL, then name must be filled in by the caller */
|
||||||
|
@ -93,6 +94,7 @@ void v4l2_device_disconnect(struct v4l2_device *v4l2_dev)
|
||||||
|
|
||||||
if (dev_get_drvdata(v4l2_dev->dev) == v4l2_dev)
|
if (dev_get_drvdata(v4l2_dev->dev) == v4l2_dev)
|
||||||
dev_set_drvdata(v4l2_dev->dev, NULL);
|
dev_set_drvdata(v4l2_dev->dev, NULL);
|
||||||
|
put_device(v4l2_dev->dev);
|
||||||
v4l2_dev->dev = NULL;
|
v4l2_dev->dev = NULL;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(v4l2_device_disconnect);
|
EXPORT_SYMBOL_GPL(v4l2_device_disconnect);
|
||||||
|
|
Loading…
Reference in a new issue