diff options
author | Hans Verkuil <hans.verkuil@cisco.com> | 2012-06-22 05:37:38 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2012-07-06 16:25:31 -0400 |
commit | 80131fe06e0bdd7b429594493c1317ddede89a61 (patch) | |
tree | 645af85d4922b22b7c457bcfcf1005b22e1439d6 | |
parent | f18d8e07b28e2950679edaa4edaa7ce410dd57fc (diff) |
[media] v4l2-dev.c: add debug sysfs entry
Since this could theoretically change the debug value while in the middle
of v4l2-ioctl.c, we make a copy of vfd->debug to ensure consistent debug
behavior.
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
-rw-r--r-- | drivers/media/video/v4l2-dev.c | 24 | ||||
-rw-r--r-- | drivers/media/video/v4l2-ioctl.c | 9 |
2 files changed, 29 insertions, 4 deletions
diff --git a/drivers/media/video/v4l2-dev.c b/drivers/media/video/v4l2-dev.c index 83dbb2ddff10..c2122e53f051 100644 --- a/drivers/media/video/v4l2-dev.c +++ b/drivers/media/video/v4l2-dev.c | |||
@@ -46,6 +46,29 @@ static ssize_t show_index(struct device *cd, | |||
46 | return sprintf(buf, "%i\n", vdev->index); | 46 | return sprintf(buf, "%i\n", vdev->index); |
47 | } | 47 | } |
48 | 48 | ||
49 | static ssize_t show_debug(struct device *cd, | ||
50 | struct device_attribute *attr, char *buf) | ||
51 | { | ||
52 | struct video_device *vdev = to_video_device(cd); | ||
53 | |||
54 | return sprintf(buf, "%i\n", vdev->debug); | ||
55 | } | ||
56 | |||
57 | static ssize_t set_debug(struct device *cd, struct device_attribute *attr, | ||
58 | const char *buf, size_t len) | ||
59 | { | ||
60 | struct video_device *vdev = to_video_device(cd); | ||
61 | int res = 0; | ||
62 | u16 value; | ||
63 | |||
64 | res = kstrtou16(buf, 0, &value); | ||
65 | if (res) | ||
66 | return res; | ||
67 | |||
68 | vdev->debug = value; | ||
69 | return len; | ||
70 | } | ||
71 | |||
49 | static ssize_t show_name(struct device *cd, | 72 | static ssize_t show_name(struct device *cd, |
50 | struct device_attribute *attr, char *buf) | 73 | struct device_attribute *attr, char *buf) |
51 | { | 74 | { |
@@ -56,6 +79,7 @@ static ssize_t show_name(struct device *cd, | |||
56 | 79 | ||
57 | static struct device_attribute video_device_attrs[] = { | 80 | static struct device_attribute video_device_attrs[] = { |
58 | __ATTR(name, S_IRUGO, show_name, NULL), | 81 | __ATTR(name, S_IRUGO, show_name, NULL), |
82 | __ATTR(debug, 0644, show_debug, set_debug), | ||
59 | __ATTR(index, S_IRUGO, show_index, NULL), | 83 | __ATTR(index, S_IRUGO, show_index, NULL), |
60 | __ATTR_NULL | 84 | __ATTR_NULL |
61 | }; | 85 | }; |
diff --git a/drivers/media/video/v4l2-ioctl.c b/drivers/media/video/v4l2-ioctl.c index 9ded54b16e88..273c6d7bef65 100644 --- a/drivers/media/video/v4l2-ioctl.c +++ b/drivers/media/video/v4l2-ioctl.c | |||
@@ -1999,6 +1999,7 @@ static long __video_do_ioctl(struct file *file, | |||
1999 | void *fh = file->private_data; | 1999 | void *fh = file->private_data; |
2000 | struct v4l2_fh *vfh = NULL; | 2000 | struct v4l2_fh *vfh = NULL; |
2001 | int use_fh_prio = 0; | 2001 | int use_fh_prio = 0; |
2002 | int debug = vfd->debug; | ||
2002 | long ret = -ENOTTY; | 2003 | long ret = -ENOTTY; |
2003 | 2004 | ||
2004 | if (ops == NULL) { | 2005 | if (ops == NULL) { |
@@ -2032,7 +2033,7 @@ static long __video_do_ioctl(struct file *file, | |||
2032 | } | 2033 | } |
2033 | 2034 | ||
2034 | write_only = _IOC_DIR(cmd) == _IOC_WRITE; | 2035 | write_only = _IOC_DIR(cmd) == _IOC_WRITE; |
2035 | if (write_only && vfd->debug > V4L2_DEBUG_IOCTL) { | 2036 | if (write_only && debug > V4L2_DEBUG_IOCTL) { |
2036 | v4l_print_ioctl(vfd->name, cmd); | 2037 | v4l_print_ioctl(vfd->name, cmd); |
2037 | pr_cont(": "); | 2038 | pr_cont(": "); |
2038 | info->debug(arg, write_only); | 2039 | info->debug(arg, write_only); |
@@ -2054,8 +2055,8 @@ static long __video_do_ioctl(struct file *file, | |||
2054 | } | 2055 | } |
2055 | 2056 | ||
2056 | done: | 2057 | done: |
2057 | if (vfd->debug) { | 2058 | if (debug) { |
2058 | if (write_only && vfd->debug > V4L2_DEBUG_IOCTL) { | 2059 | if (write_only && debug > V4L2_DEBUG_IOCTL) { |
2059 | if (ret < 0) | 2060 | if (ret < 0) |
2060 | printk(KERN_DEBUG "%s: error %ld\n", | 2061 | printk(KERN_DEBUG "%s: error %ld\n", |
2061 | video_device_node_name(vfd), ret); | 2062 | video_device_node_name(vfd), ret); |
@@ -2064,7 +2065,7 @@ done: | |||
2064 | v4l_print_ioctl(vfd->name, cmd); | 2065 | v4l_print_ioctl(vfd->name, cmd); |
2065 | if (ret < 0) | 2066 | if (ret < 0) |
2066 | pr_cont(": error %ld\n", ret); | 2067 | pr_cont(": error %ld\n", ret); |
2067 | else if (vfd->debug == V4L2_DEBUG_IOCTL) | 2068 | else if (debug == V4L2_DEBUG_IOCTL) |
2068 | pr_cont("\n"); | 2069 | pr_cont("\n"); |
2069 | else if (_IOC_DIR(cmd) == _IOC_NONE) | 2070 | else if (_IOC_DIR(cmd) == _IOC_NONE) |
2070 | info->debug(arg, write_only); | 2071 | info->debug(arg, write_only); |