[media] v4l: Allow calling v4l2_device_register_subdev_nodes() multiple times
authorSebastian Reichel <sre@kernel.org>
Tue, 14 Feb 2017 22:38:49 +0000 (20:38 -0200)
committerMauro Carvalho Chehab <mchehab@s-opensource.com>
Wed, 22 Mar 2017 14:21:43 +0000 (11:21 -0300)
Previously multiple calls to v4l2_device_register_subdev_nodes() ended up
corrupting memory and leaking some, too. This patch changes the behaviour so
that sub-devices the device nodes of which are already registered are
ignored.

Signed-off-by: Sebastian Reichel <sre@kernel.org>
Signed-off-by: Ivaylo Dimitrov <ivo.g.dimitrov.75@gmail.com>
Signed-off-by: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
drivers/media/v4l2-core/v4l2-device.c

index f364cc1b521dcd65919cb8a548e3f3d18acf6880..937c6de85606d6855b0899a5e77470297bf8a568 100644 (file)
@@ -235,6 +235,9 @@ int v4l2_device_register_subdev_nodes(struct v4l2_device *v4l2_dev)
                if (!(sd->flags & V4L2_SUBDEV_FL_HAS_DEVNODE))
                        continue;
 
+               if (sd->devnode)
+                       continue;
+
                vdev = kzalloc(sizeof(*vdev), GFP_KERNEL);
                if (!vdev) {
                        err = -ENOMEM;