[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>
diff --git a/drivers/media/video/v4l2-ioctl.c b/drivers/media/video/v4l2-ioctl.c
index 9ded54b..273c6d7 100644
--- a/drivers/media/video/v4l2-ioctl.c
+++ b/drivers/media/video/v4l2-ioctl.c
@@ -1999,6 +1999,7 @@
 	void *fh = file->private_data;
 	struct v4l2_fh *vfh = NULL;
 	int use_fh_prio = 0;
+	int debug = vfd->debug;
 	long ret = -ENOTTY;
 
 	if (ops == NULL) {
@@ -2032,7 +2033,7 @@
 	}
 
 	write_only = _IOC_DIR(cmd) == _IOC_WRITE;
-	if (write_only && vfd->debug > V4L2_DEBUG_IOCTL) {
+	if (write_only && debug > V4L2_DEBUG_IOCTL) {
 		v4l_print_ioctl(vfd->name, cmd);
 		pr_cont(": ");
 		info->debug(arg, write_only);
@@ -2054,8 +2055,8 @@
 	}
 
 done:
-	if (vfd->debug) {
-		if (write_only && vfd->debug > V4L2_DEBUG_IOCTL) {
+	if (debug) {
+		if (write_only && debug > V4L2_DEBUG_IOCTL) {
 			if (ret < 0)
 				printk(KERN_DEBUG "%s: error %ld\n",
 					video_device_node_name(vfd), ret);
@@ -2064,7 +2065,7 @@
 		v4l_print_ioctl(vfd->name, cmd);
 		if (ret < 0)
 			pr_cont(": error %ld\n", ret);
-		else if (vfd->debug == V4L2_DEBUG_IOCTL)
+		else if (debug == V4L2_DEBUG_IOCTL)
 			pr_cont("\n");
 		else if (_IOC_DIR(cmd) == _IOC_NONE)
 			info->debug(arg, write_only);