drm/bridge: waveshare-dsi: Fix signedness bug
Subsystems (3)
PATCH 1/1 drm/bridge: waveshare-dsi: Fix signedness bug
The function drm_of_get_data_lanes_count_ep() returns negative error codes and dsi->lanes is an unsigned integer, so the check (dsi->lanes <
0) is always impossible.
Make the return value of drm_of_get_data_lanes_count_ep() be assigned to ret, check for error, and then assign dsi->lanes to ret.
Detected by Smatch:drivers/gpu/drm/bridge/waveshare-dsi.c:70 ws_bridge_attach_dsi() warn:
unsigned 'dsi->lanes' is never less than zero.
--- drivers/gpu/drm/bridge/waveshare-dsi.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/gpu/drm/bridge/waveshare-dsi.c +5 -3
@@ -66,11 +66,13 @@ static int ws_bridge_attach_dsi(struct ws_bridge *ws) dsi->mode_flags =MIPI_DSI_MODE_VIDEO_HSE |MIPI_DSI_MODE_VIDEO |MIPI_DSI_CLOCK_NON_CONTINUOUS ; dsi->format =MIPI_DSI_FMT_RGB888 ; - dsi->lanes =drm_of_get_data_lanes_count_ep (dev->of_node,0 ,0 ,1 ,4 ); -if (dsi->lanes <0 ) { + ret =drm_of_get_data_lanes_count_ep (dev->of_node,0 ,0 ,1 ,4 ); +if (ret <0 ) {dev_warn (dev,"Invalid or missing DSI lane count %d, falling back to 2 lanes\n" , - dsi->lanes); + ret); dsi->lanes =2 ;/* Old DT backward compatibility */ + }else { + dsi->lanes = ret; } ret =devm_mipi_dsi_attach (dev, dsi);
Signature · 1 line
2.53.0
Quoted 10 lines · Ethan Tidmore
The function
drm_of_get_data_lanes_count_ep()returns negative error codes anddsi->lanesis an unsigned integer, so the check (dsi->lanes<
0) is always impossible.Make the return value of
drm_of_get_data_lanes_count_ep()be assigned to ret, check for error, and then assigndsi->lanesto ret.Detected by Smatch:
drivers/gpu/drm/bridge/waveshare-dsi.c:70ws_bridge_attach_dsi()warn:
unsigned 'dsi->lanes' is never less than zero.
I already sent:
[PATCH] drm/bridge: waveshare-dsi: Use temporary signed variable for DSI lanes validation
Quoted 6 lines · Marek Vasut
On 3/7/26 4:32 AM, Ethan Tidmore wrote:
I already sent:
[PATCH] drm/bridge: waveshare-dsi: Use temporary signed variable for DSI lanes validation
Sorry about that! I glanced at lore looking for the kernel test robot, should have looked for patches already for this.
Thanks,
ET
Marek Vasut
Reviewed-byQuoted 10 lines · Ethan Tidmore
Quoted 6 lines · Marek Vasut
On 3/7/26 4:32 AM, Ethan Tidmore wrote:
I already sent:
[PATCH] drm/bridge: waveshare-dsi: Use temporary signed variable for DSI lanes validation
Sorry about that! I glanced at lore looking for the kernel test robot, should have looked for patches already for this.
Actually, looking at it one more time, the patch I sent is missing the update of dev_warn() , so this patch is the better fix:
Thank you !
Quoted 7 lines · Ethan Tidmore
The function
drm_of_get_data_lanes_count_ep()returns negative error codes anddsi->lanesis an unsigned integer, so the check (dsi->lanes<
0) is always impossible.Make the return value of
drm_of_get_data_lanes_count_ep()be assigned to ret, check for error, and then assigndsi->lanesto ret.
Quoted 8 lines
Detected by Smatch:
drivers/gpu/drm/bridge/waveshare-dsi.c:70ws_bridge_attach_dsi()warn:
unsigned 'dsi->lanes' is never less than zero.Reported-by kernel test robot <[email protected]>Fixes fca11428425e9 ("drm/bridge: waveshare-dsi: Add support for 1..4 DSI data lanes")Signed-off-by Ethan Tidmore <[email protected]>
--
Luca Ceresoli, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
Marek Vasut
Reviewed-byQuoted 12 lines · Luca Ceresoli
Quoted 11 lines · Ethan Tidmore
The function
drm_of_get_data_lanes_count_ep()returns negative error codes anddsi->lanesis an unsigned integer, so the check (dsi->lanes<
0) is always impossible.Make the return value of
drm_of_get_data_lanes_count_ep()be assigned to ret, check for error, and then assigndsi->lanesto ret.Detected by Smatch:
drivers/gpu/drm/bridge/waveshare-dsi.c:70ws_bridge_attach_dsi()warn:
unsigned 'dsi->lanes' is never less than zero.
Quoted 6 lines
Quoted 4 lines
Reported-by kernel test robot <[email protected]>Fixes fca11428425e9 ("drm/bridge: waveshare-dsi: Add support for 1..4 DSI data lanes")Signed-off-by Ethan Tidmore <[email protected]>Reviewed-by Luca Ceresoli <[email protected]>
(it seems FDO patchwork did not pick this up)
Quoted 8 lines · Ethan Tidmore
The function
drm_of_get_data_lanes_count_ep()returns negative error codes anddsi->lanesis an unsigned integer, so the check (dsi->lanes<
0) is always impossible.Make the return value of
drm_of_get_data_lanes_count_ep()be assigned to ret, check for error, and then assigndsi->lanesto ret.[...]
Applied, thanks!
[1/1] drm/bridge: waveshare-dsi: Fix signedness bug
commit: a469749640fbcd2f49ab05fb83cca3da07f35ee3
Best regards,
Signature · 1 line
Luca Ceresoli <[email protected]>