Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[PATCH] vb2: Check if there are buffers before streamon

2 views
Skip to first unread message

Ricardo Ribalda Delgado

unread,
Jan 7, 2014, 9:00:03 AM1/7/14
to
This patch adds a test preventing streamon() if there is no buffer
ready.

Without this patch, a user could call streamon() before
preparing any buffer. This leads to a situation where if he calls
close() before calling streamoff() the device is kept streaming.

Signed-off-by: Ricardo Ribalda Delgado <ricardo...@gmail.com>
---
drivers/media/v4l2-core/videobuf2-core.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c
index 098df28..6f20e5a 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -1776,6 +1776,11 @@ static int vb2_internal_streamon(struct vb2_queue *q, enum v4l2_buf_type type)
return 0;
}

+ if (!q->num_buffers) {
+ dprintk(1, "streamon: no frames have been requested\n");
+ return -EINVAL;
+ }
+
/*
* If any buffers were queued before streamon,
* we can now pass them to driver for processing.
--
1.8.5.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majo...@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Marek Szyprowski

unread,
Jan 7, 2014, 10:40:03 AM1/7/14
to
Hi,

On 2014-01-07 14:55, Ricardo Ribalda Delgado wrote:
> This patch adds a test preventing streamon() if there is no buffer
> ready.
>
> Without this patch, a user could call streamon() before
> preparing any buffer. This leads to a situation where if he calls
> close() before calling streamoff() the device is kept streaming.
>
> Signed-off-by: Ricardo Ribalda Delgado <ricardo...@gmail.com>
> ---
> drivers/media/v4l2-core/videobuf2-core.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c
> index 098df28..6f20e5a 100644
> --- a/drivers/media/v4l2-core/videobuf2-core.c
> +++ b/drivers/media/v4l2-core/videobuf2-core.c
> @@ -1776,6 +1776,11 @@ static int vb2_internal_streamon(struct vb2_queue *q, enum v4l2_buf_type type)
> return 0;
> }
>
> + if (!q->num_buffers) {
> + dprintk(1, "streamon: no frames have been requested\n");

I think that "streamon: error - no buffers have been allocated\n"
message is a bit
more descriptive and it matches the definitions used elsewhere in the
debug messages.
Please don't mix buffers and frames.

> + return -EINVAL;
> + }
> +
> /*
> * If any buffers were queued before streamon,
> * we can now pass them to driver for processing.

Best regards
--
Marek Szyprowski, PhD
Samsung R&D Institute Poland

Ricardo Ribalda Delgado

unread,
Jan 7, 2014, 11:00:03 AM1/7/14
to
This patch adds a test preventing streamon() if there is no buffer
ready.

Without this patch, a user could call streamon() before
preparing any buffer. This leads to a situation where if he calls
close() before calling streamoff() the device is kept streaming.

Signed-off-by: Ricardo Ribalda Delgado <ricardo...@gmail.com>
---
v2: Comment by Marek Szyprowski:
Reword error message
drivers/media/v4l2-core/videobuf2-core.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c
index 098df28..6f20e5a 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -1776,6 +1776,11 @@ static int vb2_internal_streamon(struct vb2_queue *q, enum v4l2_buf_type type)
return 0;
}

+ if (!q->num_buffers) {
+ dprintk(1, "streamon: no frames have been requested\n");
+ return -EINVAL;
+ }
+
/*
* If any buffers were queued before streamon,
* we can now pass them to driver for processing.
--
1.8.5.2

Ricardo Ribalda Delgado

unread,
Jan 8, 2014, 3:10:01 AM1/8/14
to
This patch adds a test preventing streamon() if there is no buffer
ready.

Without this patch, a user could call streamon() before
preparing any buffer. This leads to a situation where if he calls
close() before calling streamoff() the device is kept streaming.

Signed-off-by: Ricardo Ribalda Delgado <ricardo...@gmail.com>
---
v2: Comment by Marek Szyprowski:
Reword error message

v3: Comment by Marek Szyprowski:
Actualy do the reword :)

drivers/media/v4l2-core/videobuf2-core.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c
index 098df28..6409e0a 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -1776,6 +1776,11 @@ static int vb2_internal_streamon(struct vb2_queue *q, enum v4l2_buf_type type)
return 0;
}

+ if (!q->num_buffers) {
+ dprintk(1, "streamon: no buffers have been allocated\n");

Marek Szyprowski

unread,
Jan 8, 2014, 4:30:03 AM1/8/14
to
Hello,

On 2014-01-08 09:01, Ricardo Ribalda Delgado wrote:
> This patch adds a test preventing streamon() if there is no buffer
> ready.
>
> Without this patch, a user could call streamon() before
> preparing any buffer. This leads to a situation where if he calls
> close() before calling streamoff() the device is kept streaming.
>
> Signed-off-by: Ricardo Ribalda Delgado <ricardo...@gmail.com>

Reviewed-by: Marek Szyprowski <m.szyp...@samsung.com>

> ---
> v2: Comment by Marek Szyprowski:
> Reword error message
>
> v3: Comment by Marek Szyprowski:
> Actualy do the reword :)
>
> drivers/media/v4l2-core/videobuf2-core.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c
> index 098df28..6409e0a 100644
> --- a/drivers/media/v4l2-core/videobuf2-core.c
> +++ b/drivers/media/v4l2-core/videobuf2-core.c
> @@ -1776,6 +1776,11 @@ static int vb2_internal_streamon(struct vb2_queue *q, enum v4l2_buf_type type)
> return 0;
> }
>
> + if (!q->num_buffers) {
> + dprintk(1, "streamon: no buffers have been allocated\n");
> + return -EINVAL;
> + }
> +
> /*
> * If any buffers were queued before streamon,
> * we can now pass them to driver for processing.

Best regards
--
Marek Szyprowski, PhD
Samsung R&D Institute Poland

Andrzej Hajda

unread,
Apr 1, 2014, 7:10:03 AM4/1/14
to
Hi,

It seems the patch has been applied twice in linux-next/master:

$ git log --oneline -25 linux-next/master
drivers/media/v4l2-core/videobuf2-core.c
9cf3c31 [media] vb2: call buf_finish after the state check
3f1a9a3 [media] vb2: fix streamoff handling if streamon wasn't called
e4d2581 [media] vb2: replace BUG by WARN_ON
fb64dca [media] vb2: properly clean up PREPARED and QUEUED buffers
b3379c6 [media] vb2: only call start_streaming if sufficient buffers are
queued
a7afcac [media] vb2: don't init the list if there are still buffers
6ea3b98 [media] vb2: rename queued_count to owned_by_drv_count
256f316 [media] vb2: fix buf_init/buf_cleanup call sequences
9c0863b [media] vb2: call buf_finish from __queue_cancel
0647064 [media] vb2: change result code of buf_finish to void
b5b4541 [media] vb2: add debugging code to check for unbalanced ops
952c9ee [media] vb2: fix PREPARE_BUF regression
4e5a4d8 [media] vb2: fix read/write regression
>>>>> 249f5a5 [media] vb2: Check if there are buffers before streamon
c897df0 Merge tag 'v3.14-rc5' into patchwork
7ce6fd8 [media] v4l: Handle buffer timestamp flags correctly
872484c [media] v4l: Add timestamp source flags, mask and document them
c57ff79 [media] v4l: Timestamp flags will soon contain timestamp source,
not just type
ade4868 [media] v4l: Rename vb2_queue.timestamp_type as timestamp_flags
f134328 [media] vb2: fix timecode and flags handling for output buffers
>>>>> 548df78 [media] vb2: Check if there are buffers before streamon



Regards
Andrzej
0 new messages