1 From 82adac27d1b98cb33b9e5e7b2528388633df9181 Mon Sep 17 00:00:00 2001
2 From: Pawe? Chmiel <pawel.mikolaj.chmiel@gmail.com>
3 Date: Sat, 29 Dec 2018 10:46:01 -0500
4 Subject: media: s5p-jpeg: Check for fmt_ver_flag when doing fmt enumeration
6 [ Upstream commit 49710c32cd9d6626a77c9f5f978a5f58cb536b35 ]
8 Previously when doing format enumeration, it was returning all
9 formats supported by driver, even if they're not supported by hw.
10 Add missing check for fmt_ver_flag, so it'll be fixed and only those
11 supported by hw will be returned. Similar thing is already done
12 in s5p_jpeg_find_format.
14 It was found by using v4l2-compliance tool and checking result
15 of VIDIOC_ENUM_FMT/FRAMESIZES/FRAMEINTERVALS test
16 and using v4l2-ctl to get list of all supported formats.
18 Tested on s5pv210-galaxys (Samsung i9000 phone).
20 Fixes: bb677f3ac434 ("[media] Exynos4 JPEG codec v4l2 driver")
22 Signed-off-by: Pawe? Chmiel <pawel.mikolaj.chmiel@gmail.com>
23 Reviewed-by: Jacek Anaszewski <jacek.anaszewski@gmail.com>
24 [hverkuil-cisco@xs4all.nl: fix a few alignment issues]
25 Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
26 Signed-off-by: Sasha Levin <sashal@kernel.org>
28 drivers/media/platform/s5p-jpeg/jpeg-core.c | 19 +++++++++++--------
29 1 file changed, 11 insertions(+), 8 deletions(-)
31 diff --git a/drivers/media/platform/s5p-jpeg/jpeg-core.c b/drivers/media/platform/s5p-jpeg/jpeg-core.c
32 index 80c83bba7af3..0d981bbf38bc 100644
33 --- a/drivers/media/platform/s5p-jpeg/jpeg-core.c
34 +++ b/drivers/media/platform/s5p-jpeg/jpeg-core.c
35 @@ -1262,13 +1262,16 @@ static int s5p_jpeg_querycap(struct file *file, void *priv,
39 -static int enum_fmt(struct s5p_jpeg_fmt *sjpeg_formats, int n,
40 +static int enum_fmt(struct s5p_jpeg_ctx *ctx,
41 + struct s5p_jpeg_fmt *sjpeg_formats, int n,
42 struct v4l2_fmtdesc *f, u32 type)
45 + unsigned int fmt_ver_flag = ctx->jpeg->variant->fmt_ver_flag;
47 for (i = 0; i < n; ++i) {
48 - if (sjpeg_formats[i].flags & type) {
49 + if (sjpeg_formats[i].flags & type &&
50 + sjpeg_formats[i].flags & fmt_ver_flag) {
51 /* index-th format of type type found ? */
54 @@ -1294,11 +1297,11 @@ static int s5p_jpeg_enum_fmt_vid_cap(struct file *file, void *priv,
55 struct s5p_jpeg_ctx *ctx = fh_to_ctx(priv);
57 if (ctx->mode == S5P_JPEG_ENCODE)
58 - return enum_fmt(sjpeg_formats, SJPEG_NUM_FORMATS, f,
59 + return enum_fmt(ctx, sjpeg_formats, SJPEG_NUM_FORMATS, f,
60 SJPEG_FMT_FLAG_ENC_CAPTURE);
62 - return enum_fmt(sjpeg_formats, SJPEG_NUM_FORMATS, f,
63 - SJPEG_FMT_FLAG_DEC_CAPTURE);
64 + return enum_fmt(ctx, sjpeg_formats, SJPEG_NUM_FORMATS, f,
65 + SJPEG_FMT_FLAG_DEC_CAPTURE);
68 static int s5p_jpeg_enum_fmt_vid_out(struct file *file, void *priv,
69 @@ -1307,11 +1310,11 @@ static int s5p_jpeg_enum_fmt_vid_out(struct file *file, void *priv,
70 struct s5p_jpeg_ctx *ctx = fh_to_ctx(priv);
72 if (ctx->mode == S5P_JPEG_ENCODE)
73 - return enum_fmt(sjpeg_formats, SJPEG_NUM_FORMATS, f,
74 + return enum_fmt(ctx, sjpeg_formats, SJPEG_NUM_FORMATS, f,
75 SJPEG_FMT_FLAG_ENC_OUTPUT);
77 - return enum_fmt(sjpeg_formats, SJPEG_NUM_FORMATS, f,
78 - SJPEG_FMT_FLAG_DEC_OUTPUT);
79 + return enum_fmt(ctx, sjpeg_formats, SJPEG_NUM_FORMATS, f,
80 + SJPEG_FMT_FLAG_DEC_OUTPUT);
83 static struct s5p_jpeg_q_data *get_q_data(struct s5p_jpeg_ctx *ctx,