[linux-3.16-rc5/drivers/staging/media/davinci_vpfe/dm365_ipipeif.c:210]:
(style) Checking if unsigned variable 'val' is less than zero.
val = get_oneshot_mode(ipipeif->input);
if (val < 0) {
pr_err("ipipeif: links setup required");
return -EINVAL;
}
but
static int get_oneshot_mode(enum ipipeif_input_entity input)
Introduced temporary variable for negativity check.
"val" is afterwards used in a lot of bitwise operations, so changing its type
to signed is not safe, according to CERT C Secure Coding Standards chapter
INT13-C: "Use bitwise operators only on unsigned operands"
https://www.securecoding.cert.org/confluence/display/seccode/INT13-C.+Use+bitwise+operators+only+on+unsigned+operands
Philipp Zabel [Fri, 11 Jul 2014 09:36:16 +0000 (06:36 -0300)]
[media] coda: simplify IRAM setup
OVL and BTP IRAM buffers are never used, setup the bits for
for DBK/BIT/IP usage depending on CODA version in one place.
Also, use a simple allocator function and group IRAM addresses
and size in a coda_aux_buf structure.
This is done in preparation for CODA960 support.
Philipp Zabel [Fri, 11 Jul 2014 09:36:14 +0000 (06:36 -0300)]
[media] coda: fix h.264 quantization parameter range
If bitrate is not set, the encoder is running in VBR mode, with the
I- and P-frame quantization parameters configured from userspace.
For the quantization parameters, 0 is a valid value.
Philipp Zabel [Fri, 11 Jul 2014 09:36:12 +0000 (06:36 -0300)]
[media] coda: fix decoder I/P/B frame detection
Currently the rotator unit is used to copy decoded frames out into buffers
provided by videobuf2. Since the CODA reports the I/P/B frame type of the
last decoded frame, and this frame will be copied out in a later device_run,
depending on display order, we have to store the frame type until such time.
This patch also adds the B-frame type.
Jacek Anaszewski [Thu, 10 Jul 2014 09:00:39 +0000 (06:00 -0300)]
[media] s5p-mfc: Fix selective sclk_mfc init
fc906b6d "Remove special clock usage in driver" removed
initialization of MFC special clock, arguing that there's
no need to do it explicitly, since it's one of MFC gate clock's
dependencies and gets enabled along with it. However, there's
no promise of keeping this hierarchy across Exynos SoC
releases, therefore this approach fails to provide a stable,
portable solution.
Out of all MFC versions, only v6 doesn't use special clock at all.
For other versions log a message only in case clk_get fails,
as not all the devices with the same MFC version require
initializing the clock explicitly.
Signed-off-by: Mateusz Zalega <m.zalega@samsung.com> Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com> Signed-off-by: Jacek Anaszewski <j.anaszewski@samsung.com> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com> Signed-off-by: Kamil Debski <k.debski@samsung.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
This patch removes the null test on dvb. dvb is initialized at the
beginning of the function to &port->dvb. Since port is dereferenced
prior to the null test, port must be a valid pointer, and
&port->dvb cannot be null.
The following Coccinelle script is used for detecting the change:
WARNING: Missing a blank line after declarations
2245: FILE: radio-bcm2048.c:2245:
+ unsigned char tmpbuf[3];
+ tmpbuf[i] = bdev->rds_info.radio_text[bdev->rd_index+i+2];
WARNING: Possible unnecessary 'out of memory' message
2601: FILE: radio-bcm2048.c:2601:
+ if (!bdev) {
+ dev_dbg(&client->dev, "Failed to alloc video device.\n");
The following error was left since it seems to be a false positive:
ERROR: Macros with complex values should be enclosed in parenthesis
+#define DEFINE_SYSFS_PROPERTY(prop, signal, size, mask, check) \
+property_write(prop, signal size, mask, check) \
+property_read(prop, size, mask)
Signed-off-by: Luke Hart <luke.hart@birchleys.eu> Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
The issue was discovered by static analysis. It turns out that code is
somewhat insane, being
if (x) {...} else { if (x) {...} }
Edited it to do the only reasonable thing, which is to log the
information about the failed call. The most descriptive logging commands
set is taken from original code.
Hans Verkuil [Fri, 13 Jun 2014 07:31:06 +0000 (04:31 -0300)]
[media] v4l2-ioctl: call g_selection before calling cropcap
If the vidioc_cropcap op is implemented by the driver then the v4l2
core will call that directly.
If g_selection is available, then the core cropcap implementation
uses g_selection to fill in the bounds and defrect and it sets the
pixelaspect to 1x1.
But if both are available, then I would like to use g_selection to
fill in defrect and bounds before calling cropcap. That way the
driver's cropcap implementation doesn't have to set defrect or
bounds.
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Hans Verkuil [Thu, 10 Jul 2014 22:51:26 +0000 (19:51 -0300)]
[media] v4l2-dev: streamon/off is only a valid ioctl for video, vbi and sdr
The VIDIOC_STREAMON/OFF ioctls are not valid for radio devices, just
like the other streaming I/O ioctls. Add the streamon/off ioctls
to the other streaming I/O ioctls.
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
If the driver supports enum_freq_bands, but only for certain device
nodes, then it may return -ENOTTY. But in that case the code should
fall into the fall-back case where the current tuner/modulator range
is returned.
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Hans Verkuil [Sat, 12 Jul 2014 10:54:26 +0000 (07:54 -0300)]
[media] v4l2-ioctl.c: check vfl_type in ENUM_FMT
The other format ioctls (g/s/try_fmt) all check if the passed buffer type
makes sense for the device node's vfl_type. E.g. it makes no sense for a
VBI buffer type to be passed through a video node instead of a vbi node.
But this check was missing in ENUM_FMT which can cause a problem if you
have both video and sdr device nodes.
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
[media] v4l: omap4iss: Signal fatal errors to the vb2 queue
When a fatal error occurs in the pipeline signal it to the vb2 queue
with a call to vb2_queue_error(). The queue will then take care to
return -EIO when preparing buffers, remove the driver-specific code that
now duplicates that check.
The OMAP4 camera support depends on I2C and VIDEO_V4L2, both
of which can be loadable modules. This causes build failures
if we want the camera driver to be built-in.
This can be solved by turning the option into "tristate",
which unfortunately causes another problem, because the
driver incorrectly calls a platform-internal interface
for omap4_ctrl_pad_readl/omap4_ctrl_pad_writel.
Instead, this patch just forbids the invalid configurations
and ensures that the driver can only be built if all its
dependencies are built-in.
When a fatal error occurs that render the device unusable, the only
options for a driver to signal the error condition to userspace is to
set the V4L2_BUF_FLAG_ERROR flag when dequeuing buffers and to return an
error from the buffer prepare handler when queuing buffers.
The buffer error flag indicates a transient error and can't be used by
applications to detect fatal errors. Returning an error from vb2_qbuf()
is thus the only real indication that a fatal error occurred. However,
this is difficult to handle for multithreaded applications that requeue
buffers from a thread other than the control thread. In particular the
poll() call in the control thread will not notify userspace of the
error.
This patch adds an explicit mechanism to report fatal errors to
userspace. Drivers can call the vb2_queue_error() function to signal a
fatal error. From this moment on, buffer preparation will return -EIO to
userspace, and vb2_poll() will set the POLLERR flag and return
immediately. The error flag is cleared when cancelling the queue, either
at stream off time (through vb2_streamoff) or when releasing the queue
with vb2_queue_release().
[media] v4l: vb2: Don't return POLLERR during transient buffer underruns
The V4L2 specification states that
"When the application did not call VIDIOC_QBUF or VIDIOC_STREAMON yet
the poll() function succeeds, but sets the POLLERR flag in the revents
field."
The vb2_poll() function sets POLLERR when the queued buffers list is
empty, regardless of whether this is caused by the stream not being
active yet, or by a transient buffer underrun.
Bring the implementation in line with the specification by returning
POLLERR if no buffer has been queued only when the queue is not
streaming. Buffer underruns during streaming are not treated specially
anymore and just result in poll() blocking until the next event.
Laurent Pinchart [Sat, 31 May 2014 00:45:48 +0000 (21:45 -0300)]
[media] v4l: vsp1: uds: Fix scaling of alpha layer
Pixel color components can be scaled using either bilinear interpolation
or a multitap filter. The multitap filter provides better results, but
can't be selected when the alpha layer need to be scaled down by more
than 1/2.
Disable alpha scaling when the input has a fixed alpha value, and
program the UDS to output a fixed alpha value in that case. This ensures
the multitap filter will be used whenever possible.
Laurent Pinchart [Tue, 27 May 2014 23:35:36 +0000 (20:35 -0300)]
[media] v4l: vsp1: bru: Support premultiplied alpha at the BRU inputs
Adjust the BRU blending formula to avoid the multiplication by alpha
when the corresponding input format is premultiplied. As this requires
access to the RPFs connected to the BRU inputs from the BRU module,
store pointers to the RPFs in the BRU structure when validating the
pipeline.
Laurent Pinchart [Mon, 26 May 2014 22:57:21 +0000 (19:57 -0300)]
[media] v4l: vsp1: Switch to XRGB formats
The driver ignores the alpha component on output video nodes and
hardcodes the alpha component to 0 on capture video nodes. Make this
explicit by exposing XRGB formats.
Compatibility with existing userspace applications is handled by
selecting the XRGB format corresponding to the requested old RGB format.
Laurent Pinchart [Wed, 28 May 2014 16:10:33 +0000 (13:10 -0300)]
[media] v4l: vsp1: wpf: Clear RPF to WPF association at stream off time
The VSP1 stores the video pipelines' input (RPF) to output (WPF)
mappings in a WPF register. An RPF must never be associated with
multiple WPFs, even if all of those WPFs but one are unused, otherwise
the hardware won't function properly.
The driver doesn't ensure this correctly as it never clears the
mappings. An RPF used with one WPF and later with a different WPF will
lead to malfunction, as it will be associated with two WPFs. Clear the
mappings at stream off time to fix this.
Laurent Pinchart [Sat, 31 May 2014 23:30:11 +0000 (20:30 -0300)]
[media] v4l: vsp1: sru: Make the intensity controllable during streaming
The control value is currently stored in the SRU structure by the
control set handler and written to the hardware at stream on time,
making control set during streaming ineffective. Fix it by writing to
the registers from within the control set handler.
Laurent Pinchart [Sat, 31 May 2014 13:40:51 +0000 (10:40 -0300)]
[media] v4l: vsp1: Setup control handler automatically at stream on time
When setting a control directly on a subdev node the VSP1 driver doesn't
guarantee that the device is powered on. This leads to crashes when the
control handlers writes to hardware registers. One easy way to fix this
is to ensure that the device gets powered on when a subdev node is
opened. However, this consumes power unnecessarily, as there's no need
to power the device on when setting formats on the pipeline.
Furthermore, control handler setup at entity init time suffers from the
same problem as the device isn't powered on easier.
Fix this by extend the entity base object to setup the control handler
automatically when starting the stream. Entities must then skip writing
to registers in the set control handler when not streaming, which can be
tested with the new vsp1_entity_is_streaming() helper function.
Laurent Pinchart [Wed, 28 May 2014 15:49:13 +0000 (12:49 -0300)]
[media] v4l: vsp1: Cleanup video nodes at removal time
Video nodes created and initialized in the RPF and WPF init code paths
are never unregistered, and the related resources (videobuf alloc
context and media entity) never released.
Fix this by storing a pointer to the vsp1_video object in vsp1_entity
and calling vsp1_video_cleanup() from vsp1_entity_destroy(). This also
allows simplifying the init error code paths.
Laurent Pinchart [Mon, 23 Jun 2014 20:15:02 +0000 (17:15 -0300)]
[media] v4l: vsp1: Fix pipeline stop timeout
If the pipeline was already stopped when stopping the stream, no
frame end interrupt will be generated and the driver will time out
waiting for the pipeline to stop.
Fix this by setting the pipeline state to STOPPED when the pipeline is
idle waiting for frames to process, and to STOPPING at stream stop time
only when the pipeline is currently RUNNING.
Laurent Pinchart [Mon, 23 Jun 2014 19:57:22 +0000 (16:57 -0300)]
[media] v4l: vsp1: Release buffers at stream stop
videobuf2 expects no buffer to be owned by the driver when the
stop_stream queue operation returns. As the vsp1 driver fails to do so,
a warning is generated at stream top time.
Fix this by releasing all buffers queued on the IRQ queue in the
stop_stream operation handler and marking them as erroneous.
Laurent Pinchart [Mon, 23 Jun 2014 21:40:49 +0000 (18:40 -0300)]
[media] v4l: vsp1: Fix routing cleanup when stopping the stream
Commit d9b45ed3d8b75e8cf38c8cd1563c29217eecba27 ("v4l: vsp1: Support
multi-input entities") reworked pipeline routing configuration and
introduced a bug by writing to the entities routing registers without
first checking whether the entity had a routing register. This results
in overwriting the value at offset 0 of the device register space when
stopping the stream.
Fix this by skipping routing register write for entities without a
routing register.
Laurent Pinchart [Mon, 23 Jun 2014 21:00:22 +0000 (18:00 -0300)]
[media] v4l: vb2: Fix stream start and buffer completion race
videobuf2 stores the driver streaming state internally in the queue in
the start_streaming_called variable. The state is set right after the
driver start_stream operation returns, and checked in the
vb2_buffer_done() function, typically called from the frame completion
interrupt handler. A race condition exists if the hardware finishes
processing the first frame before the start_stream operation returns.
Fix this by setting start_streaming_called to 1 before calling the
start_stream operation, and resetting it to 0 if the operation fails.
Cc: stable@vger.kernel.org # for v3.15 and up Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com> Reviewed-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Laurent Pinchart [Tue, 27 May 2014 12:41:05 +0000 (09:41 -0300)]
[media] v4l: Support extending the v4l2_pix_format structure
The v4l2_pix_format structure has no reserved field. It is embedded in
the v4l2_framebuffer structure which has no reserved fields either, and
in the v4l2_format structure which has reserved fields that were not
previously required to be zeroed out by applications.
To allow extending v4l2_pix_format, inline it in the v4l2_framebuffer
structure, and use the priv field as a magic value to indicate that the
application has set all v4l2_pix_format extended fields and zeroed all
reserved fields following the v4l2_pix_format field in the v4l2_format
structure.
The availability of this API extension is reported to userspace through
the new V4L2_CAP_EXT_PIX_FORMAT capability flag. Just checking that the
priv field is still set to the magic value at [GS]_FMT return wouldn't
be enough, as older kernels don't zero the priv field on return.
To simplify the internal API towards drivers zero the extended fields
and set the priv field to the magic value for applications not aware of
the extensions.
Laurent Pinchart [Wed, 21 May 2014 22:16:01 +0000 (19:16 -0300)]
[media] DocBook: media: Document ALPHA_COMPONENT control usage on output devices
Extend the V4L2_CID_ALPHA_COMPONENT control for use on output devices,
to set the alpha component value when the output format doesn't have an
alpha channel.
Laurent Pinchart [Thu, 22 May 2014 01:07:55 +0000 (22:07 -0300)]
[media] v4l: Add ARGB and XRGB pixel formats
The existing RGB pixel formats are ill-defined in respect to their alpha
bits and their meaning is driver dependent. Create new standard ARGB and
XRGB variants with clearly defined meanings and make the existing
variants deprecated.
The new pixel formats 4CC values have been selected to match the DRM
4CCs for the same in-memory formats.
Hans Verkuil [Thu, 17 Jul 2014 15:31:23 +0000 (12:31 -0300)]
[media] Fix 64-bit division fall-out from 64-bit control ranges
Commit 0ba2aeb6dab80920edd9cf5b93b1ea4d6913b8f3 increased the internal control ranges
to 64 bit, but that caused problems in drivers that use the minimum/maximum/step/default_value
control values in a division or modulus operations since not all architectures support
those natively.
Luckily, in almost all cases it is possible to just cast to 32 bits (the control value
is known to be 32 bits, so it is safe to cast). Only in v4l2-ctrls.c was it necessary to
use do_div in one function.
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Hans Verkuil [Tue, 10 Jun 2014 10:39:04 +0000 (07:39 -0300)]
[media] go7007: add motion detection support
This patch adds motion detection support to the go7007 driver using the new
motion detection controls, events.
The global motion detection works fine, but the regional motion detection
support probably needs more work. There seems to be some interaction between
regions that makes setting correct thresholds difficult. The exact meaning of
the thresholds isn't entirely clear either.
I do not have any documentation, the only information I have is the custom code
in the driver and a modet.c application.
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Hans Verkuil [Mon, 5 May 2014 13:16:49 +0000 (10:16 -0300)]
[media] DocBook media: improve control section
Improve the control section:
- Clarify the handling of private controls
- Explain the V4L2_CTRL_FLAG_INACTIVE flag
- Remove obsolete text regarding missing control event (we have them
today) and the incorrect V4L2_CTRL_FLAG_DISABLED reference.
- Add a code example on how to enumerate over user controls.
Hans Verkuil [Sat, 18 Jan 2014 09:06:01 +0000 (06:06 -0300)]
[media] v4l2-ctrls: return elem_size instead of strlen
When getting a string and the size given by the application is too
short return the max length the string can have (elem_size) instead
of the string length + 1. That makes more sense.
Hans Verkuil [Fri, 17 Jan 2014 11:25:26 +0000 (08:25 -0300)]
[media] v4l2-ctrls: compare values only once
When setting a control the control's new value is compared to the current
value twice: once by new_to_cur(), once by cluster_changed(). Not a big
deal when dealing with simple values, but it can be a problem when dealing
with compound types or arrays. So fix this: cluster_changed() sets the
has_changed flag, which is used by new_to_cur() instead of having to do
another compare.
Hans Verkuil [Sun, 27 Apr 2014 06:26:30 +0000 (03:26 -0300)]
[media] v4l2-ctrls: rewrite copy routines to operate on union v4l2_ctrl_ptr
In order to implement array support and (for the future) configuration stores
we need to have more generic copy routines that all operate on the v4l2_ctrl_ptr
union. So instead of e.g. using ctrl->cur.string it uses ptr.p_char. This makes
e.g. cur_to_user generic so it can be used to copy any v4l2_ctrl_ptr value to
userspace, not just the (hardcoded) current value.
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Hans Verkuil [Sun, 27 Apr 2014 06:22:17 +0000 (03:22 -0300)]
[media] v4l2-ctrls: create type_ops
Since compound controls can have non-standard types we need to be able to do
type-specific checks etc. In order to make that easy type operations are added.
There are four operations:
- equal: check if two values are equal
- init: initialize a value
- log: log the value
- validate: validate a new value
The v4l2_ctrl struct adds p_new and p_cur unions at the end of the struct.
This union provides a standard way of accessing control types through a pointer,
which greatly simplifies internal control processing.
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Hans Verkuil [Thu, 12 Jun 2014 10:54:16 +0000 (07:54 -0300)]
[media] v4l2-ctrls: add support for compound types
This patch implements initial support for compound types.
The changes are fairly obvious: basic support for is_ptr types, the
type_is_int function is replaced by a is_int bitfield, and
v4l2_query_ext_ctrl is added.
Note that this patch does not yet add support for N-dimensional
arrays, that comes later. So v4l2_query_ext_ctrl just sets elems to
1 and nr_of_dims and dims[] are all zero.
Signed-off-by: Hans Verkuil <hans.verkuil@cisco.com> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
Hans Verkuil [Thu, 27 Mar 2014 14:25:45 +0000 (11:25 -0300)]
[media] videodev2.h: add initial support for compound controls
Compound controls are controls that can be used for compound and array
types. This allows for more compound data structures to be used with the
control framework.
The existing V4L2_CTRL_FLAG_NEXT_CTRL flag will only enumerate non-compound
controls, so a new V4L2_CTRL_FLAG_NEXT_COMPOUND flag is added to enumerate
compound controls. Set both flags to enumerate any control (compound or not).
Compound control types will start at V4L2_CTRL_COMPOUND_TYPES. In addition, any
control that uses the new 'ptr' field or the existing 'string' field will have
flag V4L2_CTRL_FLAG_HAS_PAYLOAD set.
While not strictly necessary, adding that flag makes life for applications
a lot simpler. If the flag is not set, then the control value is set
through the value or value64 fields of struct v4l2_ext_control, otherwise
a pointer points to the value.