Skip to contentSkip to conversation

drm/bridge: Avoid uninitialized variable warning

PATCH Superseded Dan Carpenter 2 participants 4 messages Jun 28, 2022

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/bridge: Avoid uninitialized variable warning

This works, but technically it uses "num_in_bus_fmts" before it has been initialized so it leads to static checker warnings and probably KMEMsan warnings at run time. Reverse the checks so it checks for failure first and then check for unsupported formats next.

Fixes f32df58acc68 ("drm/bridge: Add the necessary bits to support bus format negotiation")
---
 drivers/gpu/drm/drm_bridge.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/gpu/drm/drm_bridge.c +6 -6
index e275b4ca344b..00cbde654472 100644
@@ -897,10 +897,10 @@ static int select_bus_fmt_recursive(struct drm_bridge *first_bridge,
 							conn_state,
 							out_bus_fmt,
 							&num_in_bus_fmts);
-	if (!num_in_bus_fmts)
-		return -ENOTSUPP;
-	else if (!in_bus_fmts)
+	if (!in_bus_fmts)
 		return -ENOMEM;
+	else if (!num_in_bus_fmts)
+		return -ENOTSUPP;
 
 	if (first_bridge == cur_bridge) {
 		cur_state->input_bus_cfg.format = in_bus_fmts[0];
@@ -993,10 +993,10 @@ drm_atomic_bridge_chain_select_bus_fmts(struct drm_bridge *bridge,
 							crtc_state,
 							conn_state,
 							&num_out_bus_fmts);
-		if (!num_out_bus_fmts)
-			return -ENOTSUPP;
-		else if (!out_bus_fmts)
+		if (!out_bus_fmts)
 			return -ENOMEM;
+		else if (!num_out_bus_fmts)
+			return -ENOTSUPP;
 	} else {
 		num_out_bus_fmts = 1;
 		out_bus_fmts = kmalloc(sizeof(*out_bus_fmts), GFP_KERNEL);
Signature · 1 line
2.35.1
#1 lore raw
Quoted 16 lines · On Tue, 28 Jun 2022 09:59:51 +0300 Dan Carpenter <[email protected]>…

This works, but technically it uses "num_in_bus_fmts" before it has been initialized so it leads to static checker warnings and probably KMEMsan warnings at run time. Reverse the checks so it checks for failure first and then check for unsupported formats next.

Fixes f32df58acc68 ("drm/bridge: Add the necessary bits to support bus format negotiation")
---
 drivers/gpu/drm/drm_bridge.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/gpu/drm/drm_bridge.c +0 -0
index e275b4ca344b..00cbde654472 100644

drivers/gpu/drm/drm_bridge.c static int select_bus_fmt_recursive(struct drm_bridge *first_bridge, · line 903

Quoted 10 lines
drivers/gpu/drm/drm_bridge.c +3 -3
@@ -897,10 +897,10 @@ static int select_bus_fmt_recursive(struct drm_bridge *first_bridge,
 							conn_state,
 							out_bus_fmt,
 							&num_in_bus_fmts);
-	if (!num_in_bus_fmts)
-		return -ENOTSUPP;
-	else if (!in_bus_fmts)
+	if (!in_bus_fmts)
 		return -ENOMEM;
+	else if (!num_in_bus_fmts)
+		return -ENOTSUPP;

Well, it changes the error we return when num_in_bus_fmts = 0 && in_bus_fmts == NULL which is not an ENOMEM situation, so I'd rather initialize num_{in,out}_bus_fmts to 0 here.

Quoted 17 lines
drivers/gpu/drm/drm_bridge.c +3 -3
 	if (first_bridge == cur_bridge) {
 		cur_state->input_bus_cfg.format = in_bus_fmts[0];
@@ -993,10 +993,10 @@ drm_atomic_bridge_chain_select_bus_fmts(struct drm_bridge *bridge,
 							crtc_state,
 							conn_state,
 							&num_out_bus_fmts);
-		if (!num_out_bus_fmts)
-			return -ENOTSUPP;
-		else if (!out_bus_fmts)
+		if (!out_bus_fmts)
 			return -ENOMEM;
+		else if (!num_out_bus_fmts)
+			return -ENOTSUPP;
 	} else {
 		num_out_bus_fmts = 1;
 		out_bus_fmts = kmalloc(sizeof(*out_bus_fmts), GFP_KERNEL);
#2 lore raw
Quoted 25 lines · Boris Brezillon
Quoted 22 lines · On Tue, 28 Jun 2022 09:59:51 +0300 Dan Carpenter <[email protected]>…

This works, but technically it uses "num_in_bus_fmts" before it has been initialized so it leads to static checker warnings and probably KMEMsan warnings at run time. Reverse the checks so it checks for failure first and then check for unsupported formats next.

Fixes f32df58acc68 ("drm/bridge: Add the necessary bits to support bus format negotiation")
---
 drivers/gpu/drm/drm_bridge.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/gpu/drm/drm_bridge.c +0 -3
index e275b4ca344b..00cbde654472 100644
@@ -897,10 +897,10 @@ static int select_bus_fmt_recursive(struct drm_bridge *first_bridge,
 							conn_state,
 							out_bus_fmt,
 							&num_in_bus_fmts);
-	if (!num_in_bus_fmts)
-		return -ENOTSUPP;
-	else if (!in_bus_fmts)
Quoted 9 lines

drivers/gpu/drm/drm_bridge.c static int select_bus_fmt_recursive(struct drm_bridge *first_bridge, · line 903

Quoted 4 lines
drivers/gpu/drm/drm_bridge.c +3 -0
+	if (!in_bus_fmts)
 		return -ENOMEM;
+	else if (!num_in_bus_fmts)
+		return -ENOTSUPP;

Well, it changes the error we return when num_in_bus_fmts = 0 && in_bus_fmts == NULL which is not an ENOMEM situation, so I'd rather initialize num_{in,out}_bus_fmts to 0 here.

I can do that but there is no real consistency in how ->atomic_get_input_bus_fmts() functions are implemented. Some set *num_input_fmts = 0; before the kmalloc() and then reset it to *num_input_fmts = 1; if the allocation succeeds. Some just set it to *num_input_fmts = 1 at the start.

This bug only affects the imx code like:
imx8qm_ldb_bridge_atomic_get_input_bus_fmts() imx8qxp_pixel_link_bridge_atomic_get_input_bus_fmts

Anyway, it's not a problem to resend.

regards,
dan carpenter

#3 lore raw
Quoted 42 lines · On Tue, 28 Jun 2022 10:45:19 +0300 Dan Carpenter <[email protected]>…
Quoted 25 lines · Boris Brezillon
Quoted 22 lines · On Tue, 28 Jun 2022 09:59:51 +0300 Dan Carpenter <[email protected]>…

This works, but technically it uses "num_in_bus_fmts" before it has been initialized so it leads to static checker warnings and probably KMEMsan warnings at run time. Reverse the checks so it checks for failure first and then check for unsupported formats next.

Fixes f32df58acc68 ("drm/bridge: Add the necessary bits to support bus format negotiation")
---
 drivers/gpu/drm/drm_bridge.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/gpu/drm/drm_bridge.c +0 -3
index e275b4ca344b..00cbde654472 100644
@@ -897,10 +897,10 @@ static int 	(struct drm_bridge *first_bridge,
 							conn_state,
 							out_bus_fmt,
 							&num_in_bus_fmts);
-	if (!num_in_bus_fmts)
-		return -ENOTSUPP;
-	else if (!in_bus_fmts)
Quoted 9 lines

drivers/gpu/drm/drm_bridge.c static int select_bus_fmt_recursive(struct drm_bridge *first_bridge, · line 903

Quoted 4 lines
drivers/gpu/drm/drm_bridge.c +3 -0
+	if (!in_bus_fmts)
 		return -ENOMEM;
+	else if (!num_in_bus_fmts)
+		return -ENOTSUPP;  

Well, it changes the error we return when num_in_bus_fmts = 0 && in_bus_fmts == NULL which is not an ENOMEM situation, so I'd rather initialize num_{in,out}_bus_fmts to 0 here.

I can do that but there is no real consistency in how ->atomic_get_input_bus_fmts() functions are implemented. Some set *num_input_fmts = 0; before the kmalloc() and then reset it to *num_input_fmts = 1; if the allocation succeeds. Some just set it to *num_input_fmts = 1 at the start.

Quoted 4 lines

This bug only affects the imx code like:
imx8qm_ldb_bridge_atomic_get_input_bus_fmts() imx8qxp_pixel_link_bridge_atomic_get_input_bus_fmts

I'd say imx8qm_ldb_bridge_atomic_get_input_bus_fmts() and imx8qxp_pixel_link_bridge_atomic_get_input_bus_fmts() should be patched to set *num_input_fmts = 0 when they return NULL on purpose, as documented here [1].

[1]https://elixir.bootlin.com/linux/latest/source/include/drm/drm_bridge.h#L453