mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Manush Prajwal" <manushprajwal555@gmail.com>
To: sre@kernel.org, jay-hx@posteo.net
Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] power: supply: rt5033_charger: fix extcon DT parsing and deferral handling
Date: 11 Nov 2026 16:45:21 +0530	[thread overview]
Message-ID: <6af44e4b.4b6e150d.9a2df.361b@mx.google.com> (raw)

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")
Signed-off-by: Manush Prajwal <manushprajwal555@gmail.com>
---
 drivers/power/supply/rt5033_charger.c | 30 +++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)

diff --git a/drivers/power/supply/rt5033_charger.c b/drivers/power/supply/rt5033_charger.c
index e545a6e7f..5a149640a 100644
--- a/drivers/power/supply/rt5033_charger.c
+++ b/drivers/power/supply/rt5033_charger.c
@@ -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;
 }
-- 
2.46.2.windows.1


                 reply	other threads:[~2026-11-11 11:15 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6af44e4b.4b6e150d.9a2df.361b@mx.google.com \
    --to=manushprajwal555@gmail.com \
    --cc=jay-hx@posteo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=sre@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®