Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: mc: mark the media devnode as registered from the, start

First the media device node was created, and if successful it was
marked as 'registered'. This leaves a small race condition where
an application can open the device node and get an error back
because the 'registered' flag was not yet set.

Change the order: first set the 'registered' flag, then actually
register the media device node. If that fails, then clear the flag.

Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Fixes: cf4b9211b568 ("[media] media: Media device node support")
Cc: stable@vger.kernel.org
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>

+2 -3
+2 -3
drivers/media/mc/mc-devnode.c
··· 245 245 kobject_set_name(&devnode->cdev.kobj, "media%d", devnode->minor); 246 246 247 247 /* Part 3: Add the media and char device */ 248 + set_bit(MEDIA_FLAG_REGISTERED, &devnode->flags); 248 249 ret = cdev_device_add(&devnode->cdev, &devnode->dev); 249 250 if (ret < 0) { 251 + clear_bit(MEDIA_FLAG_REGISTERED, &devnode->flags); 250 252 pr_err("%s: cdev_device_add failed\n", __func__); 251 253 goto cdev_add_error; 252 254 } 253 - 254 - /* Part 4: Activate this minor. The char device can now be used. */ 255 - set_bit(MEDIA_FLAG_REGISTERED, &devnode->flags); 256 255 257 256 return 0; 258 257