From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-dy1-f171.google.com (mail-dy1-f171.google.com [74.125.82.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4AEBC8632B for ; Tue, 24 Mar 2026 04:46:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774327619; cv=none; b=a9f5cTMiUaRL2pZTXHU+X2PxupqWwzhiJDlOTkkgyBgDTotoxjvP6eCMKihDsV7IYosBM+R/6fcUi/Tn3Gu1cBcSJQztm6PHY/Dic/dRkjd3fjHnQdrxZ3+eiT3SCbb23FyaY4BQwxF+hbEfx5MkoCToD/0ClssDBYzFvDb8WsA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774327619; c=relaxed/simple; bh=S4LmDD5N7YorWQUk0CYhBh+UXavWKeyPWNH2i6t9Gjk=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=C7NqiXAIABhwORz/xKCKg/FVFe13DLnqPsUNGHlgzybsNaWVAI4HMKlCVcGUZkEcc7QIpLhm9ySPIQTGMBDACm0i5aN5UcRVX/n18l/B0ZnC9DldaLtD+lbhSzMCa/69iaG+nJyNuvYqpqizDAqP8zwPzsaJ0oGFu4A4VuNArYg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=h1tZ1rmq; arc=none smtp.client-ip=74.125.82.171 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.b="h1tZ1rmq" Received: by mail-dy1-f171.google.com with SMTP id 5a478bee46e88-2c0e3a2605fso1255773eec.0 for ; Mon, 23 Mar 2026 21:46:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774327616; x=1774932416; darn=vger.kernel.org; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date:message-id:reply-to; bh=4n4yln5k8cNFTolCtaKAVbNlkFjgerksTIKyF55kf7g=; b=h1tZ1rmqJKQ1VqLsvMFUqdCbD0VV7FlCr89jI/mM10cbSzXtGeAhkUpCtZ50PBNsl3 VRD8uRYKjcA1Uo3IZxDVoNawip4HgZt6vOEQwkaupbUbVXaYnRkPGgM1jXggwuJ3Icfy cEfBQ6XulzmuKn6CwgK98AFbD6/6UPL45HbcQV+LtztigeaRcoXHinhuTWqwloavXW8h Bfll1y2dSiY2iv8uhzUb+oSnzCxPumyXf6QKtJtFq83MUf+Bcmy1KNGsw/tovZT1pU60 Rg/cckOId7sHmT+igsPT8Hc4ZJSDvXZ28zOk+gxlXTFtJ0s2cfuTx1lbpfyAQkb9uHdc slKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774327616; x=1774932416; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=4n4yln5k8cNFTolCtaKAVbNlkFjgerksTIKyF55kf7g=; b=VMYsfc66VdB/VMAHir/XKdzGGqG8cx7MRlkVE2sS04lw713qhBRvzt4RlO3/48Njz0 2nlAamS70cCe5DB4cilXSWlCQKwb2boWndPJY2e2DkPi3Ey4fFBvjt9bVJWeUoDdyMQL 7UJQ6RKryqLpr4v/xAmUz/bB8xzAwMtkVlov+Ge3y+K6Wm2QIpol3BJTfiNA+o+jt4O1 0p11A3stiIsARt9y0JZY3wI03iXE1J+EnYMZ0d/3rVZzcYMbk4Ut7i1SI/ci/DHhTj67 ErRvBnCPdrQZA6iuyoQjUnFwXY9n68nTiq99bX6mn346AarqRyi2MkTMkyyiKx/hf7rv k30w== X-Forwarded-Encrypted: i=1; AJvYcCXM5ePxcxCFm0neta2AizF4jSUjF+To3v1+aGnU4X/d5OTh/OYtSE6I9Gledp9kQiGhkqQb54w8NC46GQw=@vger.kernel.org X-Gm-Message-State: AOJu0YytqoTsoj0IgCYwHl7ZGjcIIHiZTTS7+ZMkKy0YEZ6NabCwH9zU x+QiJ/433kId6A3hkcGBKmUXpIv0OLE+RJCiR9RAWhkKXh03YQsGQHrKQeOYTg== X-Gm-Gg: ATEYQzxnQAD+K98AA6k5GwgB1LhHg5kEnjJ9/5IAUsqRoCqnTaHU4l3OqUIjzpRe9xM hPEtZKBRvsGXKBDH+b0yTu/SqodFqsMH7fA7iNQVbVvse6WTYdrhB/gJ/waj1vb9N/Y2MFyL+5L /cTCqx8SC/HpPSbNFg77X1Cf3MBjd65WzpIUS4zIsWY2v7fPijISCLzuHGr2clw+gAPXskWsPGH f+P6/Mj1irRdmpGFKTo/ji/2P25aXA7S/hcly3lon0gTzXBIvJ0BJbyL2pw/HSa8YPwhQZfNQsh QspzWh2DstRdDYeHgJ4ZIZlBbVbikg3oC+KW/IOF/xeaJZLK81Z4RKZbBY/C7Pz7tg0a6CgIWvE znYcQ5HopoUushGlX+bvOSJ0/PZszYUiankVEFz/oyqM6uRhK0fCcLw7lK9AdscXUPAEEnSzScT Bs4b616AGDrIM9g5d/trg1LUQmIZSKpH7PoSMTuY9obNArx+X7F7PHdn/lmdyaASjcumG3/xE9o SQ= X-Received: by 2002:a05:7301:3f07:b0:2b8:30b8:58cf with SMTP id 5a478bee46e88-2c1095f867cmr6583342eec.8.1774327616075; Mon, 23 Mar 2026 21:46:56 -0700 (PDT) Received: from google.com ([2a00:79e0:2ebe:8:a296:1211:5ab0:bc95]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-2c1536aa870sm244833eec.2.2026.03.23.21.46.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2026 21:46:54 -0700 (PDT) Date: Mon, 23 Mar 2026 21:46:50 -0700 From: Dmitry Torokhov To: Greg Kroah-Hartman Cc: Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Bartosz Golaszewski , Greg Kroah-Hartman , Danilo Krummrich , "Rafael J. Wysocki" , linux-acpi@vger.kernel.org, driver-core@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH] software node: allow referencing software nodes by name Message-ID: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Currently static device properties references require either an instance of software node or an instance of fwnode_handle to be available when defining a reference property. This may not be very convenient when device node is instantiated from a different module (which is usually the case). The original implementation for describing GPIOs using software nodes worked around this by creating a detached from gpiochip instances software nodes, and performing matching using gpiochip label and node name. The gpiolib maintainers rightfully questioned this approach, and currently recommend to attach secondary software node to gpiochip instance, export the symbol, and use it in board file when instantiating static properties. This unfortunately results in tight coupling between gpiochip drivers and board code, necessitates creation of header files, requires adding Kconfig dependencies, limits options for choosing module vs built-in compilation, and alters device initialization/probing order. Solve the issue by providing an option to use software node name in place of the node instance when describing reference properties. When evaluating reference driver core will attempt to resolve the name to concrete node instance and, in case of GPIO references, will use identity match on firmware node to locate corresponding gpiochip device. This approach has a drawback of needing to know name of the node that gpiochip device will be using, however benefits (minimal coupling, no need for adding dependencies) outweigh this drawback. To deal cases with software nodes not being created or registered at time of look up, assume that the node with matching name will get registered eventually and return -EPROBE_DEFER in the meantime. Signed-off-by: Dmitry Torokhov --- drivers/base/swnode.c | 25 +++++++++++++++++++------ include/linux/property.h | 4 ++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c index 51320837f3a9..9903f252d1d6 100644 --- a/drivers/base/swnode.c +++ b/drivers/base/swnode.c @@ -510,7 +510,6 @@ software_node_get_reference_args(const struct fwnode_handle *fwnode, const struct software_node_ref_args *ref_array; const struct software_node_ref_args *ref; const struct property_entry *prop; - struct fwnode_handle *refnode; u32 nargs_prop_val; int error; int i; @@ -546,12 +545,26 @@ software_node_get_reference_args(const struct fwnode_handle *fwnode, * relevant properties and bump the reference count. */ - if (ref->swnode) - refnode = software_node_fwnode(ref->swnode); - else if (ref->fwnode) - refnode = ref->fwnode; - else + struct fwnode_handle *refnode __free(fwnode_handle) = NULL; + if (ref->swnode) { + refnode = fwnode_handle_get(software_node_fwnode(ref->swnode)); + } else if (ref->fwnode) { + refnode = fwnode_handle_get(ref->fwnode); + } else if (ref->swnode_name) { + const struct software_node *ref_swnode = + software_node_find_by_name(NULL, ref->swnode_name); + /* + * When using a name instead of a software node structure + * assume the node will appear at some point. + */ + if (!ref_swnode) + return -EPROBE_DEFER; + + /* Reference is already taken by software_node_find_by_name() */ + refnode = software_node_fwnode(ref_swnode); + } else { return -EINVAL; + } if (!refnode) return -ENOENT; diff --git a/include/linux/property.h b/include/linux/property.h index e30ef23a9af3..44e96ee47272 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -363,6 +363,7 @@ struct software_node; struct software_node_ref_args { const struct software_node *swnode; struct fwnode_handle *fwnode; + const char *swnode_name; unsigned int nargs; u64 args[NR_FWNODE_REFERENCE_ARGS]; }; @@ -373,6 +374,9 @@ struct software_node_ref_args { const struct software_node *: _ref_, \ struct software_node *: _ref_, \ default: NULL), \ + .swnode_name = _Generic(_ref_, \ + const char *: _ref_, \ + default: NULL), \ .fwnode = _Generic(_ref_, \ struct fwnode_handle *: _ref_, \ default: NULL), \ -- 2.53.0.1018.g2bb0e51243-goog -- Dmitry