mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Michael Walle <michael@walle.cc>
To: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Rob Herring <robh+dt@kernel.org>,
	Frank Rowand <frowand.list@gmail.com>,
	Michael Walle <michael@walle.cc>, Rob Herring <robh@kernel.org>
Subject: [PATCH v2 1/5] of: base: convert index to unsigned for of_parse_phandle()
Date: Fri, 14 Jan 2022 13:07:19 +0100	[thread overview]
Message-ID: <20220114120723.326268-2-michael@walle.cc> (raw)
In-Reply-To: <20220114120723.326268-1-michael@walle.cc>

Since commit 2021bd01ffcc ("of: Remove counting special case from
__of_parse_phandle_with_args()"), the index is >=0, thus convert the
parameter to unsigned of the of_parse_phandle() and all its variants.
This allows us to drop the check for negative index values.

Suggested-by: Rob Herring <robh@kernel.org>
Signed-off-by: Michael Walle <michael@walle.cc>
---
changes since v1:
 - just change the index to unsigned int, the static inline change
   is now an own patch

 drivers/of/base.c  | 27 ++++++++++-----------------
 include/linux/of.h | 16 ++++++++--------
 2 files changed, 18 insertions(+), 25 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 8a24d37153b4..704d6353ac3f 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -1423,11 +1423,12 @@ int of_phandle_iterator_args(struct of_phandle_iterator *it,
 static int __of_parse_phandle_with_args(const struct device_node *np,
 					const char *list_name,
 					const char *cells_name,
-					int cell_count, int index,
+					int cell_count, unsigned int index,
 					struct of_phandle_args *out_args)
 {
 	struct of_phandle_iterator it;
-	int rc, cur_index = 0;
+	unsigned int cur_index = 0;
+	int rc;
 
 	/* Loop over the phandles until all the requested entry is found */
 	of_for_each_phandle(&it, rc, np, list_name, cells_name, cell_count) {
@@ -1483,13 +1484,11 @@ static int __of_parse_phandle_with_args(const struct device_node *np,
  * of_node_put() on it when done.
  */
 struct device_node *of_parse_phandle(const struct device_node *np,
-				     const char *phandle_name, int index)
+				     const char *phandle_name,
+				     unsigned int index)
 {
 	struct of_phandle_args args;
 
-	if (index < 0)
-		return NULL;
-
 	if (__of_parse_phandle_with_args(np, phandle_name, NULL, 0,
 					 index, &args))
 		return NULL;
@@ -1531,14 +1530,11 @@ EXPORT_SYMBOL(of_parse_phandle);
  * of_parse_phandle_with_args(node3, "list", "#list-cells", 1, &args);
  */
 int of_parse_phandle_with_args(const struct device_node *np, const char *list_name,
-				const char *cells_name, int index,
+				const char *cells_name, unsigned int index,
 				struct of_phandle_args *out_args)
 {
 	int cell_count = -1;
 
-	if (index < 0)
-		return -EINVAL;
-
 	/* If cells_name is NULL we assume a cell count of 0 */
 	if (!cells_name)
 		cell_count = 0;
@@ -1593,7 +1589,8 @@ EXPORT_SYMBOL(of_parse_phandle_with_args);
 int of_parse_phandle_with_args_map(const struct device_node *np,
 				   const char *list_name,
 				   const char *stem_name,
-				   int index, struct of_phandle_args *out_args)
+				   unsigned int index,
+				   struct of_phandle_args *out_args)
 {
 	char *cells_name, *map_name = NULL, *mask_name = NULL;
 	char *pass_name = NULL;
@@ -1606,9 +1603,6 @@ int of_parse_phandle_with_args_map(const struct device_node *np,
 	int i, ret, map_len, match;
 	u32 list_size, new_size;
 
-	if (index < 0)
-		return -EINVAL;
-
 	cells_name = kasprintf(GFP_KERNEL, "#%s-cells", stem_name);
 	if (!cells_name)
 		return -ENOMEM;
@@ -1764,10 +1758,9 @@ EXPORT_SYMBOL(of_parse_phandle_with_args_map);
  */
 int of_parse_phandle_with_fixed_args(const struct device_node *np,
 				const char *list_name, int cell_count,
-				int index, struct of_phandle_args *out_args)
+				unsigned int index,
+				struct of_phandle_args *out_args)
 {
-	if (index < 0)
-		return -EINVAL;
 	return __of_parse_phandle_with_args(np, list_name, NULL, cell_count,
 					   index, out_args);
 }
diff --git a/include/linux/of.h b/include/linux/of.h
index ff143a027abc..36ddb4aac722 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -366,15 +366,15 @@ extern int of_modalias_node(struct device_node *node, char *modalias, int len);
 extern void of_print_phandle_args(const char *msg, const struct of_phandle_args *args);
 extern struct device_node *of_parse_phandle(const struct device_node *np,
 					    const char *phandle_name,
-					    int index);
+					    unsigned int index);
 extern int of_parse_phandle_with_args(const struct device_node *np,
-	const char *list_name, const char *cells_name, int index,
+	const char *list_name, const char *cells_name, unsigned int index,
 	struct of_phandle_args *out_args);
 extern int of_parse_phandle_with_args_map(const struct device_node *np,
-	const char *list_name, const char *stem_name, int index,
+	const char *list_name, const char *stem_name, unsigned int index,
 	struct of_phandle_args *out_args);
 extern int of_parse_phandle_with_fixed_args(const struct device_node *np,
-	const char *list_name, int cells_count, int index,
+	const char *list_name, int cells_count, unsigned int index,
 	struct of_phandle_args *out_args);
 extern int of_count_phandle_with_args(const struct device_node *np,
 	const char *list_name, const char *cells_name);
@@ -867,7 +867,7 @@ static inline int of_property_read_string_helper(const struct device_node *np,
 
 static inline struct device_node *of_parse_phandle(const struct device_node *np,
 						   const char *phandle_name,
-						   int index)
+						   unsigned int index)
 {
 	return NULL;
 }
@@ -875,7 +875,7 @@ static inline struct device_node *of_parse_phandle(const struct device_node *np,
 static inline int of_parse_phandle_with_args(const struct device_node *np,
 					     const char *list_name,
 					     const char *cells_name,
-					     int index,
+					     unsigned int index,
 					     struct of_phandle_args *out_args)
 {
 	return -ENOSYS;
@@ -884,14 +884,14 @@ static inline int of_parse_phandle_with_args(const struct device_node *np,
 static inline int of_parse_phandle_with_args_map(const struct device_node *np,
 						 const char *list_name,
 						 const char *stem_name,
-						 int index,
+						 unsigned int index,
 						 struct of_phandle_args *out_args)
 {
 	return -ENOSYS;
 }
 
 static inline int of_parse_phandle_with_fixed_args(const struct device_node *np,
-	const char *list_name, int cells_count, int index,
+	const char *list_name, int cells_count, unsigned int index,
 	struct of_phandle_args *out_args)
 {
 	return -ENOSYS;
-- 
2.30.2


  reply	other threads:[~2022-01-14 12:07 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-14 12:07 [PATCH v2 0/5] of: base: small cleanups Michael Walle
2022-01-14 12:07 ` Michael Walle [this message]
2022-01-14 12:07 ` [PATCH v2 2/5] of: base: make small of_parse_phandle() variants static inline Michael Walle
2022-01-14 12:07 ` [PATCH v2 3/5] of: base: add of_parse_phandle_with_optional_args() Michael Walle
2022-01-14 12:07 ` [PATCH v2 4/5] of: property: define of_property_read_u{8,16,32,64}_array() unconditionally Michael Walle
2022-01-14 12:07 ` [PATCH v2 5/5] of: property: use unsigned index for of_link_property() Michael Walle
2022-01-14 14:50 ` [PATCH v2 0/5] of: base: small cleanups Rob Herring

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=20220114120723.326268-2-michael@walle.cc \
    --to=michael@walle.cc \
    --cc=devicetree@vger.kernel.org \
    --cc=frowand.list@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=robh@kernel.org \
    /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®