Commit 957b4aa9 authored by Laurent Pinchart's avatar Laurent Pinchart Committed by Mauro Carvalho Chehab

V4L/DVB (13552): v4l: Replace video_is_unregistered with video_is_registered

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: default avatarLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab@redhat.com>
parent 0fda5d44
...@@ -523,7 +523,7 @@ static unsigned int hdpvr_poll(struct file *filp, poll_table *wait) ...@@ -523,7 +523,7 @@ static unsigned int hdpvr_poll(struct file *filp, poll_table *wait)
mutex_lock(&dev->io_mutex); mutex_lock(&dev->io_mutex);
if (video_is_unregistered(dev->video_dev)) { if (!video_is_registered(dev->video_dev)) {
mutex_unlock(&dev->io_mutex); mutex_unlock(&dev->io_mutex);
return -EIO; return -EIO;
} }
......
...@@ -189,7 +189,7 @@ static ssize_t v4l2_read(struct file *filp, char __user *buf, ...@@ -189,7 +189,7 @@ static ssize_t v4l2_read(struct file *filp, char __user *buf,
if (!vdev->fops->read) if (!vdev->fops->read)
return -EINVAL; return -EINVAL;
if (video_is_unregistered(vdev)) if (!video_is_registered(vdev))
return -EIO; return -EIO;
return vdev->fops->read(filp, buf, sz, off); return vdev->fops->read(filp, buf, sz, off);
} }
...@@ -201,7 +201,7 @@ static ssize_t v4l2_write(struct file *filp, const char __user *buf, ...@@ -201,7 +201,7 @@ static ssize_t v4l2_write(struct file *filp, const char __user *buf,
if (!vdev->fops->write) if (!vdev->fops->write)
return -EINVAL; return -EINVAL;
if (video_is_unregistered(vdev)) if (!video_is_registered(vdev))
return -EIO; return -EIO;
return vdev->fops->write(filp, buf, sz, off); return vdev->fops->write(filp, buf, sz, off);
} }
...@@ -210,7 +210,7 @@ static unsigned int v4l2_poll(struct file *filp, struct poll_table_struct *poll) ...@@ -210,7 +210,7 @@ static unsigned int v4l2_poll(struct file *filp, struct poll_table_struct *poll)
{ {
struct video_device *vdev = video_devdata(filp); 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 DEFAULT_POLLMASK;
return vdev->fops->poll(filp, poll); return vdev->fops->poll(filp, poll);
} }
...@@ -250,7 +250,7 @@ static unsigned long v4l2_get_unmapped_area(struct file *filp, ...@@ -250,7 +250,7 @@ static unsigned long v4l2_get_unmapped_area(struct file *filp,
if (!vdev->fops->get_unmapped_area) if (!vdev->fops->get_unmapped_area)
return -ENOSYS; return -ENOSYS;
if (video_is_unregistered(vdev)) if (!video_is_registered(vdev))
return -ENODEV; return -ENODEV;
return vdev->fops->get_unmapped_area(filp, addr, len, pgoff, flags); return vdev->fops->get_unmapped_area(filp, addr, len, pgoff, flags);
} }
...@@ -260,8 +260,7 @@ static int v4l2_mmap(struct file *filp, struct vm_area_struct *vm) ...@@ -260,8 +260,7 @@ static int v4l2_mmap(struct file *filp, struct vm_area_struct *vm)
{ {
struct video_device *vdev = video_devdata(filp); struct video_device *vdev = video_devdata(filp);
if (!vdev->fops->mmap || if (!vdev->fops->mmap || !video_is_registered(vdev))
video_is_unregistered(vdev))
return -ENODEV; return -ENODEV;
return vdev->fops->mmap(filp, vm); return vdev->fops->mmap(filp, vm);
} }
...@@ -277,7 +276,7 @@ static int v4l2_open(struct inode *inode, struct file *filp) ...@@ -277,7 +276,7 @@ static int v4l2_open(struct inode *inode, struct file *filp)
vdev = video_devdata(filp); vdev = video_devdata(filp);
/* return ENODEV if the video device has been removed /* return ENODEV if the video device has been removed
already or if it is not registered anymore. */ 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); mutex_unlock(&videodev_lock);
return -ENODEV; return -ENODEV;
} }
...@@ -555,6 +554,7 @@ static int __video_register_device(struct video_device *vdev, int type, int nr, ...@@ -555,6 +554,7 @@ static int __video_register_device(struct video_device *vdev, int type, int nr,
name_base, nr, video_device_node_name(vdev)); name_base, nr, video_device_node_name(vdev));
/* Part 5: Activate this minor. The char device can now be used. */ /* Part 5: Activate this minor. The char device can now be used. */
set_bit(V4L2_FL_REGISTERED, &vdev->flags);
mutex_lock(&videodev_lock); mutex_lock(&videodev_lock);
video_device[vdev->minor] = vdev; video_device[vdev->minor] = vdev;
mutex_unlock(&videodev_lock); mutex_unlock(&videodev_lock);
...@@ -593,11 +593,11 @@ EXPORT_SYMBOL(video_register_device_no_warn); ...@@ -593,11 +593,11 @@ EXPORT_SYMBOL(video_register_device_no_warn);
void video_unregister_device(struct video_device *vdev) void video_unregister_device(struct video_device *vdev)
{ {
/* Check if vdev was ever registered at all */ /* Check if vdev was ever registered at all */
if (!vdev || vdev->minor < 0) if (!vdev || !video_is_registered(vdev))
return; return;
mutex_lock(&videodev_lock); mutex_lock(&videodev_lock);
set_bit(V4L2_FL_UNREGISTERED, &vdev->flags); clear_bit(V4L2_FL_REGISTERED, &vdev->flags);
mutex_unlock(&videodev_lock); mutex_unlock(&videodev_lock);
device_unregister(&vdev->dev); device_unregister(&vdev->dev);
} }
......
...@@ -28,10 +28,10 @@ struct v4l2_ioctl_callbacks; ...@@ -28,10 +28,10 @@ struct v4l2_ioctl_callbacks;
struct video_device; struct video_device;
struct v4l2_device; struct v4l2_device;
/* Flag to mark the video_device struct as unregistered. /* Flag to mark the video_device struct as registered.
Drivers can set this flag if they want to block all future Drivers can clear this flag if they want to block all future
device access. It is set by video_unregister_device. */ device access. It is cleared by video_unregister_device. */
#define V4L2_FL_UNREGISTERED (0) #define V4L2_FL_REGISTERED (0)
struct v4l2_file_operations { struct v4l2_file_operations {
struct module *owner; struct module *owner;
...@@ -96,9 +96,7 @@ struct video_device ...@@ -96,9 +96,7 @@ struct video_device
/* Register video devices. Note that if video_register_device fails, /* Register video devices. Note that if video_register_device fails,
the release() callback of the video_device structure is *not* called, so the release() callback of the video_device structure is *not* called, so
the caller is responsible for freeing any data. Usually that means that the caller is responsible for freeing any data. Usually that means that
you call video_device_release() on failure. you call video_device_release() on failure. */
Also note that vdev->minor is set to -1 if the registration failed. */
int __must_check video_register_device(struct video_device *vdev, int type, int nr); 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 /* Same as video_register_device, but no warning is issued if the desired
...@@ -106,7 +104,7 @@ int __must_check video_register_device(struct video_device *vdev, int type, int ...@@ -106,7 +104,7 @@ int __must_check video_register_device(struct video_device *vdev, int type, int
int __must_check video_register_device_no_warn(struct video_device *vdev, int type, int nr); 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 /* 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); void video_unregister_device(struct video_device *vdev);
/* helper functions to alloc/release struct video_device, the /* helper functions to alloc/release struct video_device, the
...@@ -146,9 +144,9 @@ static inline const char *video_device_node_name(struct video_device *vdev) ...@@ -146,9 +144,9 @@ static inline const char *video_device_node_name(struct video_device *vdev)
return dev_name(&vdev->dev); return dev_name(&vdev->dev);
} }
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 */ #endif /* _V4L2_DEV_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment