Skip to contentSkip to conversation

media: Remove vidioc_g/s_ctrl and vidioc_queryctrl callbacks

PATCH Superseded Ricardo Ribalda 2 participants 14 messages Dec 9, 2024

Subsystems (6)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover media: Remove vidioc_g/s_ctrl and vidioc_queryctrl callbacks

Most of the drivers use the control framework or can use the superset version of these callbacks: vidioc_g/s_ext_ctrl and vidioc_query_ext_ctrl.

---
Ricardo Ribalda (10):
media: ioctl: Simulate v4l2_queryctrl with v4l2_query_ext_ctrl
media: pvrusb2: Convert queryctrl to query_ext_ctrl
media: pvrusb2: Remove g/s_ctrl callbacks
media: uvcvideo: Remove vidioc_queryctrl
media: atomisp: Replace queryctrl with query_ext_ctrl
media: atomisp: Remove vidioc_g/s callback
media: v4l2: Remove vidioc_queryctrl callback
media: v4l2: Remove vidioc_g_ctrl callback
media: cx231xx: Replace s_ctrl with s_ext_ctrls
media: v4l2: Remove vidioc_s_ctrl callback

 drivers/media/usb/cx231xx/cx231xx-417.c           | 21 ++++++++----
 drivers/media/usb/pvrusb2/pvrusb2-v4l2.c          | 40 +++++------------------
 drivers/media/usb/uvc/uvc_v4l2.c                  | 10 ------
 drivers/media/v4l2-core/v4l2-dev.c                |  6 ++--
 drivers/media/v4l2-core/v4l2-ioctl.c              | 28 ++++++++++++----
 drivers/staging/media/atomisp/pci/atomisp_ioctl.c | 36 ++++++++++----------
 include/media/v4l2-ioctl.h                        | 12 -------
 7 files changed, 65 insertions(+), 88 deletions(-)

---
base-commit: 6c10d1adae82e1c8da16e7ebd2320e69f20b9d6f
change-id: 20241209-queryctrl-5c3632b7c857

Best regards,

Signature · 1 line
Ricardo Ribalda <[email protected]>
#1 lore raw

PATCH 1/10 media: ioctl: Simulate v4l2_queryctrl with v4l2_query_ext_ctrl

v4l2_queryctrl is a subset of v4l2_query_ext_ctrl. If the driver does not implement v4l2_queryctrl we can implement it with v4l2_query_ext_ctrl.

---
 drivers/media/v4l2-core/v4l2-dev.c   |  3 ++-
 drivers/media/v4l2-core/v4l2-ioctl.c | 22 +++++++++++++++++++++-
 2 files changed, 23 insertions(+), 2 deletions(-)
drivers/media/v4l2-core/v4l2-dev.c +2 -1
index 5bcaeeba4d09..252308a67fa8 100644
@@ -572,7 +572,8 @@ static void determine_valid_ioctls(struct video_device *vdev)
 	   and that can't be tested here. If the bit for these control ioctls
 	   is set, then the ioctl is valid. But if it is 0, then it can still
 	   be valid if the filehandle passed the control handler. */
-	if (vdev->ctrl_handler || ops->vidioc_queryctrl)
+	if (vdev->ctrl_handler || ops->vidioc_queryctrl ||
+	    ops->vidioc_query_ext_ctrl)
 		__set_bit(_IOC_NR(VIDIOC_QUERYCTRL), valid_ioctls);
 	if (vdev->ctrl_handler || ops->vidioc_query_ext_ctrl)
 		__set_bit(_IOC_NR(VIDIOC_QUERY_EXT_CTRL), valid_ioctls);
drivers/media/v4l2-core/v4l2-ioctl.c +21 -1
index 0304daa8471d..a5562f2f1fc9 100644
@@ -2284,9 +2284,11 @@ static int v4l_queryctrl(const struct v4l2_ioctl_ops *ops,
 				struct file *file, void *fh, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
+	struct v4l2_query_ext_ctrl qec;
 	struct v4l2_queryctrl *p = arg;
 	struct v4l2_fh *vfh =
 		test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL;
+	int ret;
 
 	if (vfh && vfh->ctrl_handler)
 		return v4l2_queryctrl(vfh->ctrl_handler, p);
@@ -2294,7 +2296,25 @@ static int v4l_queryctrl(const struct v4l2_ioctl_ops *ops,
 		return v4l2_queryctrl(vfd->ctrl_handler, p);
 	if (ops->vidioc_queryctrl)
 		return ops->vidioc_queryctrl(file, fh, p);
-	return -ENOTTY;
+	if (!ops->vidioc_query_ext_ctrl)
+		return -ENOTTY;
+
+	/* Simulate query_ext_ctr using query_ctrl. */
+	qec.id = p->id;
+	ret = ops->vidioc_query_ext_ctrl(file, fh, &qec);
+	if (ret)
+		return ret;
+
+	p->id = qec.id;
+	p->type = qec.type;
+	strscpy(p->name, qec.name, sizeof(p->name));
+	p->minimum = qec.minimum;
+	p->maximum = qec.maximum;
+	p->step = qec.step;
+	p->default_value = qec.default_value;
+	p->flags = qec.flags;
+
+	return 0;
 }
 
 static int v4l_query_ext_ctrl(const struct v4l2_ioctl_ops *ops,
Signature · 1 line
2.47.0.338.g60cca15819-goog
#2 lore raw

Re: [PATCH 01/10] media: ioctl: Simulate v4l2_queryctrl with v4l2_query_ext_ctrl

Quoted 53 lines · Ricardo Ribalda

v4l2_queryctrl is a subset of v4l2_query_ext_ctrl. If the driver does not implement v4l2_queryctrl we can implement it with v4l2_query_ext_ctrl.

---
 drivers/media/v4l2-core/v4l2-dev.c   |  3 ++-
 drivers/media/v4l2-core/v4l2-ioctl.c | 22 +++++++++++++++++++++-
 2 files changed, 23 insertions(+), 2 deletions(-)
drivers/media/v4l2-core/v4l2-dev.c +2 -1
index 5bcaeeba4d09..252308a67fa8 100644
@@ -572,7 +572,8 @@ static void determine_valid_ioctls(struct video_device *vdev)
 	   and that can't be tested here. If the bit for these control ioctls
 	   is set, then the ioctl is valid. But if it is 0, then it can still
 	   be valid if the filehandle passed the control handler. */
-	if (vdev->ctrl_handler || ops->vidioc_queryctrl)
+	if (vdev->ctrl_handler || ops->vidioc_queryctrl ||
+	    ops->vidioc_query_ext_ctrl)
 		__set_bit(_IOC_NR(VIDIOC_QUERYCTRL), valid_ioctls);
 	if (vdev->ctrl_handler || ops->vidioc_query_ext_ctrl)
 		__set_bit(_IOC_NR(VIDIOC_QUERY_EXT_CTRL), valid_ioctls);
drivers/media/v4l2-core/v4l2-ioctl.c +9 -1
index 0304daa8471d..a5562f2f1fc9 100644
@@ -2284,9 +2284,11 @@ static int v4l_queryctrl(const struct v4l2_ioctl_ops *ops,
 				struct file *file, void *fh, void *arg)
 {
 	struct video_device *vfd = video_devdata(file);
+	struct v4l2_query_ext_ctrl qec;
 	struct v4l2_queryctrl *p = arg;
 	struct v4l2_fh *vfh =
 		test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL;
+	int ret;
 
 	if (vfh && vfh->ctrl_handler)
 		return v4l2_queryctrl(vfh->ctrl_handler, p);
@@ -2294,7 +2296,25 @@ static int v4l_queryctrl(const struct v4l2_ioctl_ops *ops,
 		return v4l2_queryctrl(vfd->ctrl_handler, p);
 	if (ops->vidioc_queryctrl)
 		return ops->vidioc_queryctrl(file, fh, p);
-	return -ENOTTY;
+	if (!ops->vidioc_query_ext_ctrl)
+		return -ENOTTY;
+
+	/* Simulate query_ext_ctr using query_ctrl. */
+	qec.id = p->id;
+	ret = ops->vidioc_query_ext_ctrl(file, fh, &qec);
+	if (ret)

drivers/media/v4l2-core/v4l2-ioctl.c static int v4l_queryctrl(const struct v4l2_ioctl_ops *ops, · line 2315

Quoted 10 lines
drivers/media/v4l2-core/v4l2-ioctl.c +10 -0
+		return ret;
+
+	p->id = qec.id;
+	p->type = qec.type;
+	strscpy(p->name, qec.name, sizeof(p->name));
+	p->minimum = qec.minimum;
+	p->maximum = qec.maximum;
+	p->step = qec.step;
+	p->default_value = qec.default_value;
+	p->flags = qec.flags;

That's not quite correct. See v4l2_queryctrl() in v4l2-ctrls-api.c on how to do this: for types that VIDIOC_QUERYCTRL doesn't support, some of these fields must be set to 0.

In fact, once vidioc_queryctrl has been removed, then you can also remove v4l2_queryctrl() and just rely on this code. Unless I missed something.

Regards,

Hans

Quoted 6 lines
drivers/media/v4l2-core/v4l2-ioctl.c +2 -0
+
+	return 0;
 }
 
 static int v4l_query_ext_ctrl(const struct v4l2_ioctl_ops *ops,
#3 lore raw

Re: [PATCH 01/10] media: ioctl: Simulate v4l2_queryctrl with v4l2_query_ext_ctrl

Hi Hans

Quoted 70 lines · Hans Verkuil
Quoted 53 lines · Ricardo Ribalda

v4l2_queryctrl is a subset of v4l2_query_ext_ctrl. If the driver does not implement v4l2_queryctrl we can implement it with v4l2_query_ext_ctrl.

---
 drivers/media/v4l2-core/v4l2-dev.c   |  3 ++-
 drivers/media/v4l2-core/v4l2-ioctl.c | 22 +++++++++++++++++++++-
 2 files changed, 23 insertions(+), 2 deletions(-)
drivers/media/v4l2-core/v4l2-dev.c +2 -1
index 5bcaeeba4d09..252308a67fa8 100644
@@ -572,7 +572,8 @@ static void determine_valid_ioctls(struct video_device *vdev)
         and that can't be tested here. If the bit for these control ioctls
         is set, then the ioctl is valid. But if it is 0, then it can still
         be valid if the filehandle passed the control handler. */
-     if (vdev->ctrl_handler || ops->vidioc_queryctrl)
+     if (vdev->ctrl_handler || ops->vidioc_queryctrl ||
+         ops->vidioc_query_ext_ctrl)
              __set_bit(_IOC_NR(VIDIOC_QUERYCTRL), valid_ioctls);
      if (vdev->ctrl_handler || ops->vidioc_query_ext_ctrl)
              __set_bit(_IOC_NR(VIDIOC_QUERY_EXT_CTRL), valid_ioctls);
drivers/media/v4l2-core/v4l2-ioctl.c +9 -1
index 0304daa8471d..a5562f2f1fc9 100644
@@ -2284,9 +2284,11 @@ static int v4l_queryctrl(const struct v4l2_ioctl_ops *ops,
                              struct file *file, void *fh, void *arg)
 {
      struct video_device *vfd = video_devdata(file);
+     struct v4l2_query_ext_ctrl qec;
      struct v4l2_queryctrl *p = arg;
      struct v4l2_fh *vfh =
              test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL;
+     int ret;
 
      if (vfh && vfh->ctrl_handler)
              return v4l2_queryctrl(vfh->ctrl_handler, p);
@@ -2294,7 +2296,25 @@ static int v4l_queryctrl(const struct v4l2_ioctl_ops *ops,
              return v4l2_queryctrl(vfd->ctrl_handler, p);
      if (ops->vidioc_queryctrl)
              return ops->vidioc_queryctrl(file, fh, p);
-     return -ENOTTY;
+     if (!ops->vidioc_query_ext_ctrl)
+             return -ENOTTY;
+
+     /* Simulate query_ext_ctr using query_ctrl. */
+     qec.id = p->id;
+     ret = ops->vidioc_query_ext_ctrl(file, fh, &qec);
+     if (ret)

drivers/media/v4l2-core/v4l2-ioctl.c static int v4l_queryctrl(const struct v4l2_ioctl_ops *ops, · line 2315

Quoted 10 lines
drivers/media/v4l2-core/v4l2-ioctl.c +10 -0
+             return ret;
+
+     p->id = qec.id;
+     p->type = qec.type;
+     strscpy(p->name, qec.name, sizeof(p->name));
+     p->minimum = qec.minimum;
+     p->maximum = qec.maximum;
+     p->step = qec.step;
+     p->default_value = qec.default_value;
+     p->flags = qec.flags;

That's not quite correct. See v4l2_queryctrl() in v4l2-ctrls-api.c on how to do this: for types that VIDIOC_QUERYCTRL doesn't support, some of these fields must be set to 0.

Quoted 3 lines

In fact, once vidioc_queryctrl has been removed, then you can also remove v4l2_queryctrl() and just rely on this code. Unless I missed something.

Thanks for the mega-fast review :)

I do not think that we can easily remove v4l2_queryctrl(). It is still called by v4l2-subdev.c

We could do something to remove the code duplication... but it will probably make the code more difficult to follow.

I will send a new version with the fix that you proposed, as well as:

-- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -2290,10 +2290,6 @@ static int v4l_queryctrl(const struct v4l2_ioctl_ops *ops,

                test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL;
        int ret;

- if (vfh && vfh->ctrl_handler)
- return v4l2_queryctrl(vfh->ctrl_handler, p);
- if (vfd->ctrl_handler)

-               return v4l2_queryctrl(vfd->ctrl_handler, p);
        if (!ops->vidioc_query_ext_ctrl)
                return -ENOTTY;
Quoted 12 lines

Regards,

Hans

Quoted 6 lines
drivers/media/v4l2-core/v4l2-ioctl.c +2 -0
+
+     return 0;
 }
 
 static int v4l_query_ext_ctrl(const struct v4l2_ioctl_ops *ops,
Signature · 1 line
Ricardo Ribalda
#4 lore raw

Re: [PATCH 01/10] media: ioctl: Simulate v4l2_queryctrl with v4l2_query_ext_ctrl

Quoted 91 lines · Ricardo Ribalda

Hi Hans

Quoted 70 lines · Hans Verkuil
Quoted 53 lines · Ricardo Ribalda

v4l2_queryctrl is a subset of v4l2_query_ext_ctrl. If the driver does not implement v4l2_queryctrl we can implement it with v4l2_query_ext_ctrl.

---
 drivers/media/v4l2-core/v4l2-dev.c   |  3 ++-
 drivers/media/v4l2-core/v4l2-ioctl.c | 22 +++++++++++++++++++++-
 2 files changed, 23 insertions(+), 2 deletions(-)
drivers/media/v4l2-core/v4l2-dev.c +2 -1
index 5bcaeeba4d09..252308a67fa8 100644
@@ -572,7 +572,8 @@ static void determine_valid_ioctls(struct video_device *vdev)
         and that can't be tested here. If the bit for these control ioctls
         is set, then the ioctl is valid. But if it is 0, then it can still
         be valid if the filehandle passed the control handler. */
-     if (vdev->ctrl_handler || ops->vidioc_queryctrl)
+     if (vdev->ctrl_handler || ops->vidioc_queryctrl ||
+         ops->vidioc_query_ext_ctrl)
              __set_bit(_IOC_NR(VIDIOC_QUERYCTRL), valid_ioctls);
      if (vdev->ctrl_handler || ops->vidioc_query_ext_ctrl)
              __set_bit(_IOC_NR(VIDIOC_QUERY_EXT_CTRL), valid_ioctls);
drivers/media/v4l2-core/v4l2-ioctl.c +9 -1
index 0304daa8471d..a5562f2f1fc9 100644
@@ -2284,9 +2284,11 @@ static int v4l_queryctrl(const struct v4l2_ioctl_ops *ops,
                              struct file *file, void *fh, void *arg)
 {
      struct video_device *vfd = video_devdata(file);
+     struct v4l2_query_ext_ctrl qec;
      struct v4l2_queryctrl *p = arg;
      struct v4l2_fh *vfh =
              test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL;
+     int ret;
 
      if (vfh && vfh->ctrl_handler)
              return v4l2_queryctrl(vfh->ctrl_handler, p);
@@ -2294,7 +2296,25 @@ static int v4l_queryctrl(const struct v4l2_ioctl_ops *ops,
              return v4l2_queryctrl(vfd->ctrl_handler, p);
      if (ops->vidioc_queryctrl)
              return ops->vidioc_queryctrl(file, fh, p);
-     return -ENOTTY;
+     if (!ops->vidioc_query_ext_ctrl)
+             return -ENOTTY;
+
+     /* Simulate query_ext_ctr using query_ctrl. */
+     qec.id = p->id;
+     ret = ops->vidioc_query_ext_ctrl(file, fh, &qec);
+     if (ret)

drivers/media/v4l2-core/v4l2-ioctl.c static int v4l_queryctrl(const struct v4l2_ioctl_ops *ops, · line 2315

Quoted 10 lines
drivers/media/v4l2-core/v4l2-ioctl.c +10 -0
+             return ret;
+
+     p->id = qec.id;
+     p->type = qec.type;
+     strscpy(p->name, qec.name, sizeof(p->name));
+     p->minimum = qec.minimum;
+     p->maximum = qec.maximum;
+     p->step = qec.step;
+     p->default_value = qec.default_value;
+     p->flags = qec.flags;

That's not quite correct. See v4l2_queryctrl() in v4l2-ctrls-api.c on how to do this: for types that VIDIOC_QUERYCTRL doesn't support, some of these fields must be set to 0.

Quoted 3 lines

In fact, once vidioc_queryctrl has been removed, then you can also remove v4l2_queryctrl() and just rely on this code. Unless I missed something.

Thanks for the mega-fast review :)

I do not think that we can easily remove v4l2_queryctrl(). It is still called by v4l2-subdev.c

We could do something to remove the code duplication... but it will probably make the code more difficult to follow.

I will send a new version with the fix that you proposed, as well as:

-- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c

Review static int v4l_queryctrl(const struct · line 2295

Quoted 10 lines
(quoted diff) +0 -4
@@ -2290,10 +2290,6 @@ static int v4l_queryctrl(const struct
 v4l2_ioctl_ops *ops,
                test_bit(V4L2_FL_USES_V4L2_FH, &vfd->flags) ? fh : NULL;
        int ret;
 
-       if (vfh && vfh->ctrl_handler)
-               return v4l2_queryctrl(vfh->ctrl_handler, p);
-       if (vfd->ctrl_handler)
-               return v4l2_queryctrl(vfd->ctrl_handler, p);
        if (!ops->vidioc_query_ext_ctrl)
                return -ENOTTY;

Actually we cannot remove these four lines. I have a set ready with a helper....
https://gitlab.freedesktop.org/linux-media/users/ribalda/-/commits/queryctrl
Not sure if it is better with or without the helper.

Will send it tomorrow if I do not have more feedback.

Best rergards!

Quoted 17 lines
Quoted 13 lines

Regards,

Hans

Quoted 6 lines
drivers/media/v4l2-core/v4l2-ioctl.c +2 -0
+
+     return 0;
 }
 
 static int v4l_query_ext_ctrl(const struct v4l2_ioctl_ops *ops,

--
Ricardo Ribalda

Signature · 1 line
Ricardo Ribalda
#5 lore raw

PATCH 2/10 media: pvrusb2: Convert queryctrl to query_ext_ctrl

In reply to Ricardo Ribalda

The driver was missing support for query_ext_ctrl. Instead of adding a new callback for it, replace the current implementation of queryctrl and let the ioctl framework emulate the old function.

Most of the fields are identical, so the change is pretty simple.

---
 drivers/media/usb/pvrusb2/pvrusb2-v4l2.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/media/usb/pvrusb2/pvrusb2-v4l2.c +8 -5
index d608b793fa84..7c8be6a0cf7c 100644
@@ -497,8 +497,8 @@ static int pvr2_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
 	return pvr2_hdw_set_streaming(hdw, 0);
 }
 
-static int pvr2_queryctrl(struct file *file, void *priv,
-		struct v4l2_queryctrl *vc)
+static int pvr2_query_ext_ctrl(struct file *file, void *priv,
+			       struct v4l2_query_ext_ctrl *vc)
 {
 	struct pvr2_v4l2_fh *fh = file->private_data;
 	struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
@@ -521,13 +521,16 @@ static int pvr2_queryctrl(struct file *file, void *priv,
 	}
 
 	pvr2_trace(PVR2_TRACE_V4LIOCTL,
-			"QUERYCTRL id=0x%x mapping name=%s (%s)",
+			"QUERYEXTCTRL id=0x%x mapping name=%s (%s)",
 			vc->id, pvr2_ctrl_get_name(cptr),
 			pvr2_ctrl_get_desc(cptr));
 	strscpy(vc->name, pvr2_ctrl_get_desc(cptr), sizeof(vc->name));
 	vc->flags = pvr2_ctrl_get_v4lflags(cptr);
 	pvr2_ctrl_get_def(cptr, &val);
 	vc->default_value = val;
+	vc->nr_of_dims = 0;
+	vc->elems = 1;
+	vc->elem_size = 4;
 	switch (pvr2_ctrl_get_type(cptr)) {
 	case pvr2_ctl_enum:
 		vc->type = V4L2_CTRL_TYPE_MENU;
@@ -549,7 +552,7 @@ static int pvr2_queryctrl(struct file *file, void *priv,
 		break;
 	default:
 		pvr2_trace(PVR2_TRACE_V4LIOCTL,
-				"QUERYCTRL id=0x%x name=%s not mappable",
+				"QUERYEXTCTRL id=0x%x name=%s not mappable",
 				vc->id, pvr2_ctrl_get_name(cptr));
 		return -EINVAL;
 	}
@@ -812,7 +815,7 @@ static const struct v4l2_ioctl_ops pvr2_ioctl_ops = {
 	.vidioc_try_fmt_vid_cap		    = pvr2_try_fmt_vid_cap,
 	.vidioc_streamon		    = pvr2_streamon,
 	.vidioc_streamoff		    = pvr2_streamoff,
-	.vidioc_queryctrl		    = pvr2_queryctrl,
+	.vidioc_query_ext_ctrl		    = pvr2_query_ext_ctrl,
 	.vidioc_querymenu		    = pvr2_querymenu,
 	.vidioc_g_ctrl			    = pvr2_g_ctrl,
 	.vidioc_s_ctrl			    = pvr2_s_ctrl,
Signature · 1 line
2.47.0.338.g60cca15819-goog
#6 lore raw

PATCH 3/10 media: pvrusb2: Remove g/s_ctrl callbacks

In reply to Ricardo Ribalda

The ioctl helpers can emulate g/s_ctrl with g/s_ext_ctrl. Simplify the code.

---
 drivers/media/usb/pvrusb2/pvrusb2-v4l2.c | 27 ---------------------------
 1 file changed, 27 deletions(-)
drivers/media/usb/pvrusb2/pvrusb2-v4l2.c +0 -27
index 7c8be6a0cf7c..ad38e1240541 100644
@@ -574,31 +574,6 @@ static int pvr2_querymenu(struct file *file, void *priv, struct v4l2_querymenu *
 	return ret;
 }
 
-static int pvr2_g_ctrl(struct file *file, void *priv, struct v4l2_control *vc)
-{
-	struct pvr2_v4l2_fh *fh = file->private_data;
-	struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
-	int val = 0;
-	int ret;
-
-	ret = pvr2_ctrl_get_value(pvr2_hdw_get_ctrl_v4l(hdw, vc->id),
-			&val);
-	vc->value = val;
-	return ret;
-}
-
-static int pvr2_s_ctrl(struct file *file, void *priv, struct v4l2_control *vc)
-{
-	struct pvr2_v4l2_fh *fh = file->private_data;
-	struct pvr2_hdw *hdw = fh->channel.mc_head->hdw;
-	int ret;
-
-	ret = pvr2_ctrl_set_value(pvr2_hdw_get_ctrl_v4l(hdw, vc->id),
-			vc->value);
-	pvr2_hdw_commit_ctl(hdw);
-	return ret;
-}
-
 static int pvr2_g_ext_ctrls(struct file *file, void *priv,
 					struct v4l2_ext_controls *ctls)
 {
@@ -817,8 +792,6 @@ static const struct v4l2_ioctl_ops pvr2_ioctl_ops = {
 	.vidioc_streamoff		    = pvr2_streamoff,
 	.vidioc_query_ext_ctrl		    = pvr2_query_ext_ctrl,
 	.vidioc_querymenu		    = pvr2_querymenu,
-	.vidioc_g_ctrl			    = pvr2_g_ctrl,
-	.vidioc_s_ctrl			    = pvr2_s_ctrl,
 	.vidioc_g_ext_ctrls		    = pvr2_g_ext_ctrls,
 	.vidioc_s_ext_ctrls		    = pvr2_s_ext_ctrls,
 	.vidioc_try_ext_ctrls		    = pvr2_try_ext_ctrls,
Signature · 1 line
2.47.0.338.g60cca15819-goog
#7 lore raw

PATCH 4/10 media: uvcvideo: Remove vidioc_queryctrl

In reply to Ricardo Ribalda

It can be implemented by the v4l2 ioctl framework using vidioc_query_ext_ctrl.

---
 drivers/media/usb/uvc/uvc_v4l2.c | 10 ----------
 1 file changed, 10 deletions(-)
drivers/media/usb/uvc/uvc_v4l2.c +0 -10
index 97c5407f6603..39f0ddb6d01c 100644
@@ -1014,15 +1014,6 @@ static int uvc_ioctl_s_input(struct file *file, void *fh, unsigned int input)
 	return ret;
 }
 
-static int uvc_ioctl_queryctrl(struct file *file, void *fh,
-			       struct v4l2_queryctrl *qc)
-{
-	struct uvc_fh *handle = fh;
-	struct uvc_video_chain *chain = handle->chain;
-
-	return uvc_query_v4l2_ctrl(chain, qc);
-}
-
 static int uvc_ioctl_query_ext_ctrl(struct file *file, void *fh,
 				    struct v4l2_query_ext_ctrl *qec)
 {
@@ -1563,7 +1554,6 @@ const struct v4l2_ioctl_ops uvc_ioctl_ops = {
 	.vidioc_enum_input = uvc_ioctl_enum_input,
 	.vidioc_g_input = uvc_ioctl_g_input,
 	.vidioc_s_input = uvc_ioctl_s_input,
-	.vidioc_queryctrl = uvc_ioctl_queryctrl,
 	.vidioc_query_ext_ctrl = uvc_ioctl_query_ext_ctrl,
 	.vidioc_g_ext_ctrls = uvc_ioctl_g_ext_ctrls,
 	.vidioc_s_ext_ctrls = uvc_ioctl_s_ext_ctrls,
Signature · 1 line
2.47.0.338.g60cca15819-goog
#8 lore raw

PATCH 5/10 media: atomisp: Replace queryctrl with query_ext_ctrl

In reply to Ricardo Ribalda

The ioctl framework provides an emulator of queryctrl using query_ext_ctrl.
Replace our implementation of queryctrl to support both.

Now that we are at it:
- Add comment about missing functionality.
- Remove superfluous clear of reserved[0].
- Remove ret var.

---
 drivers/staging/media/atomisp/pci/atomisp_ioctl.c | 34 +++++++++++++----------
 1 file changed, 19 insertions(+), 15 deletions(-)
drivers/staging/media/atomisp/pci/atomisp_ioctl.c +19 -15
index 1a960a01854f..d24420d8bd57 100644
@@ -34,7 +34,7 @@ static const char *CARD = "ATOM ISP";	/* max size 31 */
  * FIXME: ISP should not know beforehand all CIDs supported by sensor.
  * Instead, it needs to propagate to sensor unknown CIDs.
  */
-static struct v4l2_queryctrl ci_v4l2_controls[] = {
+static struct v4l2_query_ext_ctrl ci_v4l2_controls[] = {
 	{
 		.id = V4L2_CID_AUTO_WHITE_BALANCE,
 		.type = V4L2_CTRL_TYPE_BOOLEAN,
@@ -1140,31 +1140,35 @@ static int atomisp_s_ctrl(struct file *file, void *fh,
 
 /*
  * To query the attributes of a control.
- * applications set the id field of a struct v4l2_queryctrl and call the
+ * applications set the id field of a struct v4l2_query_ext_ctrl and call the
  * this ioctl with a pointer to this structure. The driver fills
  * the rest of the structure.
  */
-static int atomisp_queryctl(struct file *file, void *fh,
-			    struct v4l2_queryctrl *qc)
+static int atomisp_query_ext_ctrl(struct file *file, void *fh,
+				  struct v4l2_query_ext_ctrl *qc)
 {
-	int i, ret = -EINVAL;
+	int i;
 
+	/* TODO: implement V4L2_CTRL_FLAG_NEXT_CTRL */
 	if (qc->id & V4L2_CTRL_FLAG_NEXT_CTRL)
-		return ret;
+		return -EINVAL;
 
 	for (i = 0; i < ctrls_num; i++) {
 		if (ci_v4l2_controls[i].id == qc->id) {
-			memcpy(qc, &ci_v4l2_controls[i],
-			       sizeof(struct v4l2_queryctrl));
-			qc->reserved[0] = 0;
-			ret = 0;
-			break;
+			memcpy(qc, &ci_v4l2_controls[i], sizeof(*qc));
+			qc->nr_of_dims = 0;
+			qc->elems = 1;
+			qc->elem_size = 4;
+			return 0;
 		}
 	}
-	if (ret != 0)
-		qc->flags = V4L2_CTRL_FLAG_DISABLED;
 
-	return ret;
+	/*
+	 * This is probably not needed, but this flag has been set for
+	 * many kernel versions. Leave to avoid breaking any apps
+	 */
+	qc->flags = V4L2_CTRL_FLAG_DISABLED;
+	return -EINVAL;
 }
 
 static int atomisp_camera_g_ext_ctrls(struct file *file, void *fh,
@@ -1561,7 +1565,7 @@ const struct v4l2_ioctl_ops atomisp_ioctl_ops = {
 	.vidioc_enum_input = atomisp_enum_input,
 	.vidioc_g_input = atomisp_g_input,
 	.vidioc_s_input = atomisp_s_input,
-	.vidioc_queryctrl = atomisp_queryctl,
+	.vidioc_query_ext_ctrl = atomisp_query_ext_ctrl,
 	.vidioc_s_ctrl = atomisp_s_ctrl,
 	.vidioc_g_ctrl = atomisp_g_ctrl,
 	.vidioc_s_ext_ctrls = atomisp_s_ext_ctrls,
Signature · 1 line
2.47.0.338.g60cca15819-goog
#9 lore raw

PATCH 6/10 media: atomisp: Remove vidioc_g/s callback

In reply to Ricardo Ribalda

The v4l2 ioctl framework can implement vidioc_g/s_ctrl with vidioc_g/s_ext_ctrl() and we provide those.

These are the last references of vidioc_s/g_ctrl in the codebase. We can attempt to remove them now.

---
 drivers/staging/media/atomisp/pci/atomisp_ioctl.c | 2 --
 1 file changed, 2 deletions(-)
drivers/staging/media/atomisp/pci/atomisp_ioctl.c +0 -2
index d24420d8bd57..394b6f06246c 100644
@@ -1566,8 +1566,6 @@ const struct v4l2_ioctl_ops atomisp_ioctl_ops = {
 	.vidioc_g_input = atomisp_g_input,
 	.vidioc_s_input = atomisp_s_input,
 	.vidioc_query_ext_ctrl = atomisp_query_ext_ctrl,
-	.vidioc_s_ctrl = atomisp_s_ctrl,
-	.vidioc_g_ctrl = atomisp_g_ctrl,
 	.vidioc_s_ext_ctrls = atomisp_s_ext_ctrls,
 	.vidioc_g_ext_ctrls = atomisp_g_ext_ctrls,
 	.vidioc_enum_framesizes   = atomisp_enum_framesizes,
Signature · 1 line
2.47.0.338.g60cca15819-goog
#10 lore raw

PATCH 7/10 media: v4l2: Remove vidioc_queryctrl callback

In reply to Ricardo Ribalda

All the drivers either use the control framework or provide a vidioc_query_ext_ctrl. We can remove this callback to reduce the temptation of new drivers to implement it.

---
 drivers/media/v4l2-core/v4l2-dev.c   | 3 +--
 drivers/media/v4l2-core/v4l2-ioctl.c | 2 --
 include/media/v4l2-ioctl.h           | 4 ----
 3 files changed, 1 insertion(+), 8 deletions(-)
drivers/media/v4l2-core/v4l2-dev.c +1 -2
index 252308a67fa8..5267a0686400 100644
@@ -572,8 +572,7 @@ static void determine_valid_ioctls(struct video_device *vdev)
 	   and that can't be tested here. If the bit for these control ioctls
 	   is set, then the ioctl is valid. But if it is 0, then it can still
 	   be valid if the filehandle passed the control handler. */
-	if (vdev->ctrl_handler || ops->vidioc_queryctrl ||
-	    ops->vidioc_query_ext_ctrl)
+	if (vdev->ctrl_handler || ops->vidioc_query_ext_ctrl)
 		__set_bit(_IOC_NR(VIDIOC_QUERYCTRL), valid_ioctls);
 	if (vdev->ctrl_handler || ops->vidioc_query_ext_ctrl)
 		__set_bit(_IOC_NR(VIDIOC_QUERY_EXT_CTRL), valid_ioctls);
drivers/media/v4l2-core/v4l2-ioctl.c +0 -2
index a5562f2f1fc9..30e32ce5278f 100644
@@ -2294,8 +2294,6 @@ static int v4l_queryctrl(const struct v4l2_ioctl_ops *ops,
 		return v4l2_queryctrl(vfh->ctrl_handler, p);
 	if (vfd->ctrl_handler)
 		return v4l2_queryctrl(vfd->ctrl_handler, p);
-	if (ops->vidioc_queryctrl)
-		return ops->vidioc_queryctrl(file, fh, p);
 	if (!ops->vidioc_query_ext_ctrl)
 		return -ENOTTY;
 
include/media/v4l2-ioctl.h +0 -4
index bdbb7e542321..013996c33a9e 100644
@@ -193,8 +193,6 @@ struct v4l2_fh;
  *	:ref:`VIDIOC_G_OUTPUT <vidioc_g_output>` ioctl
  * @vidioc_s_output: pointer to the function that implements
  *	:ref:`VIDIOC_S_OUTPUT <vidioc_g_output>` ioctl
- * @vidioc_queryctrl: pointer to the function that implements
- *	:ref:`VIDIOC_QUERYCTRL <vidioc_queryctrl>` ioctl
  * @vidioc_query_ext_ctrl: pointer to the function that implements
  *	:ref:`VIDIOC_QUERY_EXT_CTRL <vidioc_queryctrl>` ioctl
  * @vidioc_g_ctrl: pointer to the function that implements
@@ -461,8 +459,6 @@ struct v4l2_ioctl_ops {
 	int (*vidioc_s_output)(struct file *file, void *fh, unsigned int i);
 
 		/* Control handling */
-	int (*vidioc_queryctrl)(struct file *file, void *fh,
-				struct v4l2_queryctrl *a);
 	int (*vidioc_query_ext_ctrl)(struct file *file, void *fh,
 				     struct v4l2_query_ext_ctrl *a);
 	int (*vidioc_g_ctrl)(struct file *file, void *fh,
Signature · 1 line
2.47.0.338.g60cca15819-goog
#11 lore raw

PATCH 8/10 media: v4l2: Remove vidioc_g_ctrl callback

In reply to Ricardo Ribalda

All the drivers either use the control framework or provide a vidioc_g_ext_ctrls callback. We can remove this callback.

Thanks for your service!

---
 drivers/media/v4l2-core/v4l2-dev.c   | 2 +-
 drivers/media/v4l2-core/v4l2-ioctl.c | 2 --
 include/media/v4l2-ioctl.h           | 4 ----
 3 files changed, 1 insertion(+), 7 deletions(-)
drivers/media/v4l2-core/v4l2-dev.c +1 -1
index 5267a0686400..068ee67cd574 100644
@@ -576,7 +576,7 @@ static void determine_valid_ioctls(struct video_device *vdev)
 		__set_bit(_IOC_NR(VIDIOC_QUERYCTRL), valid_ioctls);
 	if (vdev->ctrl_handler || ops->vidioc_query_ext_ctrl)
 		__set_bit(_IOC_NR(VIDIOC_QUERY_EXT_CTRL), valid_ioctls);
-	if (vdev->ctrl_handler || ops->vidioc_g_ctrl || ops->vidioc_g_ext_ctrls)
+	if (vdev->ctrl_handler || ops->vidioc_g_ext_ctrls)
 		__set_bit(_IOC_NR(VIDIOC_G_CTRL), valid_ioctls);
 	if (vdev->ctrl_handler || ops->vidioc_s_ctrl || ops->vidioc_s_ext_ctrls)
 		__set_bit(_IOC_NR(VIDIOC_S_CTRL), valid_ioctls);
drivers/media/v4l2-core/v4l2-ioctl.c +0 -2
index 30e32ce5278f..4e65d50bef27 100644
@@ -2363,8 +2363,6 @@ static int v4l_g_ctrl(const struct v4l2_ioctl_ops *ops,
 		return v4l2_g_ctrl(vfh->ctrl_handler, p);
 	if (vfd->ctrl_handler)
 		return v4l2_g_ctrl(vfd->ctrl_handler, p);
-	if (ops->vidioc_g_ctrl)
-		return ops->vidioc_g_ctrl(file, fh, p);
 	if (ops->vidioc_g_ext_ctrls == NULL)
 		return -ENOTTY;
 
include/media/v4l2-ioctl.h +0 -4
index 013996c33a9e..4d69128023f8 100644
@@ -195,8 +195,6 @@ struct v4l2_fh;
  *	:ref:`VIDIOC_S_OUTPUT <vidioc_g_output>` ioctl
  * @vidioc_query_ext_ctrl: pointer to the function that implements
  *	:ref:`VIDIOC_QUERY_EXT_CTRL <vidioc_queryctrl>` ioctl
- * @vidioc_g_ctrl: pointer to the function that implements
- *	:ref:`VIDIOC_G_CTRL <vidioc_g_ctrl>` ioctl
  * @vidioc_s_ctrl: pointer to the function that implements
  *	:ref:`VIDIOC_S_CTRL <vidioc_g_ctrl>` ioctl
  * @vidioc_g_ext_ctrls: pointer to the function that implements
@@ -461,8 +459,6 @@ struct v4l2_ioctl_ops {
 		/* Control handling */
 	int (*vidioc_query_ext_ctrl)(struct file *file, void *fh,
 				     struct v4l2_query_ext_ctrl *a);
-	int (*vidioc_g_ctrl)(struct file *file, void *fh,
-			     struct v4l2_control *a);
 	int (*vidioc_s_ctrl)(struct file *file, void *fh,
 			     struct v4l2_control *a);
 	int (*vidioc_g_ext_ctrls)(struct file *file, void *fh,
Signature · 1 line
2.47.0.338.g60cca15819-goog
#12 lore raw

PATCH 9/10 media: cx231xx: Replace s_ctrl with s_ext_ctrls

In reply to Ricardo Ribalda

The v4l2 ioctl framework can provide support for s_ctrl. This the last driver implementing s_ctrl.

---
 drivers/media/usb/cx231xx/cx231xx-417.c | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)
drivers/media/usb/cx231xx/cx231xx-417.c +14 -7
index a4a9781328c5..3c1941709ebf 100644
@@ -1538,17 +1538,24 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id id)
 	return 0;
 }
 
-static int vidioc_s_ctrl(struct file *file, void *priv,
-				struct v4l2_control *ctl)
+static int cx231xx_s_ext_ctrls(struct file *file, void *priv,
+			       struct v4l2_ext_controls *ctls)
 {
 	struct cx231xx *dev = video_drvdata(file);
+	struct v4l2_control ctl;
 	struct v4l2_subdev *sd;
+	unsigned int i;
 
-	dprintk(3, "enter vidioc_s_ctrl()\n");
+	dprintk(3, "enter vidioc_s_ext_ctrl()\n");
 	/* Update the A/V core */
-	v4l2_device_for_each_subdev(sd, &dev->v4l2_dev)
-		v4l2_s_ctrl(NULL, sd->ctrl_handler, ctl);
-	dprintk(3, "exit vidioc_s_ctrl()\n");
+	for (i = 0; i < ctls->count; i++) {
+		ctl.id = ctls->controls[i].id;
+		ctl.value = ctls->controls[i].value;
+		v4l2_device_for_each_subdev(sd, &dev->v4l2_dev)
+			v4l2_s_ctrl(NULL, sd->ctrl_handler, &ctl);
+		ctls->controls[i].value = ctl.value;
+	}
+	dprintk(3, "exit vidioc_s_ext_ctrl()\n");
 	return 0;
 }
 
@@ -1627,7 +1634,7 @@ static const struct v4l2_ioctl_ops mpeg_ioctl_ops = {
 	.vidioc_enum_input	 = cx231xx_enum_input,
 	.vidioc_g_input		 = cx231xx_g_input,
 	.vidioc_s_input		 = cx231xx_s_input,
-	.vidioc_s_ctrl		 = vidioc_s_ctrl,
+	.vidioc_s_ext_ctrls	 = cx231xx_s_ext_ctrls,
 	.vidioc_g_pixelaspect	 = vidioc_g_pixelaspect,
 	.vidioc_g_selection	 = vidioc_g_selection,
 	.vidioc_querycap	 = cx231xx_querycap,
Signature · 1 line
2.47.0.338.g60cca15819-goog
#13 lore raw

PATCH 10/10 media: v4l2: Remove vidioc_s_ctrl callback

In reply to Ricardo Ribalda

All the drivers either use the control framework or provide a vidiod_ext_ctrl. We can remove this callback.

---
 drivers/media/v4l2-core/v4l2-dev.c   | 2 +-
 drivers/media/v4l2-core/v4l2-ioctl.c | 2 --
 include/media/v4l2-ioctl.h           | 4 ----
 3 files changed, 1 insertion(+), 7 deletions(-)
drivers/media/v4l2-core/v4l2-dev.c +1 -1
index 068ee67cd574..b40c08ce909d 100644
@@ -578,7 +578,7 @@ static void determine_valid_ioctls(struct video_device *vdev)
 		__set_bit(_IOC_NR(VIDIOC_QUERY_EXT_CTRL), valid_ioctls);
 	if (vdev->ctrl_handler || ops->vidioc_g_ext_ctrls)
 		__set_bit(_IOC_NR(VIDIOC_G_CTRL), valid_ioctls);
-	if (vdev->ctrl_handler || ops->vidioc_s_ctrl || ops->vidioc_s_ext_ctrls)
+	if (vdev->ctrl_handler || ops->vidioc_s_ext_ctrls)
 		__set_bit(_IOC_NR(VIDIOC_S_CTRL), valid_ioctls);
 	if (vdev->ctrl_handler || ops->vidioc_g_ext_ctrls)
 		__set_bit(_IOC_NR(VIDIOC_G_EXT_CTRLS), valid_ioctls);
drivers/media/v4l2-core/v4l2-ioctl.c +0 -2
index 4e65d50bef27..5a54e796086d 100644
@@ -2396,8 +2396,6 @@ static int v4l_s_ctrl(const struct v4l2_ioctl_ops *ops,
 		return v4l2_s_ctrl(vfh, vfh->ctrl_handler, p);
 	if (vfd->ctrl_handler)
 		return v4l2_s_ctrl(NULL, vfd->ctrl_handler, p);
-	if (ops->vidioc_s_ctrl)
-		return ops->vidioc_s_ctrl(file, fh, p);
 	if (ops->vidioc_s_ext_ctrls == NULL)
 		return -ENOTTY;
 
include/media/v4l2-ioctl.h +0 -4
index 4d69128023f8..c6ec87e88dfe 100644
@@ -195,8 +195,6 @@ struct v4l2_fh;
  *	:ref:`VIDIOC_S_OUTPUT <vidioc_g_output>` ioctl
  * @vidioc_query_ext_ctrl: pointer to the function that implements
  *	:ref:`VIDIOC_QUERY_EXT_CTRL <vidioc_queryctrl>` ioctl
- * @vidioc_s_ctrl: pointer to the function that implements
- *	:ref:`VIDIOC_S_CTRL <vidioc_g_ctrl>` ioctl
  * @vidioc_g_ext_ctrls: pointer to the function that implements
  *	:ref:`VIDIOC_G_EXT_CTRLS <vidioc_g_ext_ctrls>` ioctl
  * @vidioc_s_ext_ctrls: pointer to the function that implements
@@ -459,8 +457,6 @@ struct v4l2_ioctl_ops {
 		/* Control handling */
 	int (*vidioc_query_ext_ctrl)(struct file *file, void *fh,
 				     struct v4l2_query_ext_ctrl *a);
-	int (*vidioc_s_ctrl)(struct file *file, void *fh,
-			     struct v4l2_control *a);
 	int (*vidioc_g_ext_ctrls)(struct file *file, void *fh,
 				  struct v4l2_ext_controls *a);
 	int (*vidioc_s_ext_ctrls)(struct file *file, void *fh,
Signature · 1 line
2.47.0.338.g60cca15819-goog