media: vb2: prepare for vb2_ops_wait_prepare/finish removal
Subsystems (12)
cover media: vb2: prepare for vb2_ops_wait_prepare/finish removal
This patch series sits on top of:
https://patchwork.linuxtv.org/project/linux-media/list/?series=13513
This series makes it possible for drivers to drop the wait_prepare/finish callbacks if the queue lock pointer is set.
Analyzing the code shows that in a few places the lock is set after the call to vb2_queue_init, so the first 7 patches move that lock assignment up.
Then two additional WARN_ONs are added to vb2_queue_init to ensure that either q->lock is set, or wait_prepare/finish are set.
The last patch will just unlock/lock the queue lock if wait_prepare/finish isn't set.
Once this is in, we can start dropping the wait_prepare/finish ops in almost all drivers.
Regards,
Hans
Hans Verkuil (9):
media: staging: atomisp: set lock before calling vb2_queue_init()
media: pwc: set lock before calling vb2_queue_init()
media: msi2500: set lock before calling vb2_queue_init()
media: hackrf: set lock before calling vb2_queue_init()
media: airspy: set lock before calling vb2_queue_init()
media: rcar_drif.c: set lock before calling vb2_queue_init()
media: video-i2c: set lock before calling vb2_queue_init()
media: vb2: vb2_core_queue_init(): sanity check lock and
wait_prepare/finish
media: vb2: use lock if wait_prepare/finish are NULL
.../media/common/videobuf2/videobuf2-core.c | 21 ++++++++++++++++--- drivers/media/i2c/video-i2c.c | 2 +- drivers/media/platform/renesas/rcar_drif.c | 2 +- drivers/media/usb/airspy/airspy.c | 2 +- drivers/media/usb/hackrf/hackrf.c | 4 ++-- drivers/media/usb/msi2500/msi2500.c | 2 +- drivers/media/usb/pwc/pwc-if.c | 2 +- .../media/atomisp/pci/atomisp_subdev.c | 2 +- 8 files changed, 26 insertions(+), 11 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/9 media: staging: atomisp: set lock before calling vb2_queue_init()
The vb2_queue_init() will expect the vb2_queue lock pointer to be set in the future. So for those drivers that set the lock later, move it up to before the vb2_queue_init() call.
--- drivers/staging/media/atomisp/pci/atomisp_subdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/media/atomisp/pci/atomisp_subdev.c +1 -1
@@ -797,12 +797,12 @@ static int atomisp_init_subdev_pipe(struct atomisp_sub_device *asd, pipe->vb_queue.ops = &atomisp_vb2_ops; pipe->vb_queue.mem_ops = &vb2_vmalloc_memops; pipe->vb_queue.timestamp_flags =V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC ; + pipe->vb_queue.lock = &pipe->vb_queue_mutex; ret =vb2_queue_init (&pipe->vb_queue);if (ret)return ret; pipe->vdev.queue = &pipe->vb_queue; - pipe->vdev.queue->lock = &pipe->vb_queue_mutex;INIT_LIST_HEAD (&pipe->buffers_in_css);INIT_LIST_HEAD (&pipe->activeq);
Signature · 1 line
2.34.1
Re: [PATCH 1/9] media: staging: atomisp: set lock before calling vb2_queue_init()
Hi Hans,
Thank you for the patch.
Quoted 6 lines · Hans Verkuil
The
vb2_queue_init()will expect thevb2_queuelock pointer to be set in the future. So for those drivers that set the lock later, move it up to before thevb2_queue_init()call.Signed-off-by Hans Verkuil <[email protected]>Cc Hans de Goede <[email protected]>
Quoted 22 lines
--- drivers/staging/media/atomisp/pci/atomisp_subdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/staging/media/atomisp/pci/atomisp_subdev.c +1
-1@@ -797,12 +797,12 @@ static int atomisp_init_subdev_pipe(struct atomisp_sub_device *asd, pipe->vb_queue.ops = &atomisp_vb2_ops; pipe->vb_queue.mem_ops = &vb2_vmalloc_memops; pipe->vb_queue.timestamp_flags =V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC ; + pipe->vb_queue.lock = &pipe->vb_queue_mutex; ret =vb2_queue_init (&pipe->vb_queue);if (ret)return ret; pipe->vdev.queue = &pipe->vb_queue; - pipe->vdev.queue->lock = &pipe->vb_queue_mutex;INIT_LIST_HEAD (&pipe->buffers_in_css);INIT_LIST_HEAD (&pipe->activeq);
Signature · 3 lines
Regards, Laurent Pinchart
PATCH 2/9 media: pwc: set lock before calling vb2_queue_init()
In reply to Hans VerkuilThe vb2_queue_init() will expect the vb2_queue lock pointer to be set in the future. So for those drivers that set the lock later, move it up to before the vb2_queue_init() call.
--- drivers/media/usb/pwc/pwc-if.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/usb/pwc/pwc-if.c +1 -1
@@ -1054,6 +1054,7 @@ static int usb_pwc_probe(struct usb_interface *intf, const struct usb_device_id pdev->vb_queue.ops = &pwc_vb_queue_ops; pdev->vb_queue.mem_ops = &vb2_vmalloc_memops; pdev->vb_queue.timestamp_flags =V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC ; + pdev->vb_queue.lock = &pdev->vb_queue_lock; rc =vb2_queue_init (&pdev->vb_queue);if (rc <0 ) {PWC_ERROR ("Oops, could not initialize vb2 queue.\n" );
@@ -1064,7 +1065,6 @@ static int usb_pwc_probe(struct usb_interface *intf, const struct usb_device_id pdev->vdev = pwc_template;strscpy (pdev->vdev.name, name,sizeof (pdev->vdev.name)); pdev->vdev.queue = &pdev->vb_queue; - pdev->vdev.queue->lock = &pdev->vb_queue_lock;video_set_drvdata (&pdev->vdev, pdev); pdev->release =le16_to_cpu (udev->descriptor.bcdDevice);
Signature · 1 line
2.34.1
Re: [PATCH 2/9] media: pwc: set lock before calling vb2_queue_init()
Hi Hans,
Thank you for the patch.
Quoted 5 lines · Hans Verkuil
The
vb2_queue_init()will expect thevb2_queuelock pointer to be set in the future. So for those drivers that set the lock later, move it up to before thevb2_queue_init()call.Signed-off-by Hans Verkuil <[email protected]>
Quoted 24 lines
--- drivers/media/usb/pwc/pwc-if.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/media/usb/pwc/pwc-if.c +1
-1@@ -1054,6 +1054,7 @@ static int usb_pwc_probe(struct usb_interface *intf, const struct usb_device_id pdev->vb_queue.ops = &pwc_vb_queue_ops; pdev->vb_queue.mem_ops = &vb2_vmalloc_memops; pdev->vb_queue.timestamp_flags =V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC ; + pdev->vb_queue.lock = &pdev->vb_queue_lock; rc =vb2_queue_init (&pdev->vb_queue);if (rc <0 ) {PWC_ERROR ("Oops, could not initialize vb2 queue.\n" );@@ -1064,7 +1065,6 @@ static int usb_pwc_probe(struct usb_interface *intf, const struct usb_device_id pdev->vdev = pwc_template;strscpy (pdev->vdev.name, name,sizeof (pdev->vdev.name)); pdev->vdev.queue = &pdev->vb_queue; - pdev->vdev.queue->lock = &pdev->vb_queue_lock;video_set_drvdata (&pdev->vdev, pdev); pdev->release =le16_to_cpu (udev->descriptor.bcdDevice);
Signature · 3 lines
Regards, Laurent Pinchart
PATCH 3/9 media: msi2500: set lock before calling vb2_queue_init()
In reply to Hans VerkuilThe vb2_queue_init() will expect the vb2_queue lock pointer to be set in the future. So for those drivers that set the lock later, move it up to before the vb2_queue_init() call.
--- drivers/media/usb/msi2500/msi2500.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/usb/msi2500/msi2500.c +1 -1
@@ -1199,6 +1199,7 @@ static int msi2500_probe(struct usb_interface *intf, dev->vb_queue.ops = &msi2500_vb2_ops; dev->vb_queue.mem_ops = &vb2_vmalloc_memops; dev->vb_queue.timestamp_flags =V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC ; + dev->vb_queue.lock = &dev->vb_queue_lock; ret =vb2_queue_init (&dev->vb_queue);if (ret) {dev_err (dev->dev,"Could not initialize vb2 queue\n" );
@@ -1208,7 +1209,6 @@ static int msi2500_probe(struct usb_interface *intf,/* Init video_device structure */ dev->vdev = msi2500_template; dev->vdev.queue = &dev->vb_queue; - dev->vdev.queue->lock = &dev->vb_queue_lock;video_set_drvdata (&dev->vdev, dev);/* Register the v4l2_device structure */
Signature · 1 line
2.34.1
Re: [PATCH 3/9] media: msi2500: set lock before calling vb2_queue_init()
Hi Hans,
Thank you for the patch.
Quoted 5 lines · Hans Verkuil
The
vb2_queue_init()will expect thevb2_queuelock pointer to be set in the future. So for those drivers that set the lock later, move it up to before thevb2_queue_init()call.Signed-off-by Hans Verkuil <[email protected]>
Quoted 24 lines
--- drivers/media/usb/msi2500/msi2500.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/media/usb/msi2500/msi2500.c +1
-1@@ -1199,6 +1199,7 @@ static int msi2500_probe(struct usb_interface *intf, dev->vb_queue.ops = &msi2500_vb2_ops; dev->vb_queue.mem_ops = &vb2_vmalloc_memops; dev->vb_queue.timestamp_flags =V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC ; + dev->vb_queue.lock = &dev->vb_queue_lock; ret =vb2_queue_init (&dev->vb_queue);if (ret) {dev_err (dev->dev,"Could not initialize vb2 queue\n" );@@ -1208,7 +1209,6 @@ static int msi2500_probe(struct usb_interface *intf,/* Init video_device structure */ dev->vdev = msi2500_template; dev->vdev.queue = &dev->vb_queue; - dev->vdev.queue->lock = &dev->vb_queue_lock;video_set_drvdata (&dev->vdev, dev);/* Register the v4l2_device structure */
Signature · 3 lines
Regards, Laurent Pinchart
PATCH 4/9 media: hackrf: set lock before calling vb2_queue_init()
In reply to Hans VerkuilThe vb2_queue_init() will expect the vb2_queue lock pointer to be set in the future. So for those drivers that set the lock later, move it up to before the vb2_queue_init() call.
--- drivers/media/usb/hackrf/hackrf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/media/usb/hackrf/hackrf.c +2 -2
@@ -1398,6 +1398,7 @@ static int hackrf_probe(struct usb_interface *intf, dev->rx_vb2_queue.drv_priv = dev; dev->rx_vb2_queue.buf_struct_size =sizeof (struct hackrf_buffer ); dev->rx_vb2_queue.timestamp_flags =V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC ; + dev->rx_vb2_queue.lock = &dev->vb_queue_lock; ret =vb2_queue_init (&dev->rx_vb2_queue);if (ret) {dev_err (dev->dev,"Could not initialize rx vb2 queue\n" );
@@ -1413,6 +1414,7 @@ static int hackrf_probe(struct usb_interface *intf, dev->tx_vb2_queue.drv_priv = dev; dev->tx_vb2_queue.buf_struct_size =sizeof (struct hackrf_buffer ); dev->tx_vb2_queue.timestamp_flags =V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC ; + dev->tx_vb2_queue.lock = &dev->vb_queue_lock; ret =vb2_queue_init (&dev->tx_vb2_queue);if (ret) {dev_err (dev->dev,"Could not initialize tx vb2 queue\n" );
@@ -1474,7 +1476,6 @@ static int hackrf_probe(struct usb_interface *intf,/* Init video_device structure for receiver */ dev->rx_vdev = hackrf_template; dev->rx_vdev.queue = &dev->rx_vb2_queue; - dev->rx_vdev.queue->lock = &dev->vb_queue_lock; dev->rx_vdev.v4l2_dev = &dev->v4l2_dev; dev->rx_vdev.ctrl_handler = &dev->rx_ctrl_handler; dev->rx_vdev.lock = &dev->v4l2_lock;
@@ -1494,7 +1495,6 @@ static int hackrf_probe(struct usb_interface *intf,/* Init video_device structure for transmitter */ dev->tx_vdev = hackrf_template; dev->tx_vdev.queue = &dev->tx_vb2_queue; - dev->tx_vdev.queue->lock = &dev->vb_queue_lock; dev->tx_vdev.v4l2_dev = &dev->v4l2_dev; dev->tx_vdev.ctrl_handler = &dev->tx_ctrl_handler; dev->tx_vdev.lock = &dev->v4l2_lock;
Signature · 1 line
2.34.1
Re: [PATCH 4/9] media: hackrf: set lock before calling vb2_queue_init()
Hi Hans,
Thank you for the patch.
Quoted 22 lines · Hans Verkuil
The
vb2_queue_init()will expect thevb2_queuelock pointer to be set in the future. So for those drivers that set the lock later, move it up to before thevb2_queue_init()call.Signed-off-by Hans Verkuil <[email protected]>--- drivers/media/usb/hackrf/hackrf.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/media/usb/hackrf/hackrf.c +1
-0@@ -1398,6 +1398,7 @@ static int hackrf_probe(struct usb_interface *intf, dev->rx_vb2_queue.drv_priv = dev; dev->rx_vb2_queue.buf_struct_size =sizeof (struct hackrf_buffer ); dev->rx_vb2_queue.timestamp_flags =V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC ; + dev->rx_vb2_queue.lock = &dev->vb_queue_lock; ret =vb2_queue_init (&dev->rx_vb2_queue);if (ret) {dev_err (dev->dev,"Could not initialize rx vb2 queue\n" );
drivers/media/usb/hackrf/hackrf.c static int hackrf_probe(struct usb_interface *intf, · line 1417
Quoted 4 lines
drivers/media/usb/hackrf/hackrf.c +1
-0@@ -1413,6 +1414,7 @@ static int hackrf_probe(struct usb_interface *intf, dev->tx_vb2_queue.drv_priv = dev; dev->tx_vb2_queue.buf_struct_size =sizeof (struct hackrf_buffer ); dev->tx_vb2_queue.timestamp_flags =V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC ; + dev->tx_vb2_queue.lock = &dev->vb_queue_lock;
I'm not sure if setting the same lock for both video queues is desired, but that's unrelated to this patch.
Quoted 19 lines
drivers/media/usb/hackrf/hackrf.c +0
-2ret =vb2_queue_init (&dev->tx_vb2_queue);if (ret) {dev_err (dev->dev,"Could not initialize tx vb2 queue\n" );@@ -1474,7 +1476,6 @@ static int hackrf_probe(struct usb_interface *intf,/* Init video_device structure for receiver */ dev->rx_vdev = hackrf_template; dev->rx_vdev.queue = &dev->rx_vb2_queue; - dev->rx_vdev.queue->lock = &dev->vb_queue_lock; dev->rx_vdev.v4l2_dev = &dev->v4l2_dev; dev->rx_vdev.ctrl_handler = &dev->rx_ctrl_handler; dev->rx_vdev.lock = &dev->v4l2_lock;@@ -1494,7 +1495,6 @@ static int hackrf_probe(struct usb_interface *intf,/* Init video_device structure for transmitter */ dev->tx_vdev = hackrf_template; dev->tx_vdev.queue = &dev->tx_vb2_queue; - dev->tx_vdev.queue->lock = &dev->vb_queue_lock; dev->tx_vdev.v4l2_dev = &dev->v4l2_dev; dev->tx_vdev.ctrl_handler = &dev->tx_ctrl_handler; dev->tx_vdev.lock = &dev->v4l2_lock;
Signature · 3 lines
Regards, Laurent Pinchart
PATCH 5/9 media: airspy: set lock before calling vb2_queue_init()
In reply to Hans VerkuilThe vb2_queue_init() will expect the vb2_queue lock pointer to be set in the future. So for those drivers that set the lock later, move it up to before the vb2_queue_init() call.
--- drivers/media/usb/airspy/airspy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/usb/airspy/airspy.c +1 -1
@@ -1017,6 +1017,7 @@ static int airspy_probe(struct usb_interface *intf, s->vb_queue.ops = &airspy_vb2_ops; s->vb_queue.mem_ops = &vb2_vmalloc_memops; s->vb_queue.timestamp_flags =V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC ; + s->vb_queue.lock = &s->vb_queue_lock; ret =vb2_queue_init (&s->vb_queue);if (ret) {dev_err (s->dev,"Could not initialize vb2 queue\n" );
@@ -1026,7 +1027,6 @@ static int airspy_probe(struct usb_interface *intf,/* Init video_device structure */ s->vdev = airspy_template; s->vdev.queue = &s->vb_queue; - s->vdev.queue->lock = &s->vb_queue_lock;video_set_drvdata (&s->vdev, s);/* Register the v4l2_device structure */
Signature · 1 line
2.34.1
Re: [PATCH 5/9] media: airspy: set lock before calling vb2_queue_init()
Hi Hans,
Thank you for the patch.
Quoted 5 lines · Hans Verkuil
The
vb2_queue_init()will expect thevb2_queuelock pointer to be set in the future. So for those drivers that set the lock later, move it up to before thevb2_queue_init()call.Signed-off-by Hans Verkuil <[email protected]>
Quoted 24 lines
--- drivers/media/usb/airspy/airspy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/media/usb/airspy/airspy.c +1
-1@@ -1017,6 +1017,7 @@ static int airspy_probe(struct usb_interface *intf, s->vb_queue.ops = &airspy_vb2_ops; s->vb_queue.mem_ops = &vb2_vmalloc_memops; s->vb_queue.timestamp_flags =V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC ; + s->vb_queue.lock = &s->vb_queue_lock; ret =vb2_queue_init (&s->vb_queue);if (ret) {dev_err (s->dev,"Could not initialize vb2 queue\n" );@@ -1026,7 +1027,6 @@ static int airspy_probe(struct usb_interface *intf,/* Init video_device structure */ s->vdev = airspy_template; s->vdev.queue = &s->vb_queue; - s->vdev.queue->lock = &s->vb_queue_lock;video_set_drvdata (&s->vdev, s);/* Register the v4l2_device structure */
Signature · 3 lines
Regards, Laurent Pinchart
PATCH 6/9 media: rcar_drif.c: set lock before calling vb2_queue_init()
In reply to Hans VerkuilThe vb2_queue_init() will expect the vb2_queue lock pointer to be set in the future. So for those drivers that set the lock later, move it up to before the vb2_queue_init() call.
--- drivers/media/platform/renesas/rcar_drif.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/platform/renesas/rcar_drif.c +1 -1
@@ -1071,7 +1071,6 @@ static int rcar_drif_sdr_register(struct rcar_drif_sdr *sdr) sdr->vdev->release = video_device_release; sdr->vdev->lock = &sdr->v4l2_mutex; sdr->vdev->queue = &sdr->vb_queue; - sdr->vdev->queue->lock = &sdr->vb_queue_mutex; sdr->vdev->ctrl_handler = &sdr->ctrl_hdl; sdr->vdev->v4l2_dev = &sdr->v4l2_dev; sdr->vdev->device_caps = V4L2_CAP_SDR_CAPTURE | V4L2_CAP_TUNER |
@@ -1316,6 +1315,7 @@ static int rcar_drif_sdr_probe(struct rcar_drif_sdr *sdr) sdr->vb_queue.ops = &rcar_drif_vb2_ops; sdr->vb_queue.mem_ops = &vb2_vmalloc_memops; sdr->vb_queue.timestamp_flags =V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC ; + sdr->vb_queue.lock = &sdr->vb_queue_mutex;/* Init videobuf2 queue */ ret =vb2_queue_init (&sdr->vb_queue);
Signature · 1 line
2.34.1
Re: [PATCH 6/9] media: rcar_drif.c: set lock before calling vb2_queue_init()
Hi Hans,
Thank you for the patch.
Quoted 3 lines · Hans Verkuil
The
vb2_queue_init()will expect thevb2_queuelock pointer to be set in the future. So for those drivers that set the lock later, move it up to before thevb2_queue_init()call.
The commit message doesn't match the change below, you're moving the lock down, not up.
Quoted 27 lines
Signed-off-by Hans Verkuil <[email protected]>Cc Ramesh Shanmugasundaram <[email protected]>Cc Jacopo Mondi <[email protected]>--- drivers/media/platform/renesas/rcar_drif.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/media/platform/renesas/rcar_drif.c +1
-1@@ -1071,7 +1071,6 @@ static int rcar_drif_sdr_register(struct rcar_drif_sdr *sdr) sdr->vdev->release = video_device_release; sdr->vdev->lock = &sdr->v4l2_mutex; sdr->vdev->queue = &sdr->vb_queue; - sdr->vdev->queue->lock = &sdr->vb_queue_mutex; sdr->vdev->ctrl_handler = &sdr->ctrl_hdl; sdr->vdev->v4l2_dev = &sdr->v4l2_dev; sdr->vdev->device_caps = V4L2_CAP_SDR_CAPTURE | V4L2_CAP_TUNER |@@ -1316,6 +1315,7 @@ static int rcar_drif_sdr_probe(struct rcar_drif_sdr *sdr) sdr->vb_queue.ops = &rcar_drif_vb2_ops; sdr->vb_queue.mem_ops = &vb2_vmalloc_memops; sdr->vb_queue.timestamp_flags =V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC ; + sdr->vb_queue.lock = &sdr->vb_queue_mutex;/* Init videobuf2 queue */ ret =vb2_queue_init (&sdr->vb_queue);
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH 6/9] media: rcar_drif.c: set lock before calling vb2_queue_init()
Quoted 11 lines · Laurent Pinchart
Hi Hans,
Thank you for the patch.
Quoted 3 lines · Hans Verkuil
The
vb2_queue_init()will expect thevb2_queuelock pointer to be set in the future. So for those drivers that set the lock later, move it up to before thevb2_queue_init()call.The commit message doesn't match the change below, you're moving the lock down, not up.
Actually, I am moving it up, as in 'set earlier', but in this case it is a bit confusing in the patch.
Regards,
Hans
Quoted 29 lines
Quoted 28 lines
Signed-off-by Hans Verkuil <[email protected]>Cc Ramesh Shanmugasundaram <[email protected]>Cc Jacopo Mondi <[email protected]>--- drivers/media/platform/renesas/rcar_drif.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/media/platform/renesas/rcar_drif.c +1
-1@@ -1071,7 +1071,6 @@ static int rcar_drif_sdr_register(struct rcar_drif_sdr *sdr) sdr->vdev->release = video_device_release; sdr->vdev->lock = &sdr->v4l2_mutex; sdr->vdev->queue = &sdr->vb_queue; - sdr->vdev->queue->lock = &sdr->vb_queue_mutex; sdr->vdev->ctrl_handler = &sdr->ctrl_hdl; sdr->vdev->v4l2_dev = &sdr->v4l2_dev; sdr->vdev->device_caps = V4L2_CAP_SDR_CAPTURE | V4L2_CAP_TUNER |@@ -1316,6 +1315,7 @@ static int rcar_drif_sdr_probe(struct rcar_drif_sdr *sdr) sdr->vb_queue.ops = &rcar_drif_vb2_ops; sdr->vb_queue.mem_ops = &vb2_vmalloc_memops; sdr->vb_queue.timestamp_flags =V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC ; + sdr->vb_queue.lock = &sdr->vb_queue_mutex;/* Init videobuf2 queue */ ret =vb2_queue_init (&sdr->vb_queue);
Laurent Pinchart
Reviewed-byRe: [PATCH 6/9] media: rcar_drif.c: set lock before calling vb2_queue_init()
Quoted 11 lines · Hans Verkuil
Quoted 7 lines · Laurent Pinchart
Quoted 3 lines · Hans Verkuil
The
vb2_queue_init()will expect thevb2_queuelock pointer to be set in the future. So for those drivers that set the lock later, move it up to before thevb2_queue_init()call.The commit message doesn't match the change below, you're moving the lock down, not up.
Actually, I am moving it up, as in 'set earlier', but in this case it is a bit confusing in the patch.
Oops indeed, I thought both changes were in the same function.
Quoted 27 lines
Quoted 27 lines
Quoted 27 lines
Signed-off-by Hans Verkuil <[email protected]>Cc Ramesh Shanmugasundaram <[email protected]>Cc Jacopo Mondi <[email protected]>--- drivers/media/platform/renesas/rcar_drif.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/media/platform/renesas/rcar_drif.c +1
-1@@ -1071,7 +1071,6 @@ static int rcar_drif_sdr_register(struct rcar_drif_sdr *sdr) sdr->vdev->release = video_device_release; sdr->vdev->lock = &sdr->v4l2_mutex; sdr->vdev->queue = &sdr->vb_queue; - sdr->vdev->queue->lock = &sdr->vb_queue_mutex; sdr->vdev->ctrl_handler = &sdr->ctrl_hdl; sdr->vdev->v4l2_dev = &sdr->v4l2_dev; sdr->vdev->device_caps = V4L2_CAP_SDR_CAPTURE | V4L2_CAP_TUNER |@@ -1316,6 +1315,7 @@ static int rcar_drif_sdr_probe(struct rcar_drif_sdr *sdr) sdr->vb_queue.ops = &rcar_drif_vb2_ops; sdr->vb_queue.mem_ops = &vb2_vmalloc_memops; sdr->vb_queue.timestamp_flags =V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC ; + sdr->vb_queue.lock = &sdr->vb_queue_mutex;/* Init videobuf2 queue */ ret =vb2_queue_init (&sdr->vb_queue);
Signature · 3 lines
Regards, Laurent Pinchart
PATCH 7/9 media: video-i2c: set lock before calling vb2_queue_init()
In reply to Hans VerkuilThe vb2_queue_init() will expect the vb2_queue lock pointer to be set in the future. So for those drivers that set the lock later, move it up to before the vb2_queue_init() call.
--- drivers/media/i2c/video-i2c.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/media/i2c/video-i2c.c +1 -1
@@ -798,13 +798,13 @@ static int video_i2c_probe(struct i2c_client *client) queue->min_queued_buffers =1 ; queue->ops = &video_i2c_video_qops; queue->mem_ops = &vb2_vmalloc_memops; + queue->lock = &data->queue_lock; ret =vb2_queue_init (queue);if (ret <0 ) goto error_unregister_device; data->vdev.queue = queue; - data->vdev.queue->lock = &data->queue_lock; snprintf(data->vdev.name, sizeof(data->vdev.name), "I2C %d-%d Transport Video",
Signature · 1 line
2.34.1
Re: [PATCH 7/9] media: video-i2c: set lock before calling vb2_queue_init()
Sent with Proton Mail secure email.
Quoted 6 lines · Hans Verkuil
The
vb2_queue_init()will expect thevb2_queuelock pointer to be set in the future. So for those drivers that set the lock later, move it up to before thevb2_queue_init()call.Signed-off-by Hans Verkuil [email protected]
LGTM
Quoted 34 lines
Cc Matt Ranostay [email protected]---
drivers/media/i2c/video-i2c.c| 2 +-1 file changed, 1 insertion(+), 1 deletion(-)drivers/media/i2c/video-i2c.c +1
-0@@ -798,13 +798,13 @@ static int video_i2c_probe(struct i2c_client *client) queue->min_queued_buffers =1 ; queue->ops = &video_i2c_video_qops; queue->mem_ops = &vb2_vmalloc_memops; + queue->lock = &data->queue_lock; ret =vb2_queue_init (queue);if (ret <0 ) goto error_unregister_device;
data->vdev.queue= queue;-
data->vdev.queue->lock=&data->queue_lock;snprintf(data->vdev.name,
sizeof(data->vdev.name),"I2C %d-%d Transport Video",
--
2.34.1
Re: [PATCH 7/9] media: video-i2c: set lock before calling vb2_queue_init()
In reply to Hans VerkuilHi Hans,
Thank you for the patch.
Quoted 6 lines · Hans Verkuil
The
vb2_queue_init()will expect thevb2_queuelock pointer to be set in the future. So for those drivers that set the lock later, move it up to before thevb2_queue_init()call.Signed-off-by Hans Verkuil <[email protected]>Cc Matt Ranostay <[email protected]>
Quoted 23 lines
--- drivers/media/i2c/video-i2c.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/media/i2c/video-i2c.c +1
-1@@ -798,13 +798,13 @@ static int video_i2c_probe(struct i2c_client *client) queue->min_queued_buffers =1 ; queue->ops = &video_i2c_video_qops; queue->mem_ops = &vb2_vmalloc_memops; + queue->lock = &data->queue_lock; ret =vb2_queue_init (queue);if (ret <0 ) goto error_unregister_device; data->vdev.queue = queue; - data->vdev.queue->lock = &data->queue_lock; snprintf(data->vdev.name, sizeof(data->vdev.name), "I2C %d-%d Transport Video",
Signature · 3 lines
Regards, Laurent Pinchart
PATCH 8/9 media: vb2: vb2_core_queue_init(): sanity check lock and wait_prepare/finish
In reply to Hans VerkuilAdd two new checks:
1) wait_prepare and wait_finish callbacks are either both present or both unset, you can't mix.
2) if lock == NULL, then wait_prepare (and due to check 1 also wait_finish) must be present.
These checks should prevent the case where lock == NULL, but there is no way to release/reacquire whatever lock is used when waiting for a buffer to arrive in VIDIOC_DQBUF.
--- drivers/media/common/videobuf2/videobuf2-core.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/media/common/videobuf2/videobuf2-core.c +8 -0
@@ -2644,6 +2644,14 @@ int vb2_core_queue_init(struct vb2_queue *q)if (WARN_ON (q->min_reqbufs_allocation > q->max_num_buffers))return -EINVAL ; +/* Either both or none are set */ +if (WARN_ON (!q->ops->wait_prepare ^ !q->ops->wait_finish)) +return -EINVAL ; + +/* Warn if q->lock is NULL and no custom wait_prepare is provided */ +if (WARN_ON (!q->lock && !q->ops->wait_prepare)) +return -EINVAL ; +INIT_LIST_HEAD (&q->queued_list);INIT_LIST_HEAD (&q->done_list);spin_lock_init (&q->done_lock);
Signature · 1 line
2.34.1
Re: [PATCH 8/9] media: vb2: vb2_core_queue_init(): sanity check lock and wait_prepare/finish
Hi Hans,
Thank you for the patch.
Quoted 10 lines · Hans Verkuil
Add two new checks:
1)
wait_prepareandwait_finishcallbacks are either both present or both unset, you can't mix.
2) if lock == NULL, thenwait_prepare(and due to check 1 alsowait_finish) must be present.These checks should prevent the case where lock == NULL, but there is no way to release/reacquire whatever lock is used when waiting for a buffer to arrive in
VIDIOC_DQBUF.
Don't we use the video_device lock when the queue lock is NULL ? Shouldn't it be valid to not set wait_prepare and wait_finish in that case ?
Quoted 24 lines
Signed-off-by Hans Verkuil <[email protected]>--- drivers/media/common/videobuf2/videobuf2-core.c | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/media/common/videobuf2/videobuf2-core.c +8
-0@@ -2644,6 +2644,14 @@ int vb2_core_queue_init(struct vb2_queue *q)if (WARN_ON (q->min_reqbufs_allocation > q->max_num_buffers))return -EINVAL ; +/* Either both or none are set */ +if (WARN_ON (!q->ops->wait_prepare ^ !q->ops->wait_finish)) +return -EINVAL ; + +/* Warn if q->lock is NULL and no custom wait_prepare is provided */ +if (WARN_ON (!q->lock && !q->ops->wait_prepare)) +return -EINVAL ; +INIT_LIST_HEAD (&q->queued_list);INIT_LIST_HEAD (&q->done_list);spin_lock_init (&q->done_lock);
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH 8/9] media: vb2: vb2_core_queue_init(): sanity check lock and wait_prepare/finish
Quoted 12 lines · Laurent Pinchart
Hi Hans,
Thank you for the patch.
Quoted 7 lines · Hans Verkuil
Add two new checks:
1)
wait_prepareandwait_finishcallbacks are either both present or both unset, you can't mix.
2) if lock == NULL, thenwait_prepare(and due to check 1 alsowait_finish) must be present.
Quoted 7 lines
Quoted 3 lines
These checks should prevent the case where lock == NULL, but there is no way to release/reacquire whatever lock is used when waiting for a buffer to arrive in
VIDIOC_DQBUF.Don't we use the
video_devicelock when the queue lock is NULL ? Shouldn't it be valid to not setwait_prepareandwait_finishin that case ?
If q->lock is NULL, then vb2 doesn't know which mutex needs to be unlocked while waiting for a buffer to arrive (and reacquired afterwards). So in that case you need to provide a function. Remember that vb2 doesn't know about the video_device lock. It is the driver that normally fills in q->lock, and often (or even always?) that is indeed the video_device lock.
If q->lock is NULL, and these functions are not provided, then that is almost certainly a bug since there is almost certainly some serialization mutex. And if you don't unlock that while waiting, then you can't issue other ioctls. In the unlikely event that there really is no mutex involved, then you have to supply empty functions. There is no driver like that, though.
Regards,
Hans
Quoted 26 lines
Quoted 25 lines
Signed-off-by Hans Verkuil <[email protected]>--- drivers/media/common/videobuf2/videobuf2-core.c | 8 ++++++++ 1 file changed, 8 insertions(+)drivers/media/common/videobuf2/videobuf2-core.c +8
-0@@ -2644,6 +2644,14 @@ int vb2_core_queue_init(struct vb2_queue *q)if (WARN_ON (q->min_reqbufs_allocation > q->max_num_buffers))return -EINVAL ; +/* Either both or none are set */ +if (WARN_ON (!q->ops->wait_prepare ^ !q->ops->wait_finish)) +return -EINVAL ; + +/* Warn if q->lock is NULL and no custom wait_prepare is provided */ +if (WARN_ON (!q->lock && !q->ops->wait_prepare)) +return -EINVAL ; +INIT_LIST_HEAD (&q->queued_list);INIT_LIST_HEAD (&q->done_list);spin_lock_init (&q->done_lock);
PATCH 9/9 media: vb2: use lock if wait_prepare/finish are NULL
In reply to Hans VerkuilIf the wait_prepare or wait_finish callback is set, then call it. If it is NULL and the queue lock pointer is not NULL, then just unlock/lock that mutex.
This allows simplifying drivers by dropping the wait_prepare and wait_finish ops (and eventually the vb2_ops_wait_prepare/finish helpers).
--- drivers/media/common/videobuf2/videobuf2-core.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/media/common/videobuf2/videobuf2-core.c +10 -3
@@ -2035,7 +2035,10 @@ static int __vb2_wait_for_done_vb(struct vb2_queue *q, int nonblocking)* become ready or for streamoff. Driver's lock is released to * allow streamoff or qbuf to be called while waiting. */ -call_void_qop (q, wait_prepare, q); +if (q->ops->wait_prepare) +call_void_qop (q, wait_prepare, q); +else if (q->lock) +mutex_unlock (q->lock);/* * All locks have been released, it is safe to sleep now.
@@ -2045,12 +2048,16 @@ static int __vb2_wait_for_done_vb(struct vb2_queue *q, int nonblocking) !list_empty (&q->done_list) || !q->streaming || q->error); +if (q->ops->wait_finish) +call_void_qop (q, wait_finish, q); +else if (q->lock) +mutex_lock (q->lock); + + q->waiting_in_dqbuf =0 ;/* * We need to reevaluate both conditions again after reacquiring * the locks or return an error if one occurred. */ -call_void_qop (q, wait_finish, q); - q->waiting_in_dqbuf =0 ;if (ret) {dprintk (q,1 ,"sleep was interrupted\n" );return ret;
Signature · 1 line
2.34.1
Re: [PATCH 9/9] media: vb2: use lock if wait_prepare/finish are NULL
Hi Hans,
Thank you for the patch.
Quoted 17 lines · Hans Verkuil
If the
wait_prepareorwait_finishcallback is set, then call it. If it is NULL and the queue lock pointer is not NULL, then just unlock/lock that mutex.This allows simplifying drivers by dropping the
wait_prepareandwait_finishops (and eventually the vb2_ops_wait_prepare/finish helpers).Signed-off-by Hans Verkuil <[email protected]>--- drivers/media/common/videobuf2/videobuf2-core.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)drivers/media/common/videobuf2/videobuf2-core.c +0
-0
drivers/media/common/videobuf2/videobuf2-core.c static int __vb2_wait_for_done_vb(struct vb2_queue *q, int nonblocking) · line 2041
Quoted 8 lines
drivers/media/common/videobuf2/videobuf2-core.c +4
-1@@ -2035,7 +2035,10 @@ static int __vb2_wait_for_done_vb(struct vb2_queue *q, int nonblocking)* become ready or for streamoff. Driver's lock is released to * allow streamoff or qbuf to be called while waiting. */ -call_void_qop (q, wait_prepare, q); +if (q->ops->wait_prepare) +call_void_qop (q, wait_prepare, q); +else if (q->lock) +mutex_unlock (q->lock);
How about calling vb2_ops_wait_prepare() here ? I think that would be more explicit. You would likely need to move the function to videobuf2-core.c. Same below for wait_finish.
Quoted 22 lines
drivers/media/common/videobuf2/videobuf2-core.c +6
-2/* * All locks have been released, it is safe to sleep now. @@ -2045,12 +2048,16 @@ static int __vb2_wait_for_done_vb(struct vb2_queue *q, int nonblocking) !list_empty (&q->done_list) || !q->streaming || q->error); +if (q->ops->wait_finish) +call_void_qop (q, wait_finish, q); +else if (q->lock) +mutex_lock (q->lock); + + q->waiting_in_dqbuf =0 ;/* * We need to reevaluate both conditions again after reacquiring * the locks or return an error if one occurred. */ -call_void_qop (q, wait_finish, q); - q->waiting_in_dqbuf =0 ;if (ret) {dprintk (q,1 ,"sleep was interrupted\n" );return ret;
Signature · 3 lines
Regards, Laurent Pinchart
Re: [PATCH 9/9] media: vb2: use lock if wait_prepare/finish are NULL
Quoted 26 lines · Laurent Pinchart
Hi Hans,
Thank you for the patch.
Quoted 21 lines · Hans Verkuil
If the
wait_prepareorwait_finishcallback is set, then call it. If it is NULL and the queue lock pointer is not NULL, then just unlock/lock that mutex.This allows simplifying drivers by dropping the
wait_prepareandwait_finishops (and eventually the vb2_ops_wait_prepare/finish helpers).Signed-off-by Hans Verkuil <[email protected]>--- drivers/media/common/videobuf2/videobuf2-core.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)drivers/media/common/videobuf2/videobuf2-core.c +0
-1@@ -2035,7 +2035,10 @@ static int __vb2_wait_for_done_vb(struct vb2_queue *q, int nonblocking)* become ready or for streamoff. Driver's lock is released to * allow streamoff or qbuf to be called while waiting. */ -call_void_qop (q, wait_prepare, q);
Quoted 8 lines
drivers/media/common/videobuf2/videobuf2-core.c static int __vb2_wait_for_done_vb(struct vb2_queue *q, int nonblocking) · line 2041
Quoted 4 lines
drivers/media/common/videobuf2/videobuf2-core.c +4
-0+if (q->ops->wait_prepare) +call_void_qop (q, wait_prepare, q); +else if (q->lock) +mutex_unlock (q->lock);How about calling
vb2_ops_wait_prepare()here ? I think that would be more explicit. You would likely need to move the function tovideobuf2-core.c. Same below forwait_finish.
Why would I call a function that does exactly this? It is just harder to see what it does since you need to look up that function.
Just in case it wasn't clear: once this series is in I can start removing vb2_ops_wait_prepare/finish from all media drivers, and eventually remove those two helpers from vb2.
Regards,
Hans
Quoted 24 lines
Quoted 23 lines
drivers/media/common/videobuf2/videobuf2-core.c +6
-2/* * All locks have been released, it is safe to sleep now. @@ -2045,12 +2048,16 @@ static int __vb2_wait_for_done_vb(struct vb2_queue *q, int nonblocking) !list_empty (&q->done_list) || !q->streaming || q->error); +if (q->ops->wait_finish) +call_void_qop (q, wait_finish, q); +else if (q->lock) +mutex_lock (q->lock); + + q->waiting_in_dqbuf =0 ;/* * We need to reevaluate both conditions again after reacquiring * the locks or return an error if one occurred. */ -call_void_qop (q, wait_finish, q); - q->waiting_in_dqbuf =0 ;if (ret) {dprintk (q,1 ,"sleep was interrupted\n" );return ret;