diff options
author | Hans Verkuil <hans.verkuil@cisco.com> | 2014-02-24 11:41:20 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <m.chehab@samsung.com> | 2014-03-11 05:56:41 -0400 |
commit | a7afcaccfab2fb012841852eaead79861dc9cb5f (patch) | |
tree | 48608d82c9e908484477fd3220435c54545712bd | |
parent | 6ea3b980f058d9dbc79ba88c652d581fa2d00792 (diff) |
[media] vb2: don't init the list if there are still buffers
__vb2_queue_free() would init the queued_list at all times, even if
q->num_buffers > 0. This should only happen if num_buffers == 0.
This situation can happen if a CREATE_BUFFERS call couldn't allocate
enough buffers and had to free those it did manage to allocate before
returning an error.
While we're at it: __vb2_queue_alloc() returns the number of buffers
allocated, not an error code. So stick the result in allocated_buffers
instead of ret as that's very confusing.
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
-rw-r--r-- | drivers/media/v4l2-core/videobuf2-core.c | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/drivers/media/v4l2-core/videobuf2-core.c b/drivers/media/v4l2-core/videobuf2-core.c index ef29a220c6e2..4e5004335309 100644 --- a/drivers/media/v4l2-core/videobuf2-core.c +++ b/drivers/media/v4l2-core/videobuf2-core.c | |||
@@ -456,9 +456,10 @@ static int __vb2_queue_free(struct vb2_queue *q, unsigned int buffers) | |||
456 | } | 456 | } |
457 | 457 | ||
458 | q->num_buffers -= buffers; | 458 | q->num_buffers -= buffers; |
459 | if (!q->num_buffers) | 459 | if (!q->num_buffers) { |
460 | q->memory = 0; | 460 | q->memory = 0; |
461 | INIT_LIST_HEAD(&q->queued_list); | 461 | INIT_LIST_HEAD(&q->queued_list); |
462 | } | ||
462 | return 0; | 463 | return 0; |
463 | } | 464 | } |
464 | 465 | ||
@@ -833,14 +834,12 @@ static int __reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req) | |||
833 | } | 834 | } |
834 | 835 | ||
835 | /* Finally, allocate buffers and video memory */ | 836 | /* Finally, allocate buffers and video memory */ |
836 | ret = __vb2_queue_alloc(q, req->memory, num_buffers, num_planes); | 837 | allocated_buffers = __vb2_queue_alloc(q, req->memory, num_buffers, num_planes); |
837 | if (ret == 0) { | 838 | if (allocated_buffers == 0) { |
838 | dprintk(1, "Memory allocation failed\n"); | 839 | dprintk(1, "Memory allocation failed\n"); |
839 | return -ENOMEM; | 840 | return -ENOMEM; |
840 | } | 841 | } |
841 | 842 | ||
842 | allocated_buffers = ret; | ||
843 | |||
844 | /* | 843 | /* |
845 | * Check if driver can handle the allocated number of buffers. | 844 | * Check if driver can handle the allocated number of buffers. |
846 | */ | 845 | */ |
@@ -864,6 +863,10 @@ static int __reqbufs(struct vb2_queue *q, struct v4l2_requestbuffers *req) | |||
864 | q->num_buffers = allocated_buffers; | 863 | q->num_buffers = allocated_buffers; |
865 | 864 | ||
866 | if (ret < 0) { | 865 | if (ret < 0) { |
866 | /* | ||
867 | * Note: __vb2_queue_free() will subtract 'allocated_buffers' | ||
868 | * from q->num_buffers. | ||
869 | */ | ||
867 | __vb2_queue_free(q, allocated_buffers); | 870 | __vb2_queue_free(q, allocated_buffers); |
868 | return ret; | 871 | return ret; |
869 | } | 872 | } |
@@ -937,20 +940,18 @@ static int __create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create | |||
937 | } | 940 | } |
938 | 941 | ||
939 | /* Finally, allocate buffers and video memory */ | 942 | /* Finally, allocate buffers and video memory */ |
940 | ret = __vb2_queue_alloc(q, create->memory, num_buffers, | 943 | allocated_buffers = __vb2_queue_alloc(q, create->memory, num_buffers, |
941 | num_planes); | 944 | num_planes); |
942 | if (ret == 0) { | 945 | if (allocated_buffers == 0) { |
943 | dprintk(1, "Memory allocation failed\n"); | 946 | dprintk(1, "Memory allocation failed\n"); |
944 | return -ENOMEM; | 947 | return -ENOMEM; |
945 | } | 948 | } |
946 | 949 | ||
947 | allocated_buffers = ret; | ||
948 | |||
949 | /* | 950 | /* |
950 | * Check if driver can handle the so far allocated number of buffers. | 951 | * Check if driver can handle the so far allocated number of buffers. |
951 | */ | 952 | */ |
952 | if (ret < num_buffers) { | 953 | if (allocated_buffers < num_buffers) { |
953 | num_buffers = ret; | 954 | num_buffers = allocated_buffers; |
954 | 955 | ||
955 | /* | 956 | /* |
956 | * q->num_buffers contains the total number of buffers, that the | 957 | * q->num_buffers contains the total number of buffers, that the |
@@ -973,6 +974,10 @@ static int __create_bufs(struct vb2_queue *q, struct v4l2_create_buffers *create | |||
973 | q->num_buffers += allocated_buffers; | 974 | q->num_buffers += allocated_buffers; |
974 | 975 | ||
975 | if (ret < 0) { | 976 | if (ret < 0) { |
977 | /* | ||
978 | * Note: __vb2_queue_free() will subtract 'allocated_buffers' | ||
979 | * from q->num_buffers. | ||
980 | */ | ||
976 | __vb2_queue_free(q, allocated_buffers); | 981 | __vb2_queue_free(q, allocated_buffers); |
977 | return -ENOMEM; | 982 | return -ENOMEM; |
978 | } | 983 | } |