[PATCH v2 02/25] media: i2c: imx283: Fix handling of unsupported mbus codes

From: Kieran Bingham

Date: Fri Feb 13 2026 - 09:04:27 EST


From: Stefan Klug <stefan.klug@xxxxxxxxxxxxxxxx>

When the code requested by imx283_set_pad_format() is not supported, a
kernel exception occurs due to dereferencing the mode variable which is
null. Fix that by correcting the code to a valid value before getting
the mode table.

While at it, remove the cases for the other unsupported codes in
get_mode_table.

Cc: stable@xxxxxxxxxxxxxxx # v6.10-rc1-70-gccb4eb4496fa
Fixes: ccb4eb4496fa ("media: i2c: Add imx283 camera sensor driver")
Reviewed-by: Kieran Bingham <kieran.bingham@xxxxxxxxxxxxxxxx>
Tested-by: Kieran Bingham <kieran.bingham@xxxxxxxxxxxxxxxx>
Signed-off-by: Stefan Klug <stefan.klug@xxxxxxxxxxxxxxxx>
---
drivers/media/i2c/imx283.c | 24 ++++++++++++++++--------
1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/drivers/media/i2c/imx283.c b/drivers/media/i2c/imx283.c
index e5c04d259625..9a47cd0b181a 100644
--- a/drivers/media/i2c/imx283.c
+++ b/drivers/media/i2c/imx283.c
@@ -576,23 +576,31 @@ static inline struct imx283 *to_imx283(struct v4l2_subdev *sd)
return container_of_const(sd, struct imx283, sd);
}

+static inline int get_format_code(unsigned int code)
+{
+ unsigned int i;
+
+ for (i = 0; i < ARRAY_SIZE(imx283_mbus_codes); i++)
+ if (imx283_mbus_codes[i] == code)
+ break;
+
+ if (i >= ARRAY_SIZE(imx283_mbus_codes))
+ i = 0;
+
+ return imx283_mbus_codes[i];
+}
+
static inline void get_mode_table(unsigned int code,
const struct imx283_mode **mode_list,
unsigned int *num_modes)
{
switch (code) {
case MEDIA_BUS_FMT_SRGGB12_1X12:
- case MEDIA_BUS_FMT_SGRBG12_1X12:
- case MEDIA_BUS_FMT_SGBRG12_1X12:
- case MEDIA_BUS_FMT_SBGGR12_1X12:
*mode_list = supported_modes_12bit;
*num_modes = ARRAY_SIZE(supported_modes_12bit);
break;

case MEDIA_BUS_FMT_SRGGB10_1X10:
- case MEDIA_BUS_FMT_SGRBG10_1X10:
- case MEDIA_BUS_FMT_SGBRG10_1X10:
- case MEDIA_BUS_FMT_SBGGR10_1X10:
*mode_list = supported_modes_10bit;
*num_modes = ARRAY_SIZE(supported_modes_10bit);
break;
@@ -963,6 +971,8 @@ static int imx283_set_pad_format(struct v4l2_subdev *sd,
const struct imx283_mode *mode_list;
unsigned int num_modes;

+ fmt->format.code = get_format_code(fmt->format.code);
+
get_mode_table(fmt->format.code, &mode_list, &num_modes);

mode = v4l2_find_nearest_size(mode_list, num_modes, width, height,
@@ -1361,8 +1371,6 @@ static int imx283_init_controls(struct imx283 *imx283)

imx283->vflip = v4l2_ctrl_new_std(ctrl_hdlr, &imx283_ctrl_ops, V4L2_CID_VFLIP,
0, 1, 1, 0);
- if (imx283->vflip)
- imx283->vflip->flags |= V4L2_CTRL_FLAG_MODIFY_LAYOUT;

v4l2_ctrl_new_std_menu_items(ctrl_hdlr, &imx283_ctrl_ops,
V4L2_CID_TEST_PATTERN,

--
2.52.0