aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/media/sunxi/cedrus/cedrus_video.c
diff options
context:
space:
mode:
authorHans Verkuil <hverkuil-cisco@xs4all.nl>2019-08-30 06:26:24 -0300
committerMauro Carvalho Chehab <mchehab+samsung@kernel.org>2019-10-01 16:40:53 -0300
commit965c71e8adcff315e16b58c00cd312598fc0222c (patch)
tree80598535d07246b8b833402b5fbe552b6d51a488 /drivers/staging/media/sunxi/cedrus/cedrus_video.c
parentdec555256f2cb61ee94975727ec2d4a8d592ac92 (diff)
media: cedrus: fix various format-related compliance issues
Initialize the context on open() with valid capture and output formats. It is good practice to always have valid formats internally. This solves one vb2 warning in the kernel log where the sizeimage value of the output format was 0 when requesting buffers, which is not allowed. It also simplifies the g_fmt ioctl implementations since they no longer have to check if a valid format was ever set. cedrus_prepare_format() now also validates sizeimage for the output formats, ensuring userspace can't set it to 0 since that would cause the same vb2 warning. Finally remove the sizeimage == 0 check in cedrus_try_fmt_vid_out() since cedrus_prepare_format() will now adjust this value. Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> Reviewed-by: Jernej Skrabec <jernej.skrabec@siol.net> Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
Diffstat (limited to 'drivers/staging/media/sunxi/cedrus/cedrus_video.c')
-rw-r--r--drivers/staging/media/sunxi/cedrus/cedrus_video.c28
1 files changed, 3 insertions, 25 deletions
diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_video.c b/drivers/staging/media/sunxi/cedrus/cedrus_video.c
index d69c9bcdb8e2..3ec3a2db790c 100644
--- a/drivers/staging/media/sunxi/cedrus/cedrus_video.c
+++ b/drivers/staging/media/sunxi/cedrus/cedrus_video.c
@@ -86,7 +86,7 @@ static struct cedrus_format *cedrus_find_format(u32 pixelformat, u32 directions,
return &cedrus_formats[i];
}
-static void cedrus_prepare_format(struct v4l2_pix_format *pix_fmt)
+void cedrus_prepare_format(struct v4l2_pix_format *pix_fmt)
{
unsigned int width = pix_fmt->width;
unsigned int height = pix_fmt->height;
@@ -104,7 +104,8 @@ static void cedrus_prepare_format(struct v4l2_pix_format *pix_fmt)
case V4L2_PIX_FMT_H264_SLICE:
/* Zero bytes per line for encoded source. */
bytesperline = 0;
-
+ /* Choose some minimum size since this can't be 0 */
+ sizeimage = max_t(u32, SZ_1K, sizeimage);
break;
case V4L2_PIX_FMT_SUNXI_TILED_NV12:
@@ -211,16 +212,7 @@ static int cedrus_g_fmt_vid_cap(struct file *file, void *priv,
{
struct cedrus_ctx *ctx = cedrus_file2ctx(file);
- /* Fall back to dummy default by lack of hardware configuration. */
- if (!ctx->dst_fmt.width || !ctx->dst_fmt.height) {
- f->fmt.pix.pixelformat = V4L2_PIX_FMT_SUNXI_TILED_NV12;
- cedrus_prepare_format(&f->fmt.pix);
-
- return 0;
- }
-
f->fmt.pix = ctx->dst_fmt;
-
return 0;
}
@@ -229,17 +221,7 @@ static int cedrus_g_fmt_vid_out(struct file *file, void *priv,
{
struct cedrus_ctx *ctx = cedrus_file2ctx(file);
- /* Fall back to dummy default by lack of hardware configuration. */
- if (!ctx->dst_fmt.width || !ctx->dst_fmt.height) {
- f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG2_SLICE;
- f->fmt.pix.sizeimage = SZ_1K;
- cedrus_prepare_format(&f->fmt.pix);
-
- return 0;
- }
-
f->fmt.pix = ctx->src_fmt;
-
return 0;
}
@@ -275,10 +257,6 @@ static int cedrus_try_fmt_vid_out(struct file *file, void *priv,
if (!fmt)
return -EINVAL;
- /* Source image size has to be provided by userspace. */
- if (pix_fmt->sizeimage == 0)
- return -EINVAL;
-
pix_fmt->pixelformat = fmt->pixelformat;
cedrus_prepare_format(pix_fmt);

Privacy Policy