From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.174 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796452763; b=aQrm8K5tPqftN9tuXzq4mJFhQNFCjN6KQaFWNn4hI80JqUo0Uq9eESLvRFWjDvjuLCaq ZCSscN6Z2He0jqls+yhZPwmzrYr6Y0OR0SzXmMxjcTBQeq9OzGZb9WgMs3FxPEGqEXSH3 v/edHqdZaEmT7TS0PupqXcMH9uflXvgv47d22f1VJ9ezzj4Vmthuql38rywoK3w42636k Nj0U4Fgz4EJ5nQza4PbZFXym2xCRl2yrZqfAs8Oli0BQCMoXenEwL7VfWeE39ySTpO1kp 2w9sBQFK/oE2Mxs04YpXePpNUFEoRy4e7ze0KuGJVm0qb1CJsx5wnhMeuLiRtxXkUww== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796452763; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:Date:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding: Message-Id:References:In-Reply-To:To:Cc:X-Mailer; bh=3zPbW8+Xl/A+tn796DKfG+WVcR+r52/nq7LlicVX3x4=; b=wFprt/6do/CYo2wiW5EeeIptvIHFJmIFPGluufPVsOnznCQnWAfud3EUqPI6UL67Yn+M upgUReS8djBdhFyxSNYhjJz8xFMY2z4L38HJ3qJFaVGLNx4qFXMDEsqmCOqvIiiK13wPo QXjTCDubB94WvE06+2Cj0GmP0fH9j2aTl8goV3wEABmf0lsA+hZIyQHBCjCb1OjXvUt+r fEvNWjIbci0jGQ1ldtleoWtGereDjSxB64/TiiEKGjw/6mXhar9Hn/bK9HTop2UjT0qGW QbIE0lY9QIDNjVXNns+KKNLDALsSlZfim6q+yn8y8gPBPAD17QfnCIijV9wGqmYgR2w== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=M35AQVRR; arc=none smtp.remote-ip=74.125.82.174 Received: from mail-dy1-f174.google.com (mail-dy1-f174.google.com [74.125.82.174]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B3608606A681 for ; Sat, 5 Dec 2026 06:39:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org B3608606A681 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=M35AQVRR Received: by mail-dy1-f174.google.com with SMTP id 5a478bee46e88-386ab9ab619so2761785eec.1 for ; Fri, 04 Dec 2026 22:39:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796452762; x=1797057562; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=3zPbW8+Xl/A+tn796DKfG+WVcR+r52/nq7LlicVX3x4=; b=M35AQVRRPkzHFWZYNyDDETRUpL2xAyQ73RjjELMj00Dz8QjOScI3z8zJNZzXC3HA1l bcb2LdppI0nCwLWQRg+hE/6Roub6olaYzj5gfKl8gSkrUe2vBoyn89v+nD7rkzePEnI2 ph8K+s6560KnSmmlbqb31VLwsn43N0akOC+skK3PmJSmjGwogGYzH1W52TKww1UzrJbw xm6sVlVMraoqvhqvET3fK6i8zaL3r2w/DpCSC1JHj08qwuzh8p5gl9u75qkzczjKV7+0 BmcC+FBHzEnfS2uYFQWCDpvdN/461CBXRN9RGjCwbyzVMOp2UtLNM5Mfk9ubViFy/Hkk 93Yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796452762; x=1797057562; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :content-type:mime-version:subject:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=3zPbW8+Xl/A+tn796DKfG+WVcR+r52/nq7LlicVX3x4=; b=J7h6R9FdC5S8rmqc84LA83hb6GSDiyDaEV0KUiKYpWQRtEkHpISCGOuS0q5llgvkRC ZM4adIX3TqlH3k2a+mH4kRZt9bubkM38V9NWtsuNt2SNR2J9O9ELJHmvkOrd/LVQ5zlR Ig81fx3k0LXVrrR2D3bfvix0j6aBjIlIPflWoWh9cCKs059n9vfyFBXL5CTOasGS3Jat XYy7vu6EmpUKjn9NR8fr5IVOKXNq4DwBnurTD55XYmgqFO4B981NhcNYrQ4TLmFsqCdD osXGNlbOyrevWyp7zpCzXYHJYtk62STvFCqoaCZAmBRLFEyeEyxoRNN5gyy58W1b7T8R rVjQ== X-Forwarded-Encrypted: i=1; AL+hErFVgPwvGmMBL6JWFKhA3RF+0wkSa7oTlVS8UABJlsvQYA13qaXITXjKEv6OUTDkhPMjIe0VPB2Q4y44P80=@vger.kernel.org X-Gm-Message-State: AB4q+uFclr/RkkxVGGuSHs0WBLeoCpjQ4H6c3ZCdvF+D5SS3cgoRyZ1z k6WLHK8g5RSoYWqAGWHTyIR0sL6ER07ZXH9H6J7Sk3ifvS4JnJtNiMz5 X-Gm-Gg: AZFdTZcqiR7WitLCi26xSDFYcfnpP9YE93e9nvvL2FTaKj+SOQPIODdnn2O+Up5T5Eg vz2jJt+toPP3P5b8B0yS8aToMf327RXxsWhhg/Jne9kieNOVvs0gag1Fa6CNW03qD8oDMX931hK 0il29G3ybfMbnmRmue7AVpi5l4SORzus93EhecJk9IuBFDbZI44YCIjQ42WDYnjLa7Acx5g0zEf NEvMAuDCTEuKRxKtTA949YMR2bAqoUS0L8FP4C4mdH03/Fv3EPEg9+r65RyWG50ftoZipxj5GE7 trmr5a43vgccKGUte9fDDiIoMFqJUUI1rgen0jzBMNdwPPew2bd6iN+9Jfqfg3STFJXXoJuFKSi 3yPUy24QO413N26ATr+6cxGCQWVyV3VUFOiw6F1bkFIVXwdR4mX2mn9whW838TdW3oc+Bn1qYRu oo4ZJMGRbHZkQsomAWa4hs4A4Or+4P5lH6GGed8JVULNHY10u3wXzRumAmR6K5BoX8SnSonINzz la33ga+36e8ARDmAwZo8HoiV1ThJHXa4NLtIVHTbkWWhu0VOIRkH4U7CO6/2900Yj3ud2ox3FTx ah78i5HzJAgdar7qNNwfOss9vGvLDSHtwn8CB0QU+XdH7vpZlsC12L+h9IXoj76Ant5K67Wwwhx hGQP+/P1BqfcN1SxWNA== X-Received: by 2002:a05:7300:ed85:b0:387:43ad:1d4c with SMTP id 5a478bee46e88-387520b0abbmr5416227eec.7.1796452761632; Fri, 04 Dec 2026 22:39:21 -0800 (PST) Received: from dtor-ws.sjc.corp.google.com ([2a00:79e0:2ebe:8:17a1:4895:5021:5d36]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3875221a4a3sm14754370eec.24.2026.12.04.22.39.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 22:39:21 -0800 (PST) From: Dmitry Torokhov Date: Fri, 04 Dec 2026 22:38:31 -0800 Subject: [PATCH 03/12] pinctrl: Add optional fwnode to struct pinctrl_desc X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261204-pinctrl-fwnode-fix-v1-3-8589cbd35fb2@gmail.com> References: <20261204-pinctrl-fwnode-fix-v1-0-8589cbd35fb2@gmail.com> In-Reply-To: <20261204-pinctrl-fwnode-fix-v1-0-8589cbd35fb2@gmail.com> To: Support Opensource , Linus Walleij , Charles Keepax , Andy Shevchenko , Laxman Dewangan , Richard Fitzgerald , Lee Jones , Joseph Chen , Heiko Stuebner , Herve Codina , Christophe Leroy , David Rhodes , Mathieu Dubois-Briand , Nikita Shubin Cc: Bartosz Golaszewski , Haotian Zhang , linux-gpio@vger.kernel.org, linux-sound@vger.kernel.org, patches@opensource.cirrus.com, linux-kernel@vger.kernel.org X-Mailer: b4 0.17-dev Pin controller drivers for MFD or auxiliary sub-devices often need to associate their controller with a parent or child firmware node for DT lookups and hog parsing. Attaching that node directly to the live device during probe mutates dev->fwnode and dev->of_node concurrently with readers such as uevent_show() and leads to reference count underflows, leaks, or rebind conflicts on release. Add an optional fwnode field to struct pinctrl_desc so drivers can supply a controller firmware node directly, mirroring struct gpio_chip. Keep the pinctrl core DT-agnostic by holding firmware node references in struct pinctrl_dev and struct pinctrl, replacing get_pinctrl_dev_from_of_node() with get_pinctrl_dev_from_fwnode(), and updating devicetree.c to convert between struct device_node and struct fwnode_handle. Release both references before freeing the structs on teardown. Signed-off-by: Dmitry Torokhov --- drivers/pinctrl/core.c | 18 ++++++++++++++---- drivers/pinctrl/core.h | 10 ++++++++-- drivers/pinctrl/devicetree.c | 19 +++++++------------ include/linux/pinctrl/pinctrl.h | 5 +++++ 4 files changed, 34 insertions(+), 18 deletions(-) diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c index 4968747a9650..df328ec5db25 100644 --- a/drivers/pinctrl/core.c +++ b/drivers/pinctrl/core.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -121,14 +122,17 @@ struct pinctrl_dev *get_pinctrl_dev_from_devname(const char *devname) return NULL; } -struct pinctrl_dev *get_pinctrl_dev_from_of_node(struct device_node *np) +struct pinctrl_dev *get_pinctrl_dev_from_fwnode(const struct fwnode_handle *fwnode) { struct pinctrl_dev *pctldev; + if (!fwnode) + return NULL; + mutex_lock(&pinctrldev_list_mutex); list_for_each_entry(pctldev, &pinctrldev_list, node) - if (device_match_of_node(pctldev->dev, np)) { + if (pctldev->fwnode == fwnode) { mutex_unlock(&pinctrldev_list_mutex); return pctldev; } @@ -1111,11 +1115,13 @@ static struct pinctrl *create_pinctrl(struct device *dev, if (!p) return ERR_PTR(-ENOMEM); p->dev = dev; + p->fwnode = fwnode_handle_get(pctldev ? pctldev->fwnode : dev_fwnode(dev)); INIT_LIST_HEAD(&p->states); INIT_LIST_HEAD(&p->dt_maps); ret = pinctrl_dt_to_map(p, pctldev); if (ret < 0) { + fwnode_handle_put(p->fwnode); kfree(p); return ERR_PTR(ret); } @@ -1242,6 +1248,7 @@ static void pinctrl_free(struct pinctrl *p, bool inlist) if (inlist) list_del(&p->node); + fwnode_handle_put(p->fwnode); kfree(p); mutex_unlock(&pinctrl_list_mutex); } @@ -2157,6 +2164,7 @@ pinctrl_init_controller(const struct pinctrl_desc *pctldesc, struct device *dev, INIT_LIST_HEAD(&pctldev->gpio_ranges); INIT_LIST_HEAD(&pctldev->node); pctldev->dev = dev; + pctldev->fwnode = fwnode_handle_get(pctldesc->fwnode ?: dev_fwnode(dev)); mutex_init(&pctldev->mutex); /* check core ops for sanity */ @@ -2194,6 +2202,7 @@ pinctrl_init_controller(const struct pinctrl_desc *pctldesc, struct device *dev, out_err: mutex_destroy(&pctldev->mutex); + fwnode_handle_put(pctldev->fwnode); kfree(pctldev); return ERR_PTR(ret); } @@ -2201,9 +2210,9 @@ pinctrl_init_controller(const struct pinctrl_desc *pctldesc, struct device *dev, static void pinctrl_uninit_controller(struct pinctrl_dev *pctldev, const struct pinctrl_desc *pctldesc) { - pinctrl_free_pindescs(pctldev, pctldesc->pins, - pctldesc->npins); + pinctrl_free_pindescs(pctldev, pctldesc->pins, pctldesc->npins); mutex_destroy(&pctldev->mutex); + fwnode_handle_put(pctldev->fwnode); kfree(pctldev); } @@ -2361,6 +2370,7 @@ void pinctrl_unregister(struct pinctrl_dev *pctldev) mutex_unlock(&pctldev->mutex); mutex_destroy(&pctldev->mutex); + fwnode_handle_put(pctldev->fwnode); kfree(pctldev); mutex_unlock(&pinctrldev_list_mutex); } diff --git a/drivers/pinctrl/core.h b/drivers/pinctrl/core.h index fc513a9cdd4f..2ac402788463 100644 --- a/drivers/pinctrl/core.h +++ b/drivers/pinctrl/core.h @@ -18,7 +18,7 @@ struct dentry; struct device; -struct device_node; +struct fwnode_handle; struct module; struct pinctrl; @@ -40,6 +40,8 @@ struct pinctrl_state; * @gpio_ranges: a list of GPIO ranges that is handled by this pin controller, * ranges are added to this list at runtime * @dev: the device entry for this pin controller + * @fwnode: firmware node for this pin controller; reference held until + * unregistration * @owner: module providing the pin controller, used for refcounting * @driver_data: driver data for drivers registering to the pin controller * subsystem @@ -63,6 +65,7 @@ struct pinctrl_dev { #endif struct list_head gpio_ranges; struct device *dev; + struct fwnode_handle *fwnode; struct module *owner; void *driver_data; struct pinctrl *p; @@ -78,6 +81,8 @@ struct pinctrl_dev { * struct pinctrl - per-device pin control state holder * @node: global list node * @dev: the device using this pin control handle + * @fwnode: firmware node for this handle; reference held for the handle's + * lifetime * @states: a list of states for this device * @state: the current state * @dt_maps: the mapping table chunks dynamically parsed from device tree for @@ -87,6 +92,7 @@ struct pinctrl_dev { struct pinctrl { struct list_head node; struct device *dev; + struct fwnode_handle *fwnode; struct list_head states; struct pinctrl_state *state; struct list_head dt_maps; @@ -236,7 +242,7 @@ int pinctrl_generic_remove_group(struct pinctrl_dev *pctldev, #endif /* CONFIG_GENERIC_PINCTRL_GROUPS */ struct pinctrl_dev *get_pinctrl_dev_from_devname(const char *dev_name); -struct pinctrl_dev *get_pinctrl_dev_from_of_node(struct device_node *np); +struct pinctrl_dev *get_pinctrl_dev_from_fwnode(const struct fwnode_handle *fwnode); int pin_get_from_name(struct pinctrl_dev *pctldev, const char *name); const char *pin_get_name(struct pinctrl_dev *pctldev, const unsigned int pin); int pinctrl_get_group_selector(struct pinctrl_dev *pctldev, diff --git a/drivers/pinctrl/devicetree.c b/drivers/pinctrl/devicetree.c index f61a8c75e9e2..ce7176636b68 100644 --- a/drivers/pinctrl/devicetree.c +++ b/drivers/pinctrl/devicetree.c @@ -59,8 +59,6 @@ void pinctrl_dt_free_maps(struct pinctrl *p) dt_map->num_maps); kfree(dt_map); } - - of_node_put(p->dev->of_node); } static int dt_remember_or_free_map(struct pinctrl *p, const char *statename, @@ -107,12 +105,12 @@ static int dt_remember_or_free_map(struct pinctrl *p, const char *statename, struct pinctrl_dev *of_pinctrl_get(struct device_node *np) { - return get_pinctrl_dev_from_of_node(np); + return get_pinctrl_dev_from_fwnode(of_fwnode_handle(np)); } EXPORT_SYMBOL_GPL(of_pinctrl_get); static struct pinctrl_dev *dt_find_controller(struct device_node *np_config, - const struct device_node *stop_node) + const struct fwnode_handle *stop_fwnode) { struct device_node *np_pctldev __free(device_node) = of_node_get(np_config); struct pinctrl_dev *pctldev; @@ -129,9 +127,9 @@ static struct pinctrl_dev *dt_find_controller(struct device_node *np_config, return ERR_PTR(-EPROBE_DEFER); return ERR_PTR(-ENODEV); } - if (np_pctldev == stop_node) + if (of_fwnode_handle(np_pctldev) == stop_fwnode) return NULL; - pctldev = get_pinctrl_dev_from_of_node(np_pctldev); + pctldev = get_pinctrl_dev_from_fwnode(of_fwnode_handle(np_pctldev)); if (pctldev) return pctldev; } @@ -148,7 +146,7 @@ static int dt_to_map_one_config(struct pinctrl *p, struct pinctrl_map *map; unsigned int num_maps; - pctldev = dt_find_controller(np_config, p->dev->of_node); + pctldev = dt_find_controller(np_config, p->fwnode); if (IS_ERR(pctldev)) return PTR_ERR(pctldev); if (!pctldev) { @@ -210,7 +208,7 @@ static int dt_remember_dummy_state(struct pinctrl *p, const char *statename) int pinctrl_dt_to_map(struct pinctrl *p, struct pinctrl_dev *pctldev) { - struct device_node *np = p->dev->of_node; + struct device_node *np = to_of_node(p->fwnode); int state, ret; char *propname; struct property *prop; @@ -220,7 +218,7 @@ int pinctrl_dt_to_map(struct pinctrl *p, struct pinctrl_dev *pctldev) phandle phandle; struct device_node *np_config; - /* CONFIG_OF enabled, p->dev not instantiated from DT */ + /* CONFIG_OF enabled, no DT node on device or pctldev->fwnode */ if (!np) { if (of_have_populated_dt()) dev_dbg(p->dev, @@ -228,9 +226,6 @@ int pinctrl_dt_to_map(struct pinctrl *p, struct pinctrl_dev *pctldev) return 0; } - /* We may store pointers to property names within the node */ - of_node_get(np); - /* For each defined state ID */ for (state = 0; ; state++) { /* Retrieve the pinctrl-* property */ diff --git a/include/linux/pinctrl/pinctrl.h b/include/linux/pinctrl/pinctrl.h index c329cc693139..82689052c4c1 100644 --- a/include/linux/pinctrl/pinctrl.h +++ b/include/linux/pinctrl/pinctrl.h @@ -16,6 +16,7 @@ struct device; struct device_node; +struct fwnode_handle; struct gpio_chip; struct module; struct seq_file; @@ -143,6 +144,9 @@ struct pinctrl_ops { * the hardware description * @custom_conf_items: Information how to print @params in debugfs, must be * the same size as the @custom_params, i.e. @num_custom_params + * @fwnode: Optional firmware node for the pin controller. If unset, + * the core falls back to the firmware node of the parent device. + * The core acquires its own reference to the node. * @link_consumers: If true create a device link between pinctrl and its * consumers (i.e. the devices requesting pin control states). This is * sometimes necessary to ascertain the right suspend/resume order for @@ -161,6 +165,7 @@ struct pinctrl_desc { const struct pinconf_generic_params *custom_params; const struct pin_config_item *custom_conf_items; #endif + struct fwnode_handle *fwnode; bool link_consumers; }; -- 2.56.1.987.g2ec0ab4260-goog