Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.180 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796452763; b=KgBuuukG+Y7x72BgSWdd+kStImzf1H8+2dAG2wBPS8YPHRVRm09jTqSWwEUAcUZPhqrx LuhHK9YVRNVdZRe6VZTB4NYLrBmZv2YndF1aSO63MEAqv0al0xzSfkqeqKWg8e2WVWSd3 ZG9BgF+ziDxzxSqxyWs7RB4NWBZL+hcqU2rhmH/h3vEjVxKQLo2caSgPMzJy5bNO0mhQg GQ1mnjvLcBdgxVECQG1+yT8xArzbkAHuwflrlm/8LI1cnU8MtjhyK/TtHUbiLX/HbkkHT 6zrXZdlbbuVsddvdNv51AmqM9eB3TFHPrad31fFqW+kyWXVJYWzk7rFRPhoxQguMU/Q== 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=HL6Ie6oRsfYoviEHsZBN+oaZRZkPHY0wQUaS/W/s3AxCGchJ223633c0sKyd//kJS17S w9eFHD1xupbEermDKFIvwcw9WRRBsIxHekLgV0ySEYfZsU8ciLD14YZyWKfFQxgx5P8IG Iz/s4HNKqQQChiT2ecaHD/HB7OY5rmF6YPv6wM+7FfijUArZSk7K1ZECBuid31TOYn2IY P7PSK190eMM0Q/jBACDgUOyARMSP4QuxqlVa0nHAEwZoOPvylexf/WbWDj2cpAJvPp49J voC1TDAGRydNFWxGDvbYzHduK16AlS5rW4BGlcKcD9JvZFk0lWUKX52In+/BoV/Gr2g== 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.180 Received: from mail-dy1-f180.google.com (mail-dy1-f180.google.com [74.125.82.180]) (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 A4D9A606A699 for ; Sat, 5 Dec 2026 06:39:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A4D9A606A699 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-f180.google.com with SMTP id 5a478bee46e88-3866a784546so2341800eec.0 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=igkwYVwF172UtOJr8nPNZY/rgTANP8huzG1CPPRSytOfzkTZLbM3adpNcLK4S7nAi3 AK2oVdeY84x6IuyGCvHsaOznUoh5fXMgC16KZMgITaS5wRKGbNEDuEUUDa/Oqg+4pUWa V4Bkrsa6Nr0p0vPvdepVKVhb6NrwW75EMBfy8sBwZj93yanQXwJptfcYgQN1TAuuz/4C Bz+7xxCzYGOmPIzwgFt/sDskaKHOyHOThlvOyiBRf4yeF+VAEyqouxclhEmFzE+P0lB0 1fZRiseTF1WK0jz17X0yBPh8RXaWlkNOkQc/rI17DVz6mqXVH5Kb9mMr3rxCvMBt0Q5K fKfA== X-Forwarded-Encrypted: i=1; AL+hErFfc3hWKCXmqDJ4s+cM7Zyq7dFsU8JNmg5Cx6nped+R4uxyQAQkC/g2DRg/wCi3A4/g7SBYUOqVUJoY@vger.kernel.org X-Gm-Message-State: AB4q+uF2mrz6eZlP7d1K9BBL+vV2R9KWE8ndMGTOk6vNN61BqcXfqDqJ HnJ4SAHwyRhj4VNmP3DQuRHa/YM0ZNQnk+QsDJM05z1YpkoQRxtEDgMB X-Gm-Gg: AZFdTZe1cihISy5XF+cdkeMWKOgEs4K4MN90rdWYNt4qFd84zIORCgKum2k8yyOkD4S in3JjG2bX+e1TLH0gFwHNC+nV5U3tZtT/hPKvc6pI4EoGmU6Fp1ya4KFeR1QP4lqb8jMMGjrRjh bkFSSbZc66zaV52rT1wdthRxX9fn0GyV3XbSxNt/wX/CJXG8PD3ZB1BwSIhSY0iSvxTdaAuklIO vQY2r92D3rIcq5uZjgBl068LaK0j6RfJEUwMRJWVMV0yP85YPEctkLnZipEpdjyYKWHEzCEPsjb jMF/+h7XAh0npl4oFC9PfnSyGYlhdb+mWzJe11qS18O4eYJDhMY+yQ2QTer0uY1T2IDvoXsx3tj Xsu/Y7WRLDjCO9cEY0KGHYnLR6msZEQJba5f9L2z7NMeAu0uDyzLsiwxaQmaxTHhxG8NhfmxdWq pDQGz3a7ybQoLOkbspKtTDRIiaRwZ7XJoxZMw9ctzCAWscjswz+bkMwHlyrqXHySy5Iygo5QZ42 MftWnM75fB4RBeOZyz/U9MIgTX9XpBeBSEFOo4UAcWoU7iVM35D6DF/iAx7Nx5ZW8hC/ZGqceyJ 62ukGSZwE+1YeF2e4rvmjGdx7sA8tc2PNyChFp8WmbabSz4BTffxV5CvoiIV5Y7BQCF8Nu9Kwy6 tr2YJGXpCsBSHeGMnNg== 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-gpio@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