mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Support Opensource <support.opensource@diasemi.com>,
	 Linus Walleij <linusw@kernel.org>,
	 Charles Keepax <ckeepax@opensource.cirrus.com>,
	 Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	 Laxman Dewangan <ldewangan@nvidia.com>,
	 Richard Fitzgerald <rf@opensource.cirrus.com>,
	Lee Jones <lee@kernel.org>,  Joseph Chen <chenjh@rock-chips.com>,
	Heiko Stuebner <heiko@sntech.de>,
	 Herve Codina <herve.codina@bootlin.com>,
	 Christophe Leroy <chleroy@kernel.org>,
	 David Rhodes <david.rhodes@cirrus.com>,
	 Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>,
	 Nikita Shubin <nikita.shubin@maquefel.me>
Cc: Bartosz Golaszewski <brgl@kernel.org>,
	 Haotian Zhang <vulab@iscas.ac.cn>,
	linux-gpio@vger.kernel.org,  linux-sound@vger.kernel.org,
	patches@opensource.cirrus.com,  linux-kernel@vger.kernel.org
Subject: [PATCH 02/12] pinctrl: devicetree: Do not re-claim hogs for sibling devices
Date: Fri, 04 Dec 2026 22:38:30 -0800	[thread overview]
Message-ID: <20261204-pinctrl-fwnode-fix-v1-2-8589cbd35fb2@gmail.com> (raw)
In-Reply-To: <20261204-pinctrl-fwnode-fix-v1-0-8589cbd35fb2@gmail.com>

Self-referenced pin configurations on a pin controller's DT node are
hogs claimed by pinctrl_claim_hogs() when the controller is enabled.
During non-hog lookups for a sibling device sharing that DT node (such
as a gpio_device registered on the same node), dt_find_controller()
previously called get_pinctrl_dev_from_of_node() before checking whether
np_pctldev matches the device's own node, causing it to find the already
registered controller and fail with -EINVAL when trying to re-claim the
hogs.

Lift hog policy out of dt_find_controller() by having it stop and
return NULL at the caller's own node before consulting
get_pinctrl_dev_from_of_node(). In dt_to_map_one_config(), consumer
lookups skip self-referenced configs, while hog claiming maps only
configs belonging to hog_pctldev instead of registering dead external
maps into pinctrl_maps.

Fixes: b2083062a3b4 ("pinctrl: do not defer device tree hogs")
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/pinctrl/devicetree.c | 33 ++++++++++++++++++---------------
 1 file changed, 18 insertions(+), 15 deletions(-)

diff --git a/drivers/pinctrl/devicetree.c b/drivers/pinctrl/devicetree.c
index 69e701cb9c1f..f61a8c75e9e2 100644
--- a/drivers/pinctrl/devicetree.c
+++ b/drivers/pinctrl/devicetree.c
@@ -111,9 +111,8 @@ struct pinctrl_dev *of_pinctrl_get(struct device_node *np)
 }
 EXPORT_SYMBOL_GPL(of_pinctrl_get);
 
-static struct pinctrl_dev *dt_find_controller(struct pinctrl *p,
-					      struct pinctrl_dev *hog_pctldev,
-					      struct device_node *np_config)
+static struct pinctrl_dev *dt_find_controller(struct device_node *np_config,
+					      const struct device_node *stop_node)
 {
 	struct device_node *np_pctldev __free(device_node) = of_node_get(np_config);
 	struct pinctrl_dev *pctldev;
@@ -130,19 +129,11 @@ static struct pinctrl_dev *dt_find_controller(struct pinctrl *p,
 				return ERR_PTR(-EPROBE_DEFER);
 			return ERR_PTR(-ENODEV);
 		}
-		/* If we're creating a hog we can use the passed pctldev */
-		if (hog_pctldev && np_pctldev == p->dev->of_node)
-			return hog_pctldev;
+		if (np_pctldev == stop_node)
+			return NULL;
 		pctldev = get_pinctrl_dev_from_of_node(np_pctldev);
 		if (pctldev)
 			return pctldev;
-		/*
-		 * Do not defer probing of hogs (circular loop).
-		 *
-		 * Return NULL to let the caller skip self-referenced configs.
-		 */
-		if (np_pctldev == p->dev->of_node)
-			return NULL;
 	}
 }
 
@@ -157,11 +148,23 @@ static int dt_to_map_one_config(struct pinctrl *p,
 	struct pinctrl_map *map;
 	unsigned int num_maps;
 
-	pctldev = dt_find_controller(p, hog_pctldev, np_config);
+	pctldev = dt_find_controller(np_config, p->dev->of_node);
 	if (IS_ERR(pctldev))
 		return PTR_ERR(pctldev);
-	if (!pctldev)
+	if (!pctldev) {
+		/*
+		 * Self-referenced configs are hogs (or belong to an unregistered
+		 * child controller). Use hog_pctldev during hog claiming
+		 * (not on pinctrldev_list yet), or skip on normal lookups to
+		 * avoid circular deferral and sibling re-claiming of hogs.
+		 */
+		if (!hog_pctldev)
+			return 0;
+		pctldev = hog_pctldev;
+	} else if (hog_pctldev) {
+		/* Skip external controller configs while claiming hogs */
 		return 0;
+	}
 
 	/*
 	 * Call pinctrl driver to parse device tree node, and

-- 
2.56.1.987.g2ec0ab4260-goog


  parent reply	other threads:[~2026-12-05  6:39 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-05  6:38 [PATCH 00/12] pinctrl: Fix firmware node reference count underflows Dmitry Torokhov
2026-12-05  6:38 ` [PATCH 01/12] pinctrl: devicetree: Factor out dt_find_controller() helper Dmitry Torokhov
2026-12-05 12:01   ` Andy Shevchenko
2026-12-05  6:38 ` Dmitry Torokhov [this message]
2026-12-05  6:38 ` [PATCH 03/12] pinctrl: Add optional fwnode to struct pinctrl_desc Dmitry Torokhov
2026-12-05 12:07   ` Andy Shevchenko
2026-12-05  6:38 ` [PATCH 04/12] pinctrl: da9062: Fix firmware node reference count underflow Dmitry Torokhov
2026-12-05  6:38 ` [PATCH 05/12] pinctrl: as3722: " Dmitry Torokhov
2026-12-05  6:38 ` [PATCH 06/12] pinctrl: max77620: " Dmitry Torokhov
2026-12-05  6:38 ` [PATCH 07/12] pinctrl: madera: " Dmitry Torokhov
2026-12-05  6:38 ` [PATCH 08/12] pinctrl: rk805: " Dmitry Torokhov
2026-12-05  6:38 ` [PATCH 09/12] pinctrl: pef2256: " Dmitry Torokhov
2026-12-05  6:38 ` [PATCH 10/12] pinctrl: cirrus: cs42l43: " Dmitry Torokhov
2026-12-05  6:38 ` [PATCH 11/12] pinctrl: max7360: Pass parent fwnode via pinctrl_desc Dmitry Torokhov
2026-12-05  6:38 ` [PATCH 12/12] pinctrl: ep93xx: " Dmitry Torokhov

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=20261204-pinctrl-fwnode-fix-v1-2-8589cbd35fb2@gmail.com \
    --to=dmitry.torokhov@gmail.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=brgl@kernel.org \
    --cc=chenjh@rock-chips.com \
    --cc=chleroy@kernel.org \
    --cc=ckeepax@opensource.cirrus.com \
    --cc=david.rhodes@cirrus.com \
    --cc=heiko@sntech.de \
    --cc=herve.codina@bootlin.com \
    --cc=ldewangan@nvidia.com \
    --cc=lee@kernel.org \
    --cc=linusw@kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=mathieu.dubois-briand@bootlin.com \
    --cc=nikita.shubin@maquefel.me \
    --cc=patches@opensource.cirrus.com \
    --cc=rf@opensource.cirrus.com \
    --cc=support.opensource@diasemi.com \
    --cc=vulab@iscas.ac.cn \
    /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®