Skip to contentSkip to conversation

power: supply: rt5033_charger: fix extcon DT parsing and deferral handling

PATCH New Manush Prajwal 1 participant 1 message Nov 11 Power supply

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 power: supply: rt5033_charger: fix extcon DT parsing and deferral handling

In rt5033_charger_probe(), the driver attempts to parse the optional "richtek,usb-connector" phandle:

1. When "richtek,usb-connector" is absent from DT, of_parse_phandle() returns NULL. Currently, the driver unconditionally passes np_conn to of_get_parent(NULL), which returns NULL, and then calls extcon_find_edev_by_node(NULL). In extcon_find_edev_by_node(), passing a NULL node can erroneously match any extcon device without a DT node or return -EPROBE_DEFER, which is then masked as a DT warning while leaving probe to succeed with an invalid/unintended configuration.
2. If "richtek,usb-connector" is present in DT but the extcon provider has not probed yet, extcon_find_edev_by_node() returns -EPROBE_DEFER. The driver treats all errors identically with dev_warn() and returns 0, silently abandoning extcon initialization instead of deferring probe. Consequently, cable detection and OTG supply functionality remain permanently disabled.

Fix this by:
- Checking if np_conn is NULL and skipping extcon setup cleanly if the property is omitted from DT.
- Checking that np_edev is valid before calling extcon_find_edev_by_node().
- Propagating -EPROBE_DEFER via dev_err_probe() when the extcon device is deferred.
- Using dev_err_probe() for work and notifier registration failures.

Fixes 8242336dc8a8 ("power: supply: rt5033_charger: Add cable detection and USB OTG supply")
---
 drivers/power/supply/rt5033_charger.c | 30 +++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)
drivers/power/supply/rt5033_charger.c +21 -9
index e545a6e7f..5a149640a 100644
@@ -698,29 +698,41 @@ static int rt5033_charger_probe(struct platform_device *pdev)
 	 * is available, just emit a warning and leave the probe function.
 	 */
 	np_conn = of_parse_phandle(pdev->dev.of_node, "richtek,usb-connector", 0);
+	if (!np_conn) {
+		dev_warn(charger->dev, "no extcon device found in device-tree\n");
+		goto out;
+	}
+
 	np_edev = of_get_parent(np_conn);
+	of_node_put(np_conn);
+	if (!np_edev) {
+		dev_warn(charger->dev, "no extcon parent found in device-tree\n");
+		goto out;
+	}
+
 	charger->edev = extcon_find_edev_by_node(np_edev);
 	of_node_put(np_edev);
-	of_node_put(np_conn);
 	if (IS_ERR(charger->edev)) {
+		ret = PTR_ERR(charger->edev);
+		if (ret == -EPROBE_DEFER)
+			return dev_err_probe(charger->dev, ret,
+					     "failed to find extcon device\n");
 		dev_warn(charger->dev, "no extcon device found in device-tree\n");
 		goto out;
 	}
 
 	ret = devm_work_autocancel(charger->dev, &charger->extcon_work,
 				   rt5033_charger_extcon_work);
-	if (ret) {
-		dev_err(charger->dev, "failed to initialize extcon work\n");
-		return ret;
-	}
+	if (ret)
+		return dev_err_probe(charger->dev, ret,
+				     "failed to initialize extcon work\n");
 
 	charger->extcon_nb.notifier_call = rt5033_charger_extcon_notifier;
 	ret = devm_extcon_register_notifier_all(charger->dev, charger->edev,
 						&charger->extcon_nb);
-	if (ret) {
-		dev_err(charger->dev, "failed to register extcon notifier\n");
-		return ret;
-	}
+	if (ret)
+		return dev_err_probe(charger->dev, ret,
+				     "failed to register extcon notifier\n");
 out:
 	return 0;
 }
Signature · 1 line
2.46.2.windows.1