From: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
To: linux-media@vger.kernel.org
Cc: Steve Longerbeam <slongerbeam@gmail.com>,
Philipp Zabel <p.zabel@pengutronix.de>,
Rui Miguel Silva <rmfrfs@gmail.com>
Subject: [PATCH 6/8] media: imx: utils: Make imx_media_pixfmt handle variable number of codes
Date: Tue, 10 Mar 2020 18:18:43 +0200 [thread overview]
Message-ID: <20200310161845.1588-7-laurent.pinchart@ideasonboard.com> (raw)
In-Reply-To: <20200310161845.1588-1-laurent.pinchart@ideasonboard.com>
The imx_media_pixfmt structures includes a codes member that stores
media bus codes as a fixed array of 4 integers. The functions dealing
with the imx_media_pixfmt structures assume that the array of codes is
terminated by a 0 elements. This mechanism is fragile, as demonstrated
by several instances of the structure contained 4 non-zero codes.
Fix this by turning the array into a pointer, and providing an
IMX_BUS_FMTS macro to initialize the codes member with a guaranteed 0
element at the end.
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
drivers/staging/media/imx/imx-media-utils.c | 78 ++++++++++++---------
drivers/staging/media/imx/imx-media.h | 2 +-
2 files changed, 46 insertions(+), 34 deletions(-)
diff --git a/drivers/staging/media/imx/imx-media-utils.c b/drivers/staging/media/imx/imx-media-utils.c
index 5036a856be95..291d0b781278 100644
--- a/drivers/staging/media/imx/imx-media-utils.c
+++ b/drivers/staging/media/imx/imx-media-utils.c
@@ -14,21 +14,27 @@
* mbus codes) must all fall at the end of the table.
*/
+#define IMX_BUS_FMTS(fmts...) \
+ (const u32[]) { \
+ fmts, \
+ 0 \
+ }
+
static const struct imx_media_pixfmt yuv_formats[] = {
{
.fourcc = V4L2_PIX_FMT_UYVY,
- .codes = {
+ .codes = IMX_BUS_FMTS(
MEDIA_BUS_FMT_UYVY8_2X8,
MEDIA_BUS_FMT_UYVY8_1X16
- },
+ ),
.cs = IPUV3_COLORSPACE_YUV,
.bpp = 16,
}, {
.fourcc = V4L2_PIX_FMT_YUYV,
- .codes = {
+ .codes = IMX_BUS_FMTS(
MEDIA_BUS_FMT_YUYV8_2X8,
MEDIA_BUS_FMT_YUYV8_1X16
- },
+ ),
.cs = IPUV3_COLORSPACE_YUV,
.bpp = 16,
},
@@ -71,21 +77,21 @@ static const struct imx_media_pixfmt yuv_formats[] = {
static const struct imx_media_pixfmt rgb_formats[] = {
{
.fourcc = V4L2_PIX_FMT_RGB565,
- .codes = {MEDIA_BUS_FMT_RGB565_2X8_LE},
+ .codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_RGB565_2X8_LE),
.cs = IPUV3_COLORSPACE_RGB,
.bpp = 16,
.cycles = 2,
}, {
.fourcc = V4L2_PIX_FMT_RGB24,
- .codes = {
+ .codes = IMX_BUS_FMTS(
MEDIA_BUS_FMT_RGB888_1X24,
MEDIA_BUS_FMT_RGB888_2X12_LE
- },
+ ),
.cs = IPUV3_COLORSPACE_RGB,
.bpp = 24,
}, {
.fourcc = V4L2_PIX_FMT_XRGB32,
- .codes = {MEDIA_BUS_FMT_ARGB8888_1X32},
+ .codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_ARGB8888_1X32),
.cs = IPUV3_COLORSPACE_RGB,
.bpp = 32,
.ipufmt = true,
@@ -93,91 +99,91 @@ static const struct imx_media_pixfmt rgb_formats[] = {
/*** raw bayer and grayscale formats start here ***/
{
.fourcc = V4L2_PIX_FMT_SBGGR8,
- .codes = {MEDIA_BUS_FMT_SBGGR8_1X8},
+ .codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_SBGGR8_1X8),
.cs = IPUV3_COLORSPACE_RGB,
.bpp = 8,
.bayer = true,
}, {
.fourcc = V4L2_PIX_FMT_SGBRG8,
- .codes = {MEDIA_BUS_FMT_SGBRG8_1X8},
+ .codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_SGBRG8_1X8),
.cs = IPUV3_COLORSPACE_RGB,
.bpp = 8,
.bayer = true,
}, {
.fourcc = V4L2_PIX_FMT_SGRBG8,
- .codes = {MEDIA_BUS_FMT_SGRBG8_1X8},
+ .codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_SGRBG8_1X8),
.cs = IPUV3_COLORSPACE_RGB,
.bpp = 8,
.bayer = true,
}, {
.fourcc = V4L2_PIX_FMT_SRGGB8,
- .codes = {MEDIA_BUS_FMT_SRGGB8_1X8},
+ .codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_SRGGB8_1X8),
.cs = IPUV3_COLORSPACE_RGB,
.bpp = 8,
.bayer = true,
}, {
.fourcc = V4L2_PIX_FMT_SBGGR16,
- .codes = {
+ .codes = IMX_BUS_FMTS(
MEDIA_BUS_FMT_SBGGR10_1X10,
MEDIA_BUS_FMT_SBGGR12_1X12,
MEDIA_BUS_FMT_SBGGR14_1X14,
MEDIA_BUS_FMT_SBGGR16_1X16
- },
+ ),
.cs = IPUV3_COLORSPACE_RGB,
.bpp = 16,
.bayer = true,
}, {
.fourcc = V4L2_PIX_FMT_SGBRG16,
- .codes = {
+ .codes = IMX_BUS_FMTS(
MEDIA_BUS_FMT_SGBRG10_1X10,
MEDIA_BUS_FMT_SGBRG12_1X12,
MEDIA_BUS_FMT_SGBRG14_1X14,
- MEDIA_BUS_FMT_SGBRG16_1X16,
- },
+ MEDIA_BUS_FMT_SGBRG16_1X16
+ ),
.cs = IPUV3_COLORSPACE_RGB,
.bpp = 16,
.bayer = true,
}, {
.fourcc = V4L2_PIX_FMT_SGRBG16,
- .codes = {
+ .codes = IMX_BUS_FMTS(
MEDIA_BUS_FMT_SGRBG10_1X10,
MEDIA_BUS_FMT_SGRBG12_1X12,
MEDIA_BUS_FMT_SGRBG14_1X14,
- MEDIA_BUS_FMT_SGRBG16_1X16,
- },
+ MEDIA_BUS_FMT_SGRBG16_1X16
+ ),
.cs = IPUV3_COLORSPACE_RGB,
.bpp = 16,
.bayer = true,
}, {
.fourcc = V4L2_PIX_FMT_SRGGB16,
- .codes = {
+ .codes = IMX_BUS_FMTS(
MEDIA_BUS_FMT_SRGGB10_1X10,
MEDIA_BUS_FMT_SRGGB12_1X12,
MEDIA_BUS_FMT_SRGGB14_1X14,
- MEDIA_BUS_FMT_SRGGB16_1X16,
- },
+ MEDIA_BUS_FMT_SRGGB16_1X16
+ ),
.cs = IPUV3_COLORSPACE_RGB,
.bpp = 16,
.bayer = true,
}, {
.fourcc = V4L2_PIX_FMT_GREY,
- .codes = {
+ .codes = IMX_BUS_FMTS(
MEDIA_BUS_FMT_Y8_1X8,
MEDIA_BUS_FMT_Y10_1X10,
- MEDIA_BUS_FMT_Y12_1X12,
- },
+ MEDIA_BUS_FMT_Y12_1X12
+ ),
.cs = IPUV3_COLORSPACE_RGB,
.bpp = 8,
.bayer = true,
}, {
.fourcc = V4L2_PIX_FMT_Y10,
- .codes = {MEDIA_BUS_FMT_Y10_1X10},
+ .codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_Y10_1X10),
.cs = IPUV3_COLORSPACE_RGB,
.bpp = 16,
.bayer = true,
}, {
.fourcc = V4L2_PIX_FMT_Y12,
- .codes = {MEDIA_BUS_FMT_Y12_1X12},
+ .codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_Y12_1X12),
.cs = IPUV3_COLORSPACE_RGB,
.bpp = 16,
.bayer = true,
@@ -223,14 +229,14 @@ struct imx_media_pixfmt *__find_format(u32 fourcc,
for (i = 0; i < array_size; i++) {
fmt = &array[i];
- if ((!allow_non_mbus && !fmt->codes[0]) ||
+ if ((!allow_non_mbus && !fmt->codes) ||
(!allow_bayer && fmt->bayer))
continue;
if (fourcc && fmt->fourcc == fourcc)
return fmt;
- if (!code)
+ if (!code || !fmt->codes)
continue;
for (j = 0; fmt->codes[j]; j++) {
@@ -327,7 +333,7 @@ static int enum_format(u32 *fourcc, u32 *code, u32 index,
if (fourcc)
*fourcc = fmt->fourcc;
if (code)
- *code = fmt->codes[0];
+ *code = fmt->codes ? fmt->codes[0] : 0;
return 0;
}
@@ -365,13 +371,13 @@ EXPORT_SYMBOL_GPL(imx_media_enum_mbus_format);
static const struct imx_media_pixfmt ipu_formats[] = {
{
.fourcc = V4L2_PIX_FMT_YUV32,
- .codes = {MEDIA_BUS_FMT_AYUV8_1X32},
+ .codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_AYUV8_1X32),
.cs = IPUV3_COLORSPACE_YUV,
.bpp = 32,
.ipufmt = true,
}, {
.fourcc = V4L2_PIX_FMT_XRGB32,
- .codes = {MEDIA_BUS_FMT_ARGB8888_1X32},
+ .codes = IMX_BUS_FMTS(MEDIA_BUS_FMT_ARGB8888_1X32),
.cs = IPUV3_COLORSPACE_RGB,
.bpp = 32,
.ipufmt = true,
@@ -395,6 +401,9 @@ imx_media_find_ipu_format(u32 code, enum codespace_sel cs_sel)
(!accept_rgb && fmt->cs == IPUV3_COLORSPACE_RGB))
continue;
+ if (!fmt->codes)
+ continue;
+
for (j = 0; fmt->codes[j]; j++) {
if (code == fmt->codes[j])
return fmt;
@@ -418,6 +427,9 @@ int imx_media_enum_ipu_format(u32 *code, u32 index, enum codespace_sel cs_sel)
(!accept_rgb && fmt->cs == IPUV3_COLORSPACE_RGB))
continue;
+ if (!fmt->codes)
+ continue;
+
if (index-- == 0) {
*code = fmt->codes[0];
return 0;
diff --git a/drivers/staging/media/imx/imx-media.h b/drivers/staging/media/imx/imx-media.h
index dc6f8fe7c66c..9cedc27a6b4a 100644
--- a/drivers/staging/media/imx/imx-media.h
+++ b/drivers/staging/media/imx/imx-media.h
@@ -69,7 +69,7 @@ enum {
struct imx_media_pixfmt {
u32 fourcc;
- u32 codes[4];
+ const u32 *codes;
int bpp; /* total bpp */
/* cycles per pixel for generic (bayer) formats for the parallel bus */
int cycles;
--
Regards,
Laurent Pinchart
next prev parent reply other threads:[~2020-03-10 16:19 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-03-10 16:18 [PATCH 0/8] media: imx: Miscalleanous format-related cleanups Laurent Pinchart
2020-03-10 16:18 ` [PATCH 1/8] media: imx: imx7-mipi-csis: Cleanup and fix subdev pad format handling Laurent Pinchart
2020-03-10 16:18 ` [PATCH 2/8] media: imx: imx7-mipi-csis: Centralize initialization of pad formats Laurent Pinchart
2020-03-10 16:18 ` [PATCH 3/8] media: imx: utils: Inline init_mbus_colorimetry() in its caller Laurent Pinchart
2020-03-10 16:18 ` [PATCH 4/8] media: imx: utils: Handle Bayer format lookup through a selection flag Laurent Pinchart
2020-03-10 16:18 ` [PATCH 5/8] media: imx: utils: Simplify IPU format lookup and enumeration Laurent Pinchart
2020-03-10 16:18 ` Laurent Pinchart [this message]
2020-03-10 16:18 ` [PATCH 7/8] media: imx: utils: Remove unneeded argument to (find|enum)_format() Laurent Pinchart
2020-03-10 16:18 ` [PATCH 8/8] media: imx: utils: Rename format lookup and enumeration functions Laurent Pinchart
2020-03-10 22:05 ` [PATCH 9/8] media: imx: utils: Constify mbus argument to imx_media_mbus_fmt_to_pix_fmt Laurent Pinchart
2020-03-11 14:35 ` [PATCH 0/8] media: imx: Miscalleanous format-related cleanups Rui Miguel Silva
2020-03-12 0:16 ` Steve Longerbeam
2020-03-12 0:47 ` Laurent Pinchart
2020-03-12 0:55 ` Steve Longerbeam
2020-03-14 22:30 ` Steve Longerbeam
2020-03-14 22:32 ` Laurent Pinchart
2020-03-14 22:33 ` Steve Longerbeam
2020-03-26 19:05 ` Steve Longerbeam
2020-03-26 19:53 ` Laurent Pinchart
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200310161845.1588-7-laurent.pinchart@ideasonboard.com \
--to=laurent.pinchart@ideasonboard.com \
--cc=linux-media@vger.kernel.org \
--cc=p.zabel@pengutronix.de \
--cc=rmfrfs@gmail.com \
--cc=slongerbeam@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.