vb2: fix buf_init/buf_cleanup call sequences
authorHans Verkuil <hans.verkuil@cisco.com>
Wed, 29 Jan 2014 16:36:53 +0000 (13:36 -0300)
committerChanho Park <chanho61.park@samsung.com>
Tue, 18 Nov 2014 02:59:49 +0000 (11:59 +0900)
commit333a97037dbfc49ab0502ffd893ab8c11549d7f6
tree7b44bae8235aa928c592c6c9ed808fc0625b087a
parent2572f186771928c89d51187effbab56e83344eeb
vb2: fix buf_init/buf_cleanup call sequences

Ensure that these ops are properly balanced.

There are two scenarios:

1) for MMAP buf_init is called when the buffers are created and buf_cleanup
   must be called when the queue is finally freed. This scenario was always
   working.

2) for USERPTR and DMABUF it is more complicated. When a buffer is queued
   the code checks if all planes of this buffer have been acquired before.
   If that's the case, then only buf_prepare has to be called. Otherwise
   buf_cleanup needs to be called if the buffer was acquired before, then,
   once all changed planes have been (re)acquired, buf_init has to be
   called followed by buf_prepare. Should buf_prepare fail, then buf_cleanup
   must be called on the newly acquired planes to release them in.

Finally, in __vb2_queue_free we have to check if the buffer was actually
acquired before calling buf_cleanup. While that it always true for MMAP
mode, it is not necessarily true for the other modes. E.g. if you just
call REQBUFS and close the file handle, then buffers were never queued and
so no buf_init was ever called.

Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
[Backport from upstream to support dmabuf memory]
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: I9a020bd5bca6376f70f3a9a85cce63ff0ff555ed
drivers/media/v4l2-core/videobuf2-core.c