From nobody Thu Dec 18 13:32:13 2025 Received: from out-189.mta1.migadu.com (out-189.mta1.migadu.com [95.215.58.189]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5E3B7224252 for ; Mon, 7 Apr 2025 22:37:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.189 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744065448; cv=none; b=eJoEt8exLeUlYQqLP5iT22UgGPAFev1bdQz0uwwK+tCq7T28F5ewwMyFsHYJZm0d/p4hWlI530lTlbIwEJNAnxKoQ7XLiRLyX8TPM+3t8yyuQEF+Hpgz+dzF0CgsRjcPjlX5UT4TP+V6ygkpUTWo5ZW87uFWpUr8ntP5ZXI/3dE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744065448; c=relaxed/simple; bh=MQM1kmIoyeIPIvXSo+fdLdzfUuOIRsInGoIf6OY/FxA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=sl041RmyCXQy9RVcw24CVjZz2kE2lwjl9jOMpYxX+8ye9Fy7OLWF+WpJaAGg2UNCF2AiOuEPPogyX1s/6zbVL3DtZmBGmB0u/ZPdn3DdgE/zIbCSozVKeDNSIlsiBVum/mdbgm7WbpSKAJhpWOpiPdGqA72SY3tXioI6La//i28= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=E/gjyn3e; arc=none smtp.client-ip=95.215.58.189 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="E/gjyn3e" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1744065443; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0XQwgBGUl+kN6A+/kOzVZipYCaxZjyIp9j83vL3Yths=; b=E/gjyn3eXJgs6JaLMvFqLeCUH5QHFYamcevGa6Rr4uF4/gIcHmdh1mHQsIne5nw1xa7BZq XkcMcI+hIjtFacsTC3HG80QvRF75Dif0ywvGrW9uzwAgHqWt6IrmZXDZb15KZJnIpo60fM GWzH3uDint/eKFdS3qez3rZrj0hW31o= From: Sean Anderson To: Rob Herring , Saravana Kannan , devicetree@vger.kernel.org Cc: Sakari Ailus , Greg Kroah-Hartman , "Rafael J . Wysocki" , Andy Shevchenko , Len Brown , Heikki Krogerus , Daniel Scally , linux-kernel@vger.kernel.org, Danilo Krummrich , linux-acpi@vger.kernel.org, Sean Anderson Subject: [PATCH 1/2] device property: Add optional nargs_prop for get_reference_args Date: Mon, 7 Apr 2025 18:37:13 -0400 Message-Id: <20250407223714.2287202-2-sean.anderson@linux.dev> In-Reply-To: <20250407223714.2287202-1-sean.anderson@linux.dev> References: <20250407223714.2287202-1-sean.anderson@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" get_reference_args does not permit falling back to nargs when nargs_prop is missing. This makes it difficult to support older devicetrees where nargs_prop may not be present. Add support for this by converting nargs to a signed value. Where before nargs was ignored if nargs_prop was passed, now nargs is only ignored if it is strictly negative. When it is positive, nargs represents the fallback cells to use if nargs_prop is absent. Signed-off-by: Sean Anderson --- drivers/base/property.c | 4 ++-- drivers/base/swnode.c | 13 +++++++++---- drivers/of/property.c | 10 +++------- include/linux/fwnode.h | 2 +- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/drivers/base/property.c b/drivers/base/property.c index c1392743df9c..049f8a6088a1 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -606,7 +606,7 @@ int fwnode_property_get_reference_args(const struct fwn= ode_handle *fwnode, return -ENOENT; =20 ret =3D fwnode_call_int_op(fwnode, get_reference_args, prop, nargs_prop, - nargs, index, args); + nargs_prop ? -1 : nargs, index, args); if (ret =3D=3D 0) return ret; =20 @@ -614,7 +614,7 @@ int fwnode_property_get_reference_args(const struct fwn= ode_handle *fwnode, return ret; =20 return fwnode_call_int_op(fwnode->secondary, get_reference_args, prop, na= rgs_prop, - nargs, index, args); + nargs_prop ? -1 : nargs, index, args); } EXPORT_SYMBOL_GPL(fwnode_property_get_reference_args); =20 diff --git a/drivers/base/swnode.c b/drivers/base/swnode.c index b1726a3515f6..11af2001478f 100644 --- a/drivers/base/swnode.c +++ b/drivers/base/swnode.c @@ -503,7 +503,7 @@ software_node_get_named_child_node(const struct fwnode_= handle *fwnode, static int software_node_get_reference_args(const struct fwnode_handle *fwnode, const char *propname, const char *nargs_prop, - unsigned int nargs, unsigned int index, + int nargs, unsigned int index, struct fwnode_reference_args *args) { struct swnode *swnode =3D to_swnode(fwnode); @@ -543,10 +543,15 @@ software_node_get_reference_args(const struct fwnode_= handle *fwnode, error =3D property_entry_read_int_array(ref->node->properties, nargs_prop, sizeof(u32), &nargs_prop_val, 1); - if (error) + + if (error =3D=3D -EINVAL) { + if (nargs < 0) + return error; + } else if (error) { return error; - - nargs =3D nargs_prop_val; + } else { + nargs =3D nargs_prop_val; + } } =20 if (nargs > NR_FWNODE_REFERENCE_ARGS) diff --git a/drivers/of/property.c b/drivers/of/property.c index c1feb631e383..c41190e47111 100644 --- a/drivers/of/property.c +++ b/drivers/of/property.c @@ -1116,19 +1116,15 @@ of_fwnode_get_named_child_node(const struct fwnode_= handle *fwnode, static int of_fwnode_get_reference_args(const struct fwnode_handle *fwnode, const char *prop, const char *nargs_prop, - unsigned int nargs, unsigned int index, + int nargs, unsigned int index, struct fwnode_reference_args *args) { struct of_phandle_args of_args; unsigned int i; int ret; =20 - if (nargs_prop) - ret =3D of_parse_phandle_with_args(to_of_node(fwnode), prop, - nargs_prop, index, &of_args); - else - ret =3D of_parse_phandle_with_fixed_args(to_of_node(fwnode), prop, - nargs, index, &of_args); + ret =3D __of_parse_phandle_with_args(to_of_node(fwnode), prop, nargs_prop, + nargs, index, &of_args); if (ret < 0) return ret; if (!args) { diff --git a/include/linux/fwnode.h b/include/linux/fwnode.h index 6fa0a268d538..69fe44c68f8c 100644 --- a/include/linux/fwnode.h +++ b/include/linux/fwnode.h @@ -163,7 +163,7 @@ struct fwnode_operations { const char *name); int (*get_reference_args)(const struct fwnode_handle *fwnode, const char *prop, const char *nargs_prop, - unsigned int nargs, unsigned int index, + int nargs, unsigned int index, struct fwnode_reference_args *args); struct fwnode_handle * (*graph_get_next_endpoint)(const struct fwnode_handle *fwnode, --=20 2.35.1.1320.gc452695387.dirty From nobody Thu Dec 18 13:32:13 2025 Received: from out-180.mta1.migadu.com (out-180.mta1.migadu.com [95.215.58.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4BF93225764 for ; Mon, 7 Apr 2025 22:37:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744065450; cv=none; b=jjigoSgJu1AEzVv45xxXWlewjAB9t943PtThMGIw7gmXbGK3ChhcrDMz73dHu2kOAEz9ujMIOUXuoscRGuj+QMsPgAWVFnxEZEukXWXBVevq/CQM8enL/DfbqD6FUUhTB6huJBF3PBV9QWw+mzv9xTIL7QePoeEU23ATOLE6v5Q= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1744065450; c=relaxed/simple; bh=0RHjy9Gg6nzpFP22nPWzgOuU/J8PO3od6y/zB6+i40s=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=icbOGc3rQJMhrr3/9RTtSKTLVllQSapnB8E2WJDU9+fTBZNXBa/ZL1SFCsUzyPKc0KrILn5AAsaXqt8svBu7ATL3Kk7qGC95kJlyRqKjRaukJ/Qwlfb9na3mI4gu0m0mNCeSR+5Fl8vxSvS+1LajSMM/fn08mOIAtqW2xXvt1jo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=cwwfIZJ+; arc=none smtp.client-ip=95.215.58.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="cwwfIZJ+" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1744065445; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yk2gCjwLaBA+Rjb+sf0kBMe/pJVNSpY8xdwLZOARR5g=; b=cwwfIZJ+4EN/MW00GYI3Fqdg3mO0VDqKsbPsoPg7AOsNnOvDNdG/qyiQFr3hU+sobYHOKW mODovZPkwgn85/z6YOZTwenjMNG+TEN2bd3FKMmQDUaymcVWhr0LgMX0Ouywls/dqGg0I5 fhyIE7k+9ott7vlyz3ilQBL9ODOgbNg= From: Sean Anderson To: Rob Herring , Saravana Kannan , devicetree@vger.kernel.org Cc: Sakari Ailus , Greg Kroah-Hartman , "Rafael J . Wysocki" , Andy Shevchenko , Len Brown , Heikki Krogerus , Daniel Scally , linux-kernel@vger.kernel.org, Danilo Krummrich , linux-acpi@vger.kernel.org, Sean Anderson Subject: [PATCH 2/2] device property: Add fwnode_property_get_reference_optional_args Date: Mon, 7 Apr 2025 18:37:14 -0400 Message-Id: <20250407223714.2287202-3-sean.anderson@linux.dev> In-Reply-To: <20250407223714.2287202-1-sean.anderson@linux.dev> References: <20250407223714.2287202-1-sean.anderson@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Migadu-Flow: FLOW_OUT Content-Type: text/plain; charset="utf-8" Add a fwnode variant of of_parse_phandle_with_optional_args to allow nargs_prop to be absent from the referenced node. This improves compatibility for references where the devicetree might not always have nargs_prop. Signed-off-by: Sean Anderson --- drivers/base/property.c | 46 ++++++++++++++++++++++++++++++++++++++++ include/linux/property.h | 4 ++++ 2 files changed, 50 insertions(+) diff --git a/drivers/base/property.c b/drivers/base/property.c index 049f8a6088a1..ef13ca32079b 100644 --- a/drivers/base/property.c +++ b/drivers/base/property.c @@ -618,6 +618,52 @@ int fwnode_property_get_reference_args(const struct fw= node_handle *fwnode, } EXPORT_SYMBOL_GPL(fwnode_property_get_reference_args); =20 +/** + * fwnode_property_get_reference_optional_args() - Find a reference with o= ptional arguments + * @fwnode: Firmware node where to look for the reference + * @prop: The name of the property + * @nargs_prop: The name of the property telling the number of + * arguments in the referred node. + * @index: Index of the reference, from zero onwards. + * @args: Result structure with reference and integer arguments. + * May be NULL. + * + * Obtain a reference based on a named property in an fwnode, with + * integer arguments. If @nargs_prop is absent from the referenced node, t= hen + * number of arguments is be assumed to be 0. + * + * The caller is responsible for calling fwnode_handle_put() on the return= ed + * @args->fwnode pointer. + * + * Return: %0 on success + * %-ENOENT when the index is out of bounds, the index has an empty + * reference or the property was not found + * %-EINVAL on parse error + */ +int fwnode_property_get_reference_optional_args(const struct fwnode_handle= *fwnode, + const char *prop, + const char *nargs_prop, + unsigned int index, + struct fwnode_reference_args *args) +{ + int ret; + + if (IS_ERR_OR_NULL(fwnode)) + return -ENOENT; + + ret =3D fwnode_call_int_op(fwnode, get_reference_args, prop, nargs_prop, + 0, index, args); + if (ret =3D=3D 0) + return ret; + + if (IS_ERR_OR_NULL(fwnode->secondary)) + return ret; + + return fwnode_call_int_op(fwnode->secondary, get_reference_args, prop, na= rgs_prop, + 0, index, args); +} +EXPORT_SYMBOL_GPL(fwnode_property_get_reference_optional_args); + /** * fwnode_find_reference - Find named reference to a fwnode_handle * @fwnode: Firmware node where to look for the reference diff --git a/include/linux/property.h b/include/linux/property.h index e214ecd241eb..a1662b36d15f 100644 --- a/include/linux/property.h +++ b/include/linux/property.h @@ -139,6 +139,10 @@ int fwnode_property_get_reference_args(const struct fw= node_handle *fwnode, const char *prop, const char *nargs_prop, unsigned int nargs, unsigned int index, struct fwnode_reference_args *args); +int fwnode_property_get_reference_optional_args(const struct fwnode_handle= *fwnode, + const char *prop, const char *nargs_prop, + unsigned int index, + struct fwnode_reference_args *args); =20 struct fwnode_handle *fwnode_find_reference(const struct fwnode_handle *fw= node, const char *name, --=20 2.35.1.1320.gc452695387.dirty