From 3259081991a9398434f6f49468b960f136ac0158 Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Wed, 25 Apr 2018 05:34:48 -0400 Subject: MAINTAINERS & files: Canonize the e-mails I use at files From now on, I'll start using my @kernel.org as my development e-mail. As such, let's remove the entries that point to the old mchehab@s-opensource.com at MAINTAINERS file. For the files written with a copyright with mchehab@s-opensource, let's keep Samsung on their names, using mchehab+samsung@kernel.org, in order to keep pointing to my employer, with sponsors the work. For the files written before I join Samsung (on July, 4 2013), let's just use mchehab@kernel.org. For bug reports, we can simply point to just kernel.org, as this will reach my mchehab+samsung inbox anyway. Signed-off-by: Mauro Carvalho Chehab Signed-off-by: Brian Warner Signed-off-by: Mauro Carvalho Chehab --- drivers/media/v4l2-core/v4l2-dev.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/media/v4l2-core/v4l2-dev.c') diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c index 1d0b2208e8fb..c080dcc75393 100644 --- a/drivers/media/v4l2-core/v4l2-dev.c +++ b/drivers/media/v4l2-core/v4l2-dev.c @@ -10,7 +10,7 @@ * 2 of the License, or (at your option) any later version. * * Authors: Alan Cox, (version 1) - * Mauro Carvalho Chehab (version 2) + * Mauro Carvalho Chehab (version 2) * * Fixes: 20000516 Claudio Matsuoka * - Added procfs support @@ -1072,7 +1072,7 @@ static void __exit videodev_exit(void) subsys_initcall(videodev_init); module_exit(videodev_exit) -MODULE_AUTHOR("Alan Cox, Mauro Carvalho Chehab "); +MODULE_AUTHOR("Alan Cox, Mauro Carvalho Chehab "); MODULE_DESCRIPTION("Device registrar for Video4Linux drivers v2"); MODULE_LICENSE("GPL"); MODULE_ALIAS_CHARDEV_MAJOR(VIDEO_MAJOR); -- cgit From baa057e29b5824b3727e2eb643e513ba5e35aea0 Mon Sep 17 00:00:00 2001 From: Mauro Carvalho Chehab Date: Thu, 5 Apr 2018 06:34:39 -0400 Subject: media: v4l2-dev: use pr_foo() for printing messages Instead of using printk() directly, use the pr_foo() macros. Signed-off-by: Mauro Carvalho Chehab Acked-by: Sakari Ailus Signed-off-by: Mauro Carvalho Chehab --- drivers/media/v4l2-core/v4l2-dev.c | 45 ++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 19 deletions(-) (limited to 'drivers/media/v4l2-core/v4l2-dev.c') diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c index 1d0b2208e8fb..530db8e482fb 100644 --- a/drivers/media/v4l2-core/v4l2-dev.c +++ b/drivers/media/v4l2-core/v4l2-dev.c @@ -16,6 +16,8 @@ * - Added procfs support */ +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + #include #include #include @@ -34,6 +36,12 @@ #define VIDEO_NUM_DEVICES 256 #define VIDEO_NAME "video4linux" +#define dprintk(fmt, arg...) do { \ + printk(KERN_DEBUG pr_fmt("%s: " fmt), \ + __func__, ##arg); \ +} while (0) + + /* * sysfs stuff */ @@ -309,7 +317,7 @@ static ssize_t v4l2_read(struct file *filp, char __user *buf, ret = vdev->fops->read(filp, buf, sz, off); if ((vdev->dev_debug & V4L2_DEV_DEBUG_FOP) && (vdev->dev_debug & V4L2_DEV_DEBUG_STREAMING)) - printk(KERN_DEBUG "%s: read: %zd (%d)\n", + dprintk("%s: read: %zd (%d)\n", video_device_node_name(vdev), sz, ret); return ret; } @@ -326,7 +334,7 @@ static ssize_t v4l2_write(struct file *filp, const char __user *buf, ret = vdev->fops->write(filp, buf, sz, off); if ((vdev->dev_debug & V4L2_DEV_DEBUG_FOP) && (vdev->dev_debug & V4L2_DEV_DEBUG_STREAMING)) - printk(KERN_DEBUG "%s: write: %zd (%d)\n", + dprintk("%s: write: %zd (%d)\n", video_device_node_name(vdev), sz, ret); return ret; } @@ -341,7 +349,7 @@ static __poll_t v4l2_poll(struct file *filp, struct poll_table_struct *poll) if (video_is_registered(vdev)) res = vdev->fops->poll(filp, poll); if (vdev->dev_debug & V4L2_DEV_DEBUG_POLL) - printk(KERN_DEBUG "%s: poll: %08x\n", + dprintk("%s: poll: %08x\n", video_device_node_name(vdev), res); return res; } @@ -382,7 +390,7 @@ static unsigned long v4l2_get_unmapped_area(struct file *filp, return -ENODEV; ret = vdev->fops->get_unmapped_area(filp, addr, len, pgoff, flags); if (vdev->dev_debug & V4L2_DEV_DEBUG_FOP) - printk(KERN_DEBUG "%s: get_unmapped_area (%d)\n", + dprintk("%s: get_unmapped_area (%d)\n", video_device_node_name(vdev), ret); return ret; } @@ -398,7 +406,7 @@ static int v4l2_mmap(struct file *filp, struct vm_area_struct *vm) if (video_is_registered(vdev)) ret = vdev->fops->mmap(filp, vm); if (vdev->dev_debug & V4L2_DEV_DEBUG_FOP) - printk(KERN_DEBUG "%s: mmap (%d)\n", + dprintk("%s: mmap (%d)\n", video_device_node_name(vdev), ret); return ret; } @@ -428,7 +436,7 @@ static int v4l2_open(struct inode *inode, struct file *filp) } if (vdev->dev_debug & V4L2_DEV_DEBUG_FOP) - printk(KERN_DEBUG "%s: open (%d)\n", + dprintk("%s: open (%d)\n", video_device_node_name(vdev), ret); /* decrease the refcount in case of an error */ if (ret) @@ -445,7 +453,7 @@ static int v4l2_release(struct inode *inode, struct file *filp) if (vdev->fops->release) ret = vdev->fops->release(filp); if (vdev->dev_debug & V4L2_DEV_DEBUG_FOP) - printk(KERN_DEBUG "%s: release\n", + dprintk("%s: release\n", video_device_node_name(vdev)); /* decrease the refcount unconditionally since the release() @@ -786,8 +794,7 @@ static int video_register_media_controller(struct video_device *vdev, int type) ret = media_device_register_entity(vdev->v4l2_dev->mdev, &vdev->entity); if (ret < 0) { - printk(KERN_WARNING - "%s: media_device_register_entity failed\n", + pr_warn("%s: media_device_register_entity failed\n", __func__); return ret; } @@ -869,7 +876,7 @@ int __video_register_device(struct video_device *vdev, name_base = "v4l-touch"; break; default: - printk(KERN_ERR "%s called with unknown type: %d\n", + pr_err("%s called with unknown type: %d\n", __func__, type); return -EINVAL; } @@ -918,7 +925,7 @@ int __video_register_device(struct video_device *vdev, if (nr == minor_cnt) nr = devnode_find(vdev, 0, minor_cnt); if (nr == minor_cnt) { - printk(KERN_ERR "could not get a free device node number\n"); + pr_err("could not get a free device node number\n"); mutex_unlock(&videodev_lock); return -ENFILE; } @@ -933,7 +940,7 @@ int __video_register_device(struct video_device *vdev, break; if (i == VIDEO_NUM_DEVICES) { mutex_unlock(&videodev_lock); - printk(KERN_ERR "could not get a free minor\n"); + pr_err("could not get a free minor\n"); return -ENFILE; } #endif @@ -943,7 +950,7 @@ int __video_register_device(struct video_device *vdev, /* Should not happen since we thought this minor was free */ if (WARN_ON(video_device[vdev->minor])) { mutex_unlock(&videodev_lock); - printk(KERN_ERR "video_device not empty!\n"); + pr_err("video_device not empty!\n"); return -ENFILE; } devnode_set(vdev); @@ -964,7 +971,7 @@ int __video_register_device(struct video_device *vdev, vdev->cdev->owner = owner; ret = cdev_add(vdev->cdev, MKDEV(VIDEO_MAJOR, vdev->minor), 1); if (ret < 0) { - printk(KERN_ERR "%s: cdev_add failed\n", __func__); + pr_err("%s: cdev_add failed\n", __func__); kfree(vdev->cdev); vdev->cdev = NULL; goto cleanup; @@ -977,7 +984,7 @@ int __video_register_device(struct video_device *vdev, dev_set_name(&vdev->dev, "%s%d", name_base, vdev->num); ret = device_register(&vdev->dev); if (ret < 0) { - printk(KERN_ERR "%s: device_register failed\n", __func__); + pr_err("%s: device_register failed\n", __func__); goto cleanup; } /* Register the release callback that will be called when the last @@ -985,7 +992,7 @@ int __video_register_device(struct video_device *vdev, vdev->dev.release = v4l2_device_release; if (nr != -1 && nr != vdev->num && warn_if_nr_in_use) - printk(KERN_WARNING "%s: requested %s%d, got %s\n", __func__, + pr_warn("%s: requested %s%d, got %s\n", __func__, name_base, nr, video_device_node_name(vdev)); /* Increase v4l2_device refcount */ @@ -1043,10 +1050,10 @@ static int __init videodev_init(void) dev_t dev = MKDEV(VIDEO_MAJOR, 0); int ret; - printk(KERN_INFO "Linux video capture interface: v2.00\n"); + pr_info("Linux video capture interface: v2.00\n"); ret = register_chrdev_region(dev, VIDEO_NUM_DEVICES, VIDEO_NAME); if (ret < 0) { - printk(KERN_WARNING "videodev: unable to get major %d\n", + pr_warn("videodev: unable to get major %d\n", VIDEO_MAJOR); return ret; } @@ -1054,7 +1061,7 @@ static int __init videodev_init(void) ret = class_register(&video_class); if (ret < 0) { unregister_chrdev_region(dev, VIDEO_NUM_DEVICES); - printk(KERN_WARNING "video_dev: class_register failed\n"); + pr_warn("video_dev: class_register failed\n"); return -EIO; } -- cgit From ee7582431f49b6fbdd6f9307cf20ddddf42ceeaa Mon Sep 17 00:00:00 2001 From: Simon Que Date: Mon, 9 Apr 2018 15:47:38 -0400 Subject: media: v4l2-core: Rename array 'video_driver' to 'video_drivers' Improves code clarity in two ways: 1. The plural name makes it more clear that it is an array. 2. The name of the array is now no longer identical to the struct type name, so it is easier to find in the code. Signed-off-by: Simon Que Acked-by: Laurent Pinchart Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab --- drivers/media/v4l2-core/v4l2-dev.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'drivers/media/v4l2-core/v4l2-dev.c') diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c index 530db8e482fb..b3bc839ee6ad 100644 --- a/drivers/media/v4l2-core/v4l2-dev.c +++ b/drivers/media/v4l2-core/v4l2-dev.c @@ -99,7 +99,7 @@ ATTRIBUTE_GROUPS(video_device); /* * Active devices */ -static struct video_device *video_device[VIDEO_NUM_DEVICES]; +static struct video_device *video_devices[VIDEO_NUM_DEVICES]; static DEFINE_MUTEX(videodev_lock); static DECLARE_BITMAP(devnode_nums[VFL_TYPE_MAX], VIDEO_NUM_DEVICES); @@ -181,14 +181,14 @@ static void v4l2_device_release(struct device *cd) struct v4l2_device *v4l2_dev = vdev->v4l2_dev; mutex_lock(&videodev_lock); - if (WARN_ON(video_device[vdev->minor] != vdev)) { + if (WARN_ON(video_devices[vdev->minor] != vdev)) { /* should not happen */ mutex_unlock(&videodev_lock); return; } /* Free up this device for reuse */ - video_device[vdev->minor] = NULL; + video_devices[vdev->minor] = NULL; /* Delete the cdev on this minor as well */ cdev_del(vdev->cdev); @@ -237,7 +237,7 @@ static struct class video_class = { struct video_device *video_devdata(struct file *file) { - return video_device[iminor(file_inode(file))]; + return video_devices[iminor(file_inode(file))]; } EXPORT_SYMBOL(video_devdata); @@ -501,9 +501,9 @@ static int get_index(struct video_device *vdev) bitmap_zero(used, VIDEO_NUM_DEVICES); for (i = 0; i < VIDEO_NUM_DEVICES; i++) { - if (video_device[i] != NULL && - video_device[i]->v4l2_dev == vdev->v4l2_dev) { - set_bit(video_device[i]->index, used); + if (video_devices[i] != NULL && + video_devices[i]->v4l2_dev == vdev->v4l2_dev) { + set_bit(video_devices[i]->index, used); } } @@ -936,7 +936,7 @@ int __video_register_device(struct video_device *vdev, /* The device node number and minor numbers are independent, so we just find the first free minor number. */ for (i = 0; i < VIDEO_NUM_DEVICES; i++) - if (video_device[i] == NULL) + if (video_devices[i] == NULL) break; if (i == VIDEO_NUM_DEVICES) { mutex_unlock(&videodev_lock); @@ -948,14 +948,14 @@ int __video_register_device(struct video_device *vdev, vdev->num = nr; /* Should not happen since we thought this minor was free */ - if (WARN_ON(video_device[vdev->minor])) { + if (WARN_ON(video_devices[vdev->minor])) { mutex_unlock(&videodev_lock); pr_err("video_device not empty!\n"); return -ENFILE; } devnode_set(vdev); vdev->index = get_index(vdev); - video_device[vdev->minor] = vdev; + video_devices[vdev->minor] = vdev; mutex_unlock(&videodev_lock); if (vdev->ioctl_ops) @@ -1010,7 +1010,7 @@ cleanup: mutex_lock(&videodev_lock); if (vdev->cdev) cdev_del(vdev->cdev); - video_device[vdev->minor] = NULL; + video_devices[vdev->minor] = NULL; devnode_clear(vdev); mutex_unlock(&videodev_lock); /* Mark this video device as never having been registered. */ -- cgit From 73a110623e7b7592defea69f028cccae495d69a4 Mon Sep 17 00:00:00 2001 From: Hans Verkuil Date: Fri, 11 May 2018 05:32:24 -0400 Subject: media: v4l2-core: push taking ioctl mutex down to ioctl handler The ioctl serialization mutex (vdev->lock or q->lock for vb2 queues) was taken at the highest level in v4l2-dev.c. This prevents more fine-grained locking since at that level we cannot examine the ioctl arguments, we can only do that after video_usercopy is called. So push the locking down to __video_do_ioctl() and subdev_do_ioctl_lock(). This also allows us to make a few functions in v4l2-ioctl.c static and video_usercopy() is no longer exported. The locking scheme is not changed by this patch, just pushed down. Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab --- drivers/media/v4l2-core/v4l2-dev.c | 6 ------ drivers/media/v4l2-core/v4l2-ioctl.c | 20 +++++++++++++++++--- drivers/media/v4l2-core/v4l2-subdev.c | 17 ++++++++++++++++- include/media/v4l2-dev.h | 9 --------- include/media/v4l2-ioctl.h | 12 ------------ 5 files changed, 33 insertions(+), 31 deletions(-) (limited to 'drivers/media/v4l2-core/v4l2-dev.c') diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c index c4f4357e9ca4..4ffd7d60a901 100644 --- a/drivers/media/v4l2-core/v4l2-dev.c +++ b/drivers/media/v4l2-core/v4l2-dev.c @@ -360,14 +360,8 @@ static long v4l2_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) int ret = -ENODEV; if (vdev->fops->unlocked_ioctl) { - struct mutex *lock = v4l2_ioctl_get_lock(vdev, cmd); - - if (lock && mutex_lock_interruptible(lock)) - return -ERESTARTSYS; if (video_is_registered(vdev)) ret = vdev->fops->unlocked_ioctl(filp, cmd, arg); - if (lock) - mutex_unlock(lock); } else ret = -ENOTTY; diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c index c23fbfe90a9e..965fd301f617 100644 --- a/drivers/media/v4l2-core/v4l2-ioctl.c +++ b/drivers/media/v4l2-core/v4l2-ioctl.c @@ -2655,14 +2655,15 @@ static struct v4l2_ioctl_info v4l2_ioctls[] = { }; #define V4L2_IOCTLS ARRAY_SIZE(v4l2_ioctls) -bool v4l2_is_known_ioctl(unsigned int cmd) +static bool v4l2_is_known_ioctl(unsigned int cmd) { if (_IOC_NR(cmd) >= V4L2_IOCTLS) return false; return v4l2_ioctls[_IOC_NR(cmd)].ioctl == cmd; } -struct mutex *v4l2_ioctl_get_lock(struct video_device *vdev, unsigned cmd) +static struct mutex *v4l2_ioctl_get_lock(struct video_device *vdev, + unsigned int cmd) { if (_IOC_NR(cmd) >= V4L2_IOCTLS) return vdev->lock; @@ -2713,6 +2714,7 @@ static long __video_do_ioctl(struct file *file, unsigned int cmd, void *arg) { struct video_device *vfd = video_devdata(file); + struct mutex *lock; /* ioctl serialization mutex */ const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops; bool write_only = false; struct v4l2_ioctl_info default_info; @@ -2731,6 +2733,16 @@ static long __video_do_ioctl(struct file *file, if (test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags)) vfh = file->private_data; + lock = v4l2_ioctl_get_lock(vfd, cmd); + + if (lock && mutex_lock_interruptible(lock)) + return -ERESTARTSYS; + + if (!video_is_registered(vfd)) { + ret = -ENODEV; + goto unlock; + } + if (v4l2_is_known_ioctl(cmd)) { info = &v4l2_ioctls[_IOC_NR(cmd)]; @@ -2780,6 +2792,9 @@ done: } } +unlock: + if (lock) + mutex_unlock(lock); return ret; } @@ -2969,7 +2984,6 @@ out: kvfree(mbuf); return err; } -EXPORT_SYMBOL(video_usercopy); long video_ioctl2(struct file *file, unsigned int cmd, unsigned long arg) diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c index f9eed938d348..6a7f7f75dfd7 100644 --- a/drivers/media/v4l2-core/v4l2-subdev.c +++ b/drivers/media/v4l2-core/v4l2-subdev.c @@ -502,10 +502,25 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg) return 0; } +static long subdev_do_ioctl_lock(struct file *file, unsigned int cmd, void *arg) +{ + struct video_device *vdev = video_devdata(file); + struct mutex *lock = vdev->lock; + long ret = -ENODEV; + + if (lock && mutex_lock_interruptible(lock)) + return -ERESTARTSYS; + if (video_is_registered(vdev)) + ret = subdev_do_ioctl(file, cmd, arg); + if (lock) + mutex_unlock(lock); + return ret; +} + static long subdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { - return video_usercopy(file, cmd, arg, subdev_do_ioctl); + return video_usercopy(file, cmd, arg, subdev_do_ioctl_lock); } #ifdef CONFIG_COMPAT diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h index 30423aefe7c5..456ac13eca1d 100644 --- a/include/media/v4l2-dev.h +++ b/include/media/v4l2-dev.h @@ -435,15 +435,6 @@ void video_device_release(struct video_device *vdev); */ void video_device_release_empty(struct video_device *vdev); -/** - * v4l2_is_known_ioctl - Checks if a given cmd is a known V4L ioctl - * - * @cmd: ioctl command - * - * returns true if cmd is a known V4L2 ioctl - */ -bool v4l2_is_known_ioctl(unsigned int cmd); - /** * v4l2_disable_ioctl- mark that a given command isn't implemented. * shouldn't use core locking diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h index a7b3f7c75d62..a8dbf5b54b5c 100644 --- a/include/media/v4l2-ioctl.h +++ b/include/media/v4l2-ioctl.h @@ -658,18 +658,6 @@ void v4l_printk_ioctl(const char *prefix, unsigned int cmd); struct video_device; - -/** - * v4l2_ioctl_get_lock - get the mutex (if any) that it is need to lock for - * a given command. - * - * @vdev: Pointer to struct &video_device. - * @cmd: Ioctl name. - * - * .. note:: Internal use only. Should not be used outside V4L2 core. - */ -struct mutex *v4l2_ioctl_get_lock(struct video_device *vdev, unsigned int cmd); - /* names for fancy debug output */ extern const char *v4l2_field_names[]; extern const char *v4l2_type_names[]; -- cgit