OSDN Git Service

media: imx: utils: Make imx_media_pixfmt handle variable number of codes
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Mon, 6 Apr 2020 16:39:02 +0000 (18:39 +0200)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Tue, 21 Apr 2020 11:20:33 +0000 (13:20 +0200)
commitc943b6947f459189419114682ac343fc1e22a954
tree6154ea3f3095a748ba5bbf5b98efb76fba1c5aae
parentf0f71ae440a956d51ed1f3e2ba17638c51b7dfa7
media: imx: utils: Make imx_media_pixfmt handle variable number of codes

The imx_media_pixfmt structures include 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 element. This mechanism is fragile, as demonstrated
by several instances of the structure containing 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.

[Fixed a NULL deref of the codes pointer in a couple places]
[Added more comments for the struct imx_media_pixfmt members,
 including a bold NOTE! for future developers that codes pointer
 is NULL for the in-memory-only formats]

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Steve Longerbeam <slongerbeam@gmail.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
drivers/staging/media/imx/imx-media-capture.c
drivers/staging/media/imx/imx-media-utils.c
drivers/staging/media/imx/imx-media.h