summaryrefslogtreecommitdiffstats
path: root/drivers/media
diff options
context:
space:
mode:
authorHans Verkuil2013-06-12 11:04:04 +0200
committerMauro Carvalho Chehab2013-06-21 16:00:51 +0200
commit9e882e3bc97c7774b93f3db483d2e75767b5cad1 (patch)
treec9d22c0f50320c0303b89ab9f33363dfcda64337 /drivers/media
parent[media] cx88: fix register mask (diff)
downloadkernel-qcow2-linux-9e882e3bc97c7774b93f3db483d2e75767b5cad1.tar.gz
kernel-qcow2-linux-9e882e3bc97c7774b93f3db483d2e75767b5cad1.tar.xz
kernel-qcow2-linux-9e882e3bc97c7774b93f3db483d2e75767b5cad1.zip
[media] v4l2-device: check if already unregistered
It was possible to unregister an already unregistered v4l2_device struct. Add a check whether that already happened and just return if that was the case. Also refuse to register a v4l2_device if both the dev and name fields are empty. A warning was already produced in that case, but since the name field is now used to detect whether or not the v4l2_device was already unregistered this particular combination should be rejected. Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media')
-rw-r--r--drivers/media/v4l2-core/v4l2-device.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
index 2dbfebc0ca85..02d1b6327117 100644
--- a/drivers/media/v4l2-core/v4l2-device.c
+++ b/drivers/media/v4l2-core/v4l2-device.c
@@ -44,7 +44,8 @@ int v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev)
v4l2_dev->dev = dev;
if (dev == NULL) {
/* If dev == NULL, then name must be filled in by the caller */
- WARN_ON(!v4l2_dev->name[0]);
+ if (WARN_ON(!v4l2_dev->name[0]))
+ return -EINVAL;
return 0;
}
@@ -105,7 +106,9 @@ void v4l2_device_unregister(struct v4l2_device *v4l2_dev)
{
struct v4l2_subdev *sd, *next;
- if (v4l2_dev == NULL)
+ /* Just return if v4l2_dev is NULL or if it was already
+ * unregistered before. */
+ if (v4l2_dev == NULL || !v4l2_dev->name[0])
return;
v4l2_device_disconnect(v4l2_dev);
@@ -135,6 +138,8 @@ void v4l2_device_unregister(struct v4l2_device *v4l2_dev)
}
#endif
}
+ /* Mark as unregistered, thus preventing duplicate unregistrations */
+ v4l2_dev->name[0] = '\0';
}
EXPORT_SYMBOL_GPL(v4l2_device_unregister);