All of lore.kernel.org
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: linux-media@vger.kernel.org
Cc: hverkuil@xs4all.nl, mchehab@infradead.org,
	sakari.ailus@maxwell.research.nokia.com
Subject: v4l: Replace video_is_unregistered with video_is_registered
Date: Wed, 18 Nov 2009 01:38:45 +0100	[thread overview]
Message-ID: <1258504731-8430-5-git-send-email-laurent.pinchart@ideasonboard.com> (raw)
In-Reply-To: <1258504731-8430-1-git-send-email-laurent.pinchart@ideasonboard.com>

Replace the video_is_unregistered function by a video_is_registered
function. The V4L2_FL_UNREGISTERED flag is replaced by a
V4L2_FL_REGISTERED flag.

This change makes the video_is_registered function return coherent
results when called on an initialize but not yet registered video_device
instance. The function can now be used instead of checking
video_device::minor.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Index: v4l-dvb-mc-uvc/linux/drivers/media/video/v4l2-dev.c
===================================================================
--- v4l-dvb-mc-uvc.orig/linux/drivers/media/video/v4l2-dev.c
+++ v4l-dvb-mc-uvc/linux/drivers/media/video/v4l2-dev.c
@@ -227,7 +227,7 @@ static ssize_t v4l2_read(struct file *fi
 
 	if (!vdev->fops->read)
 		return -EINVAL;
-	if (video_is_unregistered(vdev))
+	if (!video_is_registered(vdev))
 		return -EIO;
 	return vdev->fops->read(filp, buf, sz, off);
 }
@@ -239,7 +239,7 @@ static ssize_t v4l2_write(struct file *f
 
 	if (!vdev->fops->write)
 		return -EINVAL;
-	if (video_is_unregistered(vdev))
+	if (!video_is_registered(vdev))
 		return -EIO;
 	return vdev->fops->write(filp, buf, sz, off);
 }
@@ -248,7 +248,7 @@ static unsigned int v4l2_poll(struct fil
 {
 	struct video_device *vdev = video_devdata(filp);
 
-	if (!vdev->fops->poll || video_is_unregistered(vdev))
+	if (!vdev->fops->poll || !video_is_registered(vdev))
 		return DEFAULT_POLLMASK;
 	return vdev->fops->poll(filp, poll);
 }
@@ -288,7 +288,7 @@ static unsigned long v4l2_get_unmapped_a
 
 	if (!vdev->fops->get_unmapped_area)
 		return -ENOSYS;
-	if (video_is_unregistered(vdev))
+	if (!video_is_registered(vdev))
 		return -ENODEV;
 	return vdev->fops->get_unmapped_area(filp, addr, len, pgoff, flags);
 }
@@ -298,8 +298,7 @@ static int v4l2_mmap(struct file *filp, 
 {
 	struct video_device *vdev = video_devdata(filp);
 
-	if (!vdev->fops->mmap ||
-	    video_is_unregistered(vdev))
+	if (!vdev->fops->mmap || !video_is_registered(vdev))
 		return -ENODEV;
 	return vdev->fops->mmap(filp, vm);
 }
@@ -315,7 +314,7 @@ static int v4l2_open(struct inode *inode
 	vdev = video_devdata(filp);
 	/* return ENODEV if the video device has been removed
 	   already or if it is not registered anymore. */
-	if (vdev == NULL || video_is_unregistered(vdev)) {
+	if (vdev == NULL || !video_is_registered(vdev)) {
 		mutex_unlock(&videodev_lock);
 		return -ENODEV;
 	}
@@ -623,6 +622,7 @@ static int __video_register_device(struc
 			name_base, nr, video_device_node_name(vdev));
 
 	/* Part 5: Activate this minor. The char device can now be used. */
+	set_bit(V4L2_FL_REGISTERED, &vdev->flags);
 	mutex_lock(&videodev_lock);
 	video_device[vdev->minor] = vdev;
 	mutex_unlock(&videodev_lock);
@@ -661,11 +661,11 @@ EXPORT_SYMBOL(video_register_device_no_w
 void video_unregister_device(struct video_device *vdev)
 {
 	/* Check if vdev was ever registered at all */
-	if (!vdev || vdev->minor < 0)
+	if (!vdev || !video_is_registered(vdev))
 		return;
 
 	mutex_lock(&videodev_lock);
-	set_bit(V4L2_FL_UNREGISTERED, &vdev->flags);
+	clear_bit(V4L2_FL_REGISTERED, &vdev->flags);
 	mutex_unlock(&videodev_lock);
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 19)
 	class_device_unregister(&vdev->dev);
Index: v4l-dvb-mc-uvc/linux/include/media/v4l2-dev.h
===================================================================
--- v4l-dvb-mc-uvc.orig/linux/include/media/v4l2-dev.h
+++ v4l-dvb-mc-uvc/linux/include/media/v4l2-dev.h
@@ -28,10 +28,10 @@ struct v4l2_ioctl_callbacks;
 struct video_device;
 struct v4l2_device;
 
-/* Flag to mark the video_device struct as unregistered.
-   Drivers can set this flag if they want to block all future
-   device access. It is set by video_unregister_device. */
-#define V4L2_FL_UNREGISTERED	(0)
+/* Flag to mark the video_device struct as registered.
+   Drivers can clear this flag if they want to block all future
+   device access. It is cleared by video_unregister_device. */
+#define V4L2_FL_REGISTERED	(0)
 
 struct v4l2_file_operations {
 	struct module *owner;
@@ -100,9 +100,7 @@ struct video_device
 /* Register video devices. Note that if video_register_device fails,
    the release() callback of the video_device structure is *not* called, so
    the caller is responsible for freeing any data. Usually that means that
-   you call video_device_release() on failure.
-
-   Also note that vdev->minor is set to -1 if the registration failed. */
+   you call video_device_release() on failure. */
 int __must_check video_register_device(struct video_device *vdev, int type, int nr);
 
 /* Same as video_register_device, but no warning is issued if the desired
@@ -110,7 +108,7 @@ int __must_check video_register_device(s
 int __must_check video_register_device_no_warn(struct video_device *vdev, int type, int nr);
 
 /* Unregister video devices. Will do nothing if vdev == NULL or
-   vdev->minor < 0. */
+   video_is_registered() returns false. */
 void video_unregister_device(struct video_device *vdev);
 
 /* helper functions to alloc/release struct video_device, the
@@ -162,9 +160,9 @@ static inline const char *video_device_n
 #endif
 }
 
-static inline int video_is_unregistered(struct video_device *vdev)
+static inline int video_is_registered(struct video_device *vdev)
 {
-	return test_bit(V4L2_FL_UNREGISTERED, &vdev->flags);
+	return test_bit(V4L2_FL_REGISTERED, &vdev->flags);
 }
 
 #endif /* _V4L2_DEV_H */

  parent reply	other threads:[~2009-11-18  0:38 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-11-18  0:38 [PATCH/RFC] V4L core cleanups Laurent Pinchart
2009-11-18  0:38 ` v4l: Add video_device_node_name function Laurent Pinchart
2009-11-18  7:06   ` Hans Verkuil
2009-11-18 12:48     ` Laurent Pinchart
2009-11-18  0:38 ` v4l: Use the new " Laurent Pinchart
2009-11-18  6:29   ` Hans Verkuil
2009-11-18  9:30     ` Laurent Pinchart
2009-11-18  0:38 ` v4l: Remove video_device::num usage from device drivers Laurent Pinchart
2009-11-18  0:38 ` Laurent Pinchart [this message]
2009-11-18  7:15   ` v4l: Replace video_is_unregistered with video_is_registered Hans Verkuil
2009-11-18  0:38 ` hdpvr: " Laurent Pinchart
2009-11-18  0:38 ` v4l: Use the video_is_registered function in device drivers Laurent Pinchart
2009-11-18  0:38 ` v4l: Use the video_drvdata function in drivers Laurent Pinchart
2009-11-18  7:01   ` Hans Verkuil
2009-11-18  8:56     ` Devin Heitmueller
2009-11-18  9:13       ` Hans Verkuil
2009-11-18  9:36         ` Devin Heitmueller
2009-11-18 12:41           ` Laurent Pinchart
2009-11-18  9:42         ` Laurent Pinchart
2009-11-18  9:55           ` Devin Heitmueller
2009-11-18  9:38       ` Laurent Pinchart
2009-11-18  9:32     ` Laurent Pinchart
2009-11-18  0:38 ` v4l: Use video_device_node_name() instead of the minor number Laurent Pinchart
2009-11-18  0:38 ` v4l: Remove unneeded video_device::minor assignments Laurent Pinchart
2009-11-18  0:38 ` v4l: Remove unneeded video_device::minor usage in drivers Laurent Pinchart
2009-11-18  1:31 ` [PATCH/RFC] V4L core cleanups Aguirre, Sergio
2009-11-18 12:57   ` Laurent Pinchart

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1258504731-8430-5-git-send-email-laurent.pinchart@ideasonboard.com \
    --to=laurent.pinchart@ideasonboard.com \
    --cc=hverkuil@xs4all.nl \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@infradead.org \
    --cc=sakari.ailus@maxwell.research.nokia.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.