Skip to contentSkip to conversation

drm/bridge: anx7625: Zero error variable when panel bridge not present

PATCH Applied Nícolas F. R. A. Prado 4 participants 4 messages Jun 13, 2022 – Jun 15, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/bridge: anx7625: Zero error variable when panel bridge not present

While parsing the DT, the anx7625 driver checks for the presence of a panel bridge on endpoint 1. If it is missing, pdata->panel_bridge stores the error pointer and the function returns successfully without first cleaning that variable. This is an issue since other functions later check for the presence of a panel bridge by testing the trueness of that variable.

In order to ensure proper behavior, zero out pdata->panel_bridge before returning when no panel bridge is found.

Fixes 9e82ea0fb1df ("drm/bridge: anx7625: switch to devm_drm_of_get_bridge")

---

 drivers/gpu/drm/bridge/analogix/anx7625.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/bridge/analogix/anx7625.c +3 -1
index 53a5da6c49dd..3aed4de16690 100644
@@ -1657,8 +1657,10 @@ static int anx7625_parse_dt(struct device *dev,
 
 	pdata->panel_bridge = devm_drm_of_get_bridge(dev, np, 1, 0);
 	if (IS_ERR(pdata->panel_bridge)) {
-		if (PTR_ERR(pdata->panel_bridge) == -ENODEV)
+		if (PTR_ERR(pdata->panel_bridge) == -ENODEV) {
+			pdata->panel_bridge = NULL;
 			return 0;
+		}
 
 		return PTR_ERR(pdata->panel_bridge);
 	}
Signature · 1 line
2.36.1
#1 lore raw
Quoted 37 lines · Nícolas F. R. A. Prado

While parsing the DT, the anx7625 driver checks for the presence of a panel bridge on endpoint 1. If it is missing, pdata->panel_bridge stores the error pointer and the function returns successfully without first cleaning that variable. This is an issue since other functions later check for the presence of a panel bridge by testing the trueness of that variable.

In order to ensure proper behavior, zero out pdata->panel_bridge before returning when no panel bridge is found.

Fixes 9e82ea0fb1df ("drm/bridge: anx7625: switch to devm_drm_of_get_bridge")

---

 drivers/gpu/drm/bridge/analogix/anx7625.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/bridge/analogix/anx7625.c +3 -1
index 53a5da6c49dd..3aed4de16690 100644
@@ -1657,8 +1657,10 @@ static int anx7625_parse_dt(struct device *dev,
 
 	pdata->panel_bridge = devm_drm_of_get_bridge(dev, np, 1, 0);
 	if (IS_ERR(pdata->panel_bridge)) {
-		if (PTR_ERR(pdata->panel_bridge) == -ENODEV)
+		if (PTR_ERR(pdata->panel_bridge) == -ENODEV) {
+			pdata->panel_bridge = NULL;
 			return 0;
+		}
 
 		return PTR_ERR(pdata->panel_bridge);
 	}
Signature · 1 line
2.36.1

Thanks for spotting this error Nícolas. As you mentioned, prior to 9e82ea0fb1df the "pdata->panel_bridge" pointer was not modified (i.e. left to NULL) on the ENODEV error branch.

I missed it during the refactor, sorry about that.

Reviewed-by on v1 1/1
#2 lore raw
In reply to Nícolas F. R. A. Prado

Il 13/06/22 18:37, Nícolas F. R. A. Prado ha scritto:

Quoted 7 lines

While parsing the DT, the anx7625 driver checks for the presence of a panel bridge on endpoint 1. If it is missing, pdata->panel_bridge stores the error pointer and the function returns successfully without first cleaning that variable. This is an issue since other functions later check for the presence of a panel bridge by testing the trueness of that variable.

Quoted 6 lines

In order to ensure proper behavior, zero out pdata->panel_bridge before returning when no panel bridge is found.

Fixes 9e82ea0fb1df ("drm/bridge: anx7625: switch to devm_drm_of_get_bridge")

I would've preferred s/zero out/cleanup/g but it's also fine as you wrote it. Besides, good catch!

Applied
#3 lore raw
Quoted 12 lines · AngeloGioacchino Del Regno

Il 13/06/22 18:37, Nícolas F. R. A. Prado ha scritto:

Quoted 10 lines

While parsing the DT, the anx7625 driver checks for the presence of a panel bridge on endpoint 1. If it is missing, pdata->panel_bridge stores the error pointer and the function returns successfully without first cleaning that variable. This is an issue since other functions later check for the presence of a panel bridge by testing the trueness of that variable.

In order to ensure proper behavior, zero out pdata->panel_bridge before returning when no panel bridge is found.

Quoted 9 lines
Quoted 3 lines
Fixes 9e82ea0fb1df ("drm/bridge: anx7625: switch to devm_drm_of_get_bridge")

I would've preferred s/zero out/cleanup/g but it's also fine as you wrote it. Besides, good catch!

Applied to drm-misc-next