diff mbox

[RFCv4,08/11] vb2: q->num_buffers was updated too soon

Message ID 1392374472-18393-9-git-send-email-hverkuil@xs4all.nl (mailing list archive)
State New, archived
Headers show

Commit Message

Hans Verkuil Feb. 14, 2014, 10:41 a.m. UTC
From: Hans Verkuil <hans.verkuil@cisco.com>

In __reqbufs() and __create_bufs() the q->num_buffers field was updated
with the number of newly allocated buffers, but right after that those are
freed again if some error had occurred before. Move the line updating
num_buffers to *after* that error check.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
---
 drivers/media/v4l2-core/videobuf2-core.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Hans Verkuil Feb. 23, 2014, 8:36 a.m. UTC | #1
On 02/14/2014 11:41 AM, Hans Verkuil wrote:
> From: Hans Verkuil <hans.verkuil@cisco.com>
> 
> In __reqbufs() and __create_bufs() the q->num_buffers field was updated
> with the number of newly allocated buffers, but right after that those are
> freed again if some error had occurred before. Move the line updating
> num_buffers to *after* that error check.
> 
> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>

NACK: this is actually correct behavior since __vb2_queue_free() subtracts
'allocated_buffers' from q->num_buffers. A comment mentioning this might be
useful, though.

Regards,

	Hans

> ---
>  drivers/media/v4l2-core/videobuf2-core.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c
> index ad3db83..96c5ac6 100644
> --- a/drivers/media/v4l2-core/videobuf2-core.c
> +++ b/drivers/media/v4l2-core/videobuf2-core.c
> @@ -848,13 +848,13 @@ static int __reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req)
>  		 */
>  	}
>  
> -	q->num_buffers = allocated_buffers;
> -
>  	if (ret < 0) {
>  		__vb2_queue_free(q, allocated_buffers);
>  		return ret;
>  	}
>  
> +	q->num_buffers = allocated_buffers;
> +
>  	/*
>  	 * Return the number of successfully allocated buffers
>  	 * to the userspace.
> @@ -957,13 +957,13 @@ static int __create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create
>  		 */
>  	}
>  
> -	q->num_buffers += allocated_buffers;
> -
>  	if (ret < 0) {
>  		__vb2_queue_free(q, allocated_buffers);
>  		return -ENOMEM;
>  	}
>  
> +	q->num_buffers += allocated_buffers;
> +
>  	/*
>  	 * Return the number of successfully allocated buffers
>  	 * to the userspace.
> 

--
To unsubscribe from this list: send the line "unsubscribe linux-media" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c
index ad3db83..96c5ac6 100644
--- a/drivers/media/v4l2-core/videobuf2-core.c
+++ b/drivers/media/v4l2-core/videobuf2-core.c
@@ -848,13 +848,13 @@  static int __reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req)
 		 */
 	}
 
-	q->num_buffers = allocated_buffers;
-
 	if (ret < 0) {
 		__vb2_queue_free(q, allocated_buffers);
 		return ret;
 	}
 
+	q->num_buffers = allocated_buffers;
+
 	/*
 	 * Return the number of successfully allocated buffers
 	 * to the userspace.
@@ -957,13 +957,13 @@  static int __create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create
 		 */
 	}
 
-	q->num_buffers += allocated_buffers;
-
 	if (ret < 0) {
 		__vb2_queue_free(q, allocated_buffers);
 		return -ENOMEM;
 	}
 
+	q->num_buffers += allocated_buffers;
+
 	/*
 	 * Return the number of successfully allocated buffers
 	 * to the userspace.