James Hogan [Sat, 1 Mar 2014 22:52:25 +0000 (19:52 -0300)]
[media] rc-main: fix missing unlock if no devno left
While playing with make coccicheck I noticed this message:
drivers/media/rc/rc-main.c:1245:3-9: preceding lock on line 1238
It was introduced by commit 587d1b06e07b ([media] rc-core: reuse device
numbers) which returns -ENOMEM after a mutex_lock without first
unlocking it when there are no more device numbers left. The added code
doesn't depend on the device lock, so move it before the lock is taken.
Signed-off-by: James Hogan <james.hogan@imgtec.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Dan Carpenter [Sat, 1 Mar 2014 13:55:29 +0000 (10:55 -0300)]
[media] ddbridge: remove unneeded an NULL check
Static checkers complain about the inconsistent NULL check here.
There is an unchecked dereference of "input->fe" in the call to
tuner_attach_tda18271() and there is a second unchecked dereference a
couple lines later when we do:
input->fe2->tuner_priv = input->fe->tuner_priv;
But actually "intput->fe" can't be NULL because if demod_attach_drxk()
fails to allocate it, then we would have return an error code.
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Dan Carpenter [Sat, 1 Mar 2014 13:51:36 +0000 (10:51 -0300)]
[media] av7110_hw: fix a sanity check in av7110_fw_cmd()
ARRAY_SIZE(buf) (8 elements) was intended instead of sizeof(buf) (16
bytes). But this is just a sanity check and the callers always pass
valid values so this doesn't cause a problem.
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
James Hogan [Fri, 28 Feb 2014 23:28:54 +0000 (20:28 -0300)]
[media] rc: img-ir: add hardware decoder driver
Add remote control input driver for the ImgTec Infrared block hardware
decoder, which is set up with timings for a specific protocol and
supports mask/value filtering and wake events.
The hardware decoder timing values, raw data to scan code conversion
function and scan code filter to raw data filter conversion function
will be provided in separate files for each protocol which this part of
the driver can use. The new generic scan code filter interface is made
use of to reduce interrupts and control wake events.
Signed-off-by: James Hogan <james.hogan@imgtec.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
James Hogan [Fri, 28 Feb 2014 23:28:53 +0000 (20:28 -0300)]
[media] rc: img-ir: add raw driver
Add raw IR remote control input driver for the ImgTec Infrared decoder
block's raw edge interrupts. Generic software protocol decoders are used
to allow multiple protocols to be supported at a time, including those
not supported by the hardware decoder.
Signed-off-by: James Hogan <james.hogan@imgtec.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
James Hogan [Fri, 28 Feb 2014 23:28:52 +0000 (20:28 -0300)]
[media] rc: img-ir: add base driver
Add base driver for the ImgTec Infrared decoder block. The driver is
split into separate components for raw (software) decode and hardware
decoder which are in following commits.
Signed-off-by: James Hogan <james.hogan@imgtec.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
James Hogan [Fri, 28 Feb 2014 23:17:06 +0000 (20:17 -0300)]
[media] rc-main: automatically refresh filter on protocol change
When either of the normal or wakeup filter protocols are changed,
refresh the corresponding scancode filter, i.e. try and set the same
scancode filter with the new protocol. If that fails clear the filter
instead.
If no protocol was selected the filter is just cleared, and if no
s_filter callback exists the filter is left unmodified.
Similarly clear the filter mask when the filter is set if no protocol is
currently selected.
This simplifies driver code which no longer has to explicitly worry
about modifying the filter on a protocol change. This also allows the
change_wakeup_protocol callback to be omitted entirely if there is only
a single available wakeup protocol at a time, since selecting no
protocol will automatically clear the wakeup filter, disabling wakeup.
Signed-off-by: James Hogan <james.hogan@imgtec.com> Reviewed-by: Antti Seppälä <a.seppala@gmail.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
James Hogan [Fri, 28 Feb 2014 23:17:05 +0000 (20:17 -0300)]
[media] rc: add wakeup_protocols sysfs file
Add a wakeup_protocols sysfs file which controls the new
rc_dev::enabled_protocols[RC_FILTER_WAKEUP], which is the mask of
protocols that are used for the wakeup filter.
A new RC driver callback change_wakeup_protocol() is called to change
the wakeup protocol mask.
Signed-off-by: James Hogan <james.hogan@imgtec.com> Reviewed-by: Antti Seppälä <a.seppala@gmail.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Only a single allowed and enabled protocol mask currently exists in
struct rc_dev, however to support a separate wakeup filter protocol two
of each are needed, ideally as an array.
Therefore make both rc_dev::allowed_protos and rc_dev::enabled_protocols
arrays, update all users to reference the first element
(RC_FILTER_NORMAL), and add a couple more helper functions for drivers
to use for setting the allowed and enabled wakeup protocols.
We also rename allowed_protos to allowed_protocols while we're at it,
which is more consistent with enabled_protocols.
Signed-off-by: James Hogan <james.hogan@imgtec.com> Reviewed-by: Antti Seppälä <a.seppala@gmail.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
James Hogan [Fri, 28 Feb 2014 23:17:03 +0000 (20:17 -0300)]
[media] rc: abstract access to allowed/enabled protocols
The allowed and enabled protocol masks need to be expanded to be per
filter type in order to support wakeup filter protocol selection. To
ease that process abstract access to the rc_dev::allowed_protos and
rc_dev::enabled_protocols members with inline functions.
Signed-off-by: James Hogan <james.hogan@imgtec.com> Reviewed-by: Antti Seppälä <a.seppala@gmail.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
James Hogan [Fri, 28 Feb 2014 23:17:02 +0000 (20:17 -0300)]
[media] rc-main: add generic scancode filtering
Add generic scancode filtering of RC input events, and fall back to
permitting any RC_FILTER_NORMAL scancode filter to be set if no s_filter
callback exists. This allows raw IR decoder events to be filtered, and
potentially allows hardware decoders to set looser filters and rely on
generic code to filter out the corner cases.
Signed-off-by: James Hogan <james.hogan@imgtec.com> Reviewed-by: Antti Seppälä <a.seppala@gmail.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Antti Seppälä [Sun, 16 Feb 2014 10:16:02 +0000 (07:16 -0300)]
[media] nuvoton-cir: Activate PNP device when probing
On certain motherboards (mainly Intel NUC series) bios keeps the
Nuvoton CIR device disabled at boot.
This patch adds a call to kernel PNP layer to activate the device if it
is not already activated. This will improve the chances of the PNP probe
actually succeeding on Intel NUC platforms.
Signed-off-by: Antti Seppälä <a.seppala@gmail.com> Cc: Jarod Wilson <jarod@redhat.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Joonyoung Shim [Tue, 11 Feb 2014 01:54:34 +0000 (22:54 -0300)]
[media] au0828: fix i2c clock speed for DViCO FusionHDTV7
DViCO FusionHDTV7 device that use au0828 can fail to communicate with
xc5000 using i2c interface because of high i2c clock speed - i2c clock
stretching bug. It causes to fail xc5000 firmware loading normally at
the current driver.
Already this problem fixed as changing to low i2c clock speed at
HVR-950q device, also DViCO FusionHDTV7 device can solve it as using low
i2c clock speed - 20KHz.
James Hogan [Mon, 10 Feb 2014 21:31:56 +0000 (18:31 -0300)]
[media] rc-main: store_filter: pass errors to userland
Propagate errors returned by drivers from the s_filter callback back to
userland when updating scancode filters. This allows userland to see
when the filter couldn't be updated, usually because it's not a valid
filter for the hardware.
Previously the filter was being updated conditionally on success of
s_filter, but the write always reported success back to userland.
Reported-by: Antti Seppälä <a.seppala@gmail.com> Signed-off-by: James Hogan <james.hogan@imgtec.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Since the introduction of the new OMAP DSS DVI connector driver in
commit 348077b154357eec595068a3336ef6beb870e6f3 ("OMAPDSS: Add new DVI
Connector driver"), DVI outputs report a new display type of
OMAP_DISPLAY_TYPE_DVI instead of OMAP_DISPLAY_TYPE_DPI. Handle the new
type in the IRQ handler.
Hans Verkuil [Mon, 10 Mar 2014 13:58:29 +0000 (10:58 -0300)]
[media] mem2mem_testdev: improve field handling
try_fmt should just set field to NONE and not return an error if
a different field was passed.
buf_prepare should check if the field passed in from userspace has a
supported field value. At the moment only NONE is supported and ANY
is mapped to NONE.
The adv7180 has a low power mode in which the analog and the digital processing
section are shut down. Implement the s_power callback to let bridge drivers put
the part into low power mode when not needed.
Hans Verkuil [Fri, 7 Mar 2014 14:17:33 +0000 (11:17 -0300)]
[media] DocBook v4l2: update the G/S_EDID documentation
Document that it is now possible to call G/S_EDID from video nodes, not
just sub-device nodes. Add a note that -EINVAL will be returned if
the pad does not support EDIDs.
Hans Verkuil [Tue, 4 Mar 2014 10:46:47 +0000 (07:46 -0300)]
[media] v4l2: allow v4l2_subdev_edid to be used with video nodes
Struct v4l2_subdev_edid and the VIDIOC_SUBDEV_G/S_EDID ioctls were
specific for subdevices, but for hardware with a simple video pipeline
you do not need/want to create subdevice nodes to just get/set the EDID.
Move the v4l2_subdev_edid struct to v4l2-common.h and rename as
v4l2_edid. Add the same ioctls to videodev2.h as well, thus allowing
this API to be used with both video nodes and v4l-subdev nodes.
Hans Verkuil [Thu, 6 Mar 2014 10:24:21 +0000 (07:24 -0300)]
[media] v4l2-compat-ioctl32: fix wrong VIDIOC_SUBDEV_G/S_EDID32 support
The wrong ioctl numbers were used due to a copy-and-paste error.
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Cc: stable@vger.kernel.org # for v3.7 and up Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Daniel Jeong [Mon, 3 Mar 2014 09:52:10 +0000 (06:52 -0300)]
[media] lm3646: add new dual LED Flash driver
This patch adds the driver for the LM3646, dual LED Flash driver.
The LM3646 has two 1.5A sync. boost converter with dual white current source.
It is controlled via an I2C compatible interface.
Each flash brightness, torch brightness and enable/disable can be controlled.
Under voltage, input voltage monitor and thermal threshhold Faults are added.
Please refer the datasheet http://www.ti.com/lit/ds/snvs962/snvs962.pdf
Signed-off-by: Daniel Jeong <gshark.jeong@gmail.com> Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Three Flash fault are added. V4L2_FLASH_FAULT_UNDER_VOLTAGE for the case low
voltage below the min. limit. V4L2_FLASH_FAULT_INPUT_VOLTAGE for the case
falling input voltage and chip adjust flash current not occur under voltage
event. V4L2_FLASH_FAULT_LED_OVER_TEMPERATURE for the case the temperature
exceed the maximun limit
Signed-off-by: Daniel Jeong <gshark.jeong@gmail.com> Signed-off-by: Sakari Ailus <sakari.ailus@iki.fi> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Laurent Pinchart [Mon, 10 Mar 2014 23:15:12 +0000 (20:15 -0300)]
[media] v4l: of: Support empty port nodes
Empty port nodes are allowed but currently unsupported as the
v4l2_of_get_next_endpoint() function assumes that all port nodes have at
least an endpoint. Fix this.
[media] MAINTAINERS: remove myself as a maintainer of VEU and VOU V4L2 drivers
Since I'm currently unable to dedicate sufficient time to the maintainership
of these two drivers update their status to "orphan" until new maintainers
appear.
Signed-off-by: Dean Anderson <linux-dev@sensoray.com> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Arnd Bergmann [Wed, 26 Feb 2014 11:01:48 +0000 (08:01 -0300)]
[media] arv: fix sleep_on race
interruptible_sleep_on is racy and going away. In the arv driver that
race has probably never caused problems since it would require a whole
video frame to be captured before the read function has a chance to
go to sleep, but using wait_event_interruptible lets us kill off the
old interface. In order to do this, we have to slightly adapt the
meaning of the ar->start_capture field to distinguish between not having
started a frame and having completed it.
[media] v4l: VIDEO_SH_VOU should depend on HAS_DMA
If NO_DMA=y:
warning: (VIDEO_DM6446_CCDC && VIDEO_DM355_CCDC && VIDEO_DM365_ISIF && VIDEO_OMAP2_VOUT && VIDEO_SH_VOU && VIDEO_VIU && VIDEO_TIMBERDALE && VIDEO_MX1 && VIDEO_OMAP1) selects VIDEOBUF_DMA_CONTIG which has unmet direct dependencies (MEDIA_SUPPORT && HAS_DMA)
drivers/built-in.o: In function `videobuf_vm_close':
videobuf-dma-contig.c:(.text+0x407aa0): undefined reference to `videobuf_queue_cancel'
drivers/built-in.o: In function `__videobuf_dc_alloc':
videobuf-dma-contig.c:(.text+0x407ba2): undefined reference to `dma_alloc_coherent'
drivers/built-in.o: In function `__videobuf_mmap_mapper':
videobuf-dma-contig.c:(.text+0x407d44): undefined reference to `dma_free_coherent'
drivers/built-in.o: In function `free_buffer':
sh_vou.c:(.text+0x41f73a): undefined reference to `videobuf_waiton'
drivers/built-in.o: In function `sh_vou_poll':
sh_vou.c:(.text+0x41f884): undefined reference to `videobuf_poll_stream'
drivers/built-in.o: In function `sh_vou_buf_prepare':
sh_vou.c:(.text+0x41fdf6): undefined reference to `videobuf_iolock'
drivers/built-in.o: In function `sh_vou_reqbufs':
sh_vou.c:(.text+0x4203b0): undefined reference to `videobuf_reqbufs'
drivers/built-in.o: In function `sh_vou_querybuf':
sh_vou.c:(.text+0x42040a): undefined reference to `videobuf_querybuf'
drivers/built-in.o: In function `sh_vou_qbuf':
sh_vou.c:(.text+0x42045e): undefined reference to `videobuf_qbuf'
drivers/built-in.o: In function `sh_vou_dqbuf':
sh_vou.c:(.text+0x4204c2): undefined reference to `videobuf_dqbuf'
drivers/built-in.o: In function `sh_vou_streamon':
sh_vou.c:(.text+0x420572): undefined reference to `videobuf_streamon'
drivers/built-in.o: In function `sh_vou_streamoff':
sh_vou.c:(.text+0x4205d2): undefined reference to `videobuf_streamoff'
drivers/built-in.o: In function `sh_vou_mmap':
sh_vou.c:(.text+0x420c46): undefined reference to `videobuf_mmap_mapper'
VIDEO_SH_VOU selects VIDEOBUF_DMA_CONTIG, which bypasses its dependency on
HAS_DMA. Make VIDEO_SH_VOU depend on HAS_DMA to fix this.
>> drivers/media/usb/usbtv/usbtv-core.c:119:22: sparse: symbol 'usbtv_id_table' was not declared. Should it be static?
>> drivers/media/usb/usbtv/usbtv-core.c:129:19: sparse: symbol 'usbtv_usb_driver' was not declared. Should it be static?
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
drivers/media/dvb-frontends/drx39xyj/drxj.c: In function 'ctrl_get_qam_sig_quality':
drivers/media/dvb-frontends/drx39xyj/drxj.c:9468:6: warning: variable 'ber_cnt' set but not used [-Wunused-but-set-variable]
u32 ber_cnt = 0; /* BER count */
^
By reading the comment, it is said that BER should be calculated as:
qam_pre_rs_ber = frac_times1e6( ber_cnt, rs_bit_cnt );
Also, it makes sense to take the mantissa into account, so fix the
code to do what's commented.
[media] drx-j: properly handle bit counts on stats
Instead of just assuming that the min resolution is 1E-6,
pass both bit error and bit counts for userspace to calculate
BER. The same applies for PER, for 8VSB. It is not clear how
to get the packet count for QAM. So, for now, don't expose PER
for QAM.
drivers/media/dvb-frontends/drx39xyj/drxj.c: In function ‘ctrl_set_channel’:
drivers/media/dvb-frontends/drx39xyj/drxj.c:10340:26: warning: variable ‘common_attr’ set but not used [-Wunused-but-set-variable]
struct drx_common_attr *common_attr = NULL;
^
drivers/media/dvb-frontends/drx39xyj/drxj.c:10336:6: warning: variable ‘intermediate_freq’ set but not used [-Wunused-but-set-variable]
s32 intermediate_freq = 0;
[media] drx-j: propagate returned error from request_firmware()
Fix a smatch warning:
drivers/media/dvb-frontends/drx39xyj/drxj.c:11711 drx_ctrl_u_code() info: why not propagate 'rc' from request_firmware() instead of (-2)?
This function is currently not used. However, it was meant to
be called at device release. So, add it there.
While here, remove the bad check, as reported by Dan, as
smatch warning:
drivers/media/dvb-frontends/drx39xyj/drxj.c:20041 drxj_close() warn: variable dereferenced before check 'demod' (see line 20036)
Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
There are large chunks of code at drx-j that aren't used. Most
of them are due to analog TV support. Well, just enabling them
won't make analog support work, as devices with DRX and analog
support requires an extra chip (avf4910).
We don't have drivers for it, nor the current device that uses
this frontend has support for analog TV.
So, let's just get rid of this code. If latter needed, this
patch can easily be reverted from git history.
[media] drx-j: don't use mc_info before checking if its not NULL
smatch warning:
drivers/media/dvb-frontends/drx39xyj/drxj.c:20803 drx_ctrl_u_code() warn: variable dereferenced before check 'mc_info' (see line 20800)
Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
[media] drx-j: Fix dubious usage of "&" instead of "&&"
Fixes the following warnings:
drivers/media/dvb-frontends/drx39xyj/drxj.c:16764:68: warning: dubious: x & !y
drivers/media/dvb-frontends/drx39xyj/drxj.c:16778:68: warning: dubious: x & !y
drivers/media/dvb-frontends/drx39xyj/drxj.c:16797:68: warning: dubious: x & !y
Fixes the following warnings:
drivers/media/dvb-frontends/drx39xyj/drxj.c:1679:65: warning: Using plain integer as NULL pointer
drivers/media/dvb-frontends/drx39xyj/drxj.c:1679:71: warning: Using plain integer as NULL pointer
drivers/media/dvb-frontends/drx39xyj/drxj.c:1681:52: warning: Using plain integer as NULL pointer
drivers/media/dvb-frontends/drx39xyj/drxj.c:1681:58: warning: Using plain integer as NULL pointer
Fengguang Wu [Sun, 9 Mar 2014 12:08:30 +0000 (09:08 -0300)]
[media] drx-j: drxj_default_aud_data_g can be static
Fix sparse warning:
drivers/media/dvb-frontends/drx39xyj/drxj.c:1039:16: sparse: symbol 'drxj_default_aud_data_g' was not declared. Should it be static?
[media] em28xx-dvb: remove one level of identation at fini callback
Simplify the logic a little by removing one level of identation.
Also, it only makes sense to print something if the .fini callback
is actually doing something.
Reviewed-by: Frank Schäfer <fschaefer.oss@googlemail.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Hans Verkuil [Tue, 25 Feb 2014 12:42:45 +0000 (09:42 -0300)]
[media] vb2: fix streamoff handling if streamon wasn't called
If you request buffers, then queue buffers and then call STREAMOFF
those buffers are not returned to their dequeued state because streamoff
will just return if q->streaming was 0.
This means that afterwards you can never QBUF that same buffer again unless
you do STREAMON, REQBUFS or close the filehandle first.
It is clear that if you do STREAMOFF even if no STREAMON was called before,
you still want to have all buffers returned to their proper dequeued state.
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Hans Verkuil [Fri, 28 Feb 2014 15:49:18 +0000 (12:49 -0300)]
[media] vb2: properly clean up PREPARED and QUEUED buffers
If __reqbufs was called then existing buffers are freed. However, if that
happens without ever having started STREAMON, but if buffers have been queued,
then the buf_finish op is never called.
Add a call to __vb2_queue_cancel in __reqbufs so that these buffers are
cleaned up there as well.
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Hans Verkuil [Mon, 24 Feb 2014 16:51:03 +0000 (13:51 -0300)]
[media] vb2: only call start_streaming if sufficient buffers are queued
In commit 02f142ecd24aaf891324ffba8527284c1731b561 support was added to
start_streaming to return -ENOBUFS if insufficient buffers were queued
for the DMA engine to start. The vb2 core would attempt calling
start_streaming again if another buffer would be queued up.
Later analysis uncovered problems with the queue management if start_streaming
would return an error: the buffers are enqueued to the driver before the
start_streaming op is called, so after an error they are never returned to
the vb2 core. The solution for this is to let the driver return them to
the vb2 core in case of an error while starting the DMA engine. However,
in the case of -ENOBUFS that would be weird: it is not a real error, it
just says that more buffers are needed. Requiring start_streaming to give
them back only to have them requeued again the next time the application
calls QBUF is inefficient.
This patch changes this mechanism: it adds a 'min_buffers_needed' field
to vb2_queue that drivers can set with the minimum number of buffers
required to start the DMA engine. The start_streaming op is only called
if enough buffers are queued. The -ENOBUFS handling has been dropped in
favor of this new method.
Drivers are expected to return buffers back to vb2 core with state QUEUED
if start_streaming would return an error. The vb2 core checks for this
and produces a warning if that didn't happen and it will forcefully
reclaim such buffers to ensure that the internal vb2 core state remains
consistent and all buffer-related resources have been correctly freed
and all op calls have been balanced.
__reqbufs() has been updated to check that at least min_buffers_needed
buffers could be allocated. If fewer buffers were allocated then __reqbufs
will free what was allocated and return -ENOMEM. Based on a suggestion from
Pawel Osciak.
__create_bufs() doesn't do that check, since the use of __create_bufs
assumes some advance scenario where the user might want more control.
Instead streamon will check if enough buffers were allocated to prevent
streaming with fewer than the minimum required number of buffers.
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Hans Verkuil [Mon, 24 Feb 2014 16:41:20 +0000 (13:41 -0300)]
[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.
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>