]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
media: mc: mark the media devnode as registered from the, start
authorHans Verkuil <hverkuil-cisco@xs4all.nl>
Fri, 23 Feb 2024 08:46:19 +0000 (09:46 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sun, 16 Jun 2024 11:32:33 +0000 (13:32 +0200)
commit 4bc60736154bc9e0e39d3b88918f5d3762ebe5e0 upstream.

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>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/media/mc/mc-devnode.c

index f11382afe23bf280736244026890924d4f4729ba..f249199dc616b9e935d0056bc8cf81f1dd0f533d 100644 (file)
@@ -246,15 +246,14 @@ int __must_check media_devnode_register(struct media_device *mdev,
        kobject_set_name(&devnode->cdev.kobj, "media%d", devnode->minor);
 
        /* Part 3: Add the media and char device */
+       set_bit(MEDIA_FLAG_REGISTERED, &devnode->flags);
        ret = cdev_device_add(&devnode->cdev, &devnode->dev);
        if (ret < 0) {
+               clear_bit(MEDIA_FLAG_REGISTERED, &devnode->flags);
                pr_err("%s: cdev_device_add failed\n", __func__);
                goto cdev_add_error;
        }
 
-       /* Part 4: Activate this minor. The char device can now be used. */
-       set_bit(MEDIA_FLAG_REGISTERED, &devnode->flags);
-
        return 0;
 
 cdev_add_error: