[PATCH] drm/bridge: sii902x: Read "sil,i2s-data-lanes" as u32
"Rob Herring (Arm)" <[email protected]>
| Newsgroups | gmane.linux.kernel,gmane.comp.video.dri.devel |
|---|---|
| Message-ID | <[email protected]> |
The "sil,i2s-data-lanes" binding and in-tree DTS files use normal uint32 cells. Reading the array as u8 only works because the values are small, but it does not match the documented DT element size. Use the u32 array helper so the driver follows the binding. Changing to u32 increases a potential OOB access range due to using unchecked values, so add a check on the read values. Signed-off-by: Rob Herring (Arm) <[email protected]> --- v2: - Add bounds check for property values as reported by sashiko --- drivers/gpu/drm/bridge/sii902x.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/bridge/sii902x.c b/drivers/gpu/drm/bridge/sii902x.c index 9aac44ed5b67..241b472ab13e 100644 --- a/drivers/gpu/drm/bridge/sii902x.c +++ b/drivers/gpu/drm/bridge/sii902x.c @@ -862,7 +862,7 @@ static int sii902x_audio_codec_init(struct sii902x *sii902x, .max_i2s_channels = 0, .no_capture_mute = 1, }; - u8 lanes[4]; + u32 lanes[4]; int num_lanes, i; if (!of_property_present(dev->of_node, "#sound-dai-cells")) { @@ -871,10 +871,10 @@ static int sii902x_audio_codec_init(struct sii902x *sii902x, return 0; } - num_lanes = of_property_read_variable_u8_array(dev->of_node, - "sil,i2s-data-lanes", - lanes, 1, - ARRAY_SIZE(lanes)); + num_lanes = of_property_read_variable_u32_array(dev->of_node, + "sil,i2s-data-lanes", + lanes, 1, + ARRAY_SIZE(lanes)); if (num_lanes == -EINVAL) { dev_dbg(dev, @@ -890,9 +890,12 @@ static int sii902x_audio_codec_init(struct sii902x *sii902x, } codec_data.max_i2s_channels = 2 * num_lanes; - for (i = 0; i < num_lanes; i++) + for (i = 0; i < num_lanes; i++) { + if (WARN_ON(lanes[i] >= ARRAY_SIZE(i2s_lane_id))) + break; sii902x->audio.i2s_fifo_sequence[i] |= audio_fifo_id[i] | i2s_lane_id[lanes[i]] | SII902X_TPI_I2S_FIFO_ENABLE; + } sii902x->audio.mclk = devm_clk_get_optional(dev, "mclk"); if (IS_ERR(sii902x->audio.mclk)) { -- 2.53.0