All of lore.kernel.org
 help / color / mirror / Atom feed
* [git:media_stage/master] media: mc: mark the media devnode as registered from the, start
@ 2024-04-22  9:41 Hans Verkuil
  0 siblings, 0 replies; only message in thread
From: Hans Verkuil @ 2024-04-22  9:41 UTC (permalink / raw)
  To: linuxtv-commits; +Cc: Sakari Ailus, stable, Laurent Pinchart

This is an automatic generated email to let you know that the following patch were queued:

Subject: media: mc: mark the media devnode as registered from the, start
Author:  Hans Verkuil <hverkuil-cisco@xs4all.nl>
Date:    Fri Feb 23 09:46:19 2024 +0100

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>

 drivers/media/mc/mc-devnode.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

---

diff --git a/drivers/media/mc/mc-devnode.c b/drivers/media/mc/mc-devnode.c
index 7f67825c8757..318e267e798e 100644
--- a/drivers/media/mc/mc-devnode.c
+++ b/drivers/media/mc/mc-devnode.c
@@ -245,15 +245,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:

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2024-04-22  9:41 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-22  9:41 [git:media_stage/master] media: mc: mark the media devnode as registered from the, start Hans Verkuil

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.