mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 1/3] pinctrl: do not dereference a device tree property directly
Date: Wed, 31 Jan 2018 12:04:36 +0100	[thread overview]
Message-ID: <20180131110438.22620-2-s.hauer@pengutronix.de> (raw)
In-Reply-To: <20180131110438.22620-1-s.hauer@pengutronix.de>

Use of_get_property() rather than of_find_property() to avoid
dereferencing a struct property directly.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/pinctrl/pinctrl.c | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/drivers/pinctrl/pinctrl.c b/drivers/pinctrl/pinctrl.c
index bef4fcdba1..0e42a31474 100644
--- a/drivers/pinctrl/pinctrl.c
+++ b/drivers/pinctrl/pinctrl.c
@@ -99,8 +99,7 @@ static int pinctrl_config_one(struct device_node *np)
 int of_pinctrl_select_state(struct device_node *np, const char *name)
 {
 	int state, ret;
-	char *propname;
-	struct property *prop;
+	char propname[sizeof("pinctrl-4294967295")];
 	const __be32 *list;
 	int size, config;
 	phandle phandle;
@@ -113,18 +112,13 @@ int of_pinctrl_select_state(struct device_node *np, const char *name)
 	/* For each defined state ID */
 	for (state = 0; ; state++) {
 		/* Retrieve the pinctrl-* property */
-		propname = basprintf("pinctrl-%d", state);
-		prop = of_find_property(np, propname, NULL);
-		free(propname);
-
-		if (!prop) {
+		sprintf(propname, "pinctrl-%d", state);
+		list = of_get_property(np, propname, &size);
+		if (!list) {
 			ret = -ENODEV;
 			break;
 		}
 
-		size = prop->length;
-
-		list = prop->value;
 		size /= sizeof(*list);
 
 		/* Determine whether pinctrl-names property names the state */
@@ -137,7 +131,7 @@ int of_pinctrl_select_state(struct device_node *np, const char *name)
 		 */
 		if (ret < 0) {
 			/* strlen("pinctrl-") == 8 */
-			statename = prop->name + 8;
+			statename = &propname[8];
 		}
 
 		if (strcmp(name, statename))
@@ -151,7 +145,7 @@ int of_pinctrl_select_state(struct device_node *np, const char *name)
 			np_config = of_find_node_by_phandle(phandle);
 			if (!np_config) {
 				pr_err("prop %s %s index %i invalid phandle\n",
-					np->full_name, prop->name, config);
+					np->full_name, propname, config);
 				ret = -EINVAL;
 				goto err;
 			}
-- 
2.15.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2018-01-31 11:04 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-31 11:04 [PATCH 0/3] of: Allow for const properties Sascha Hauer
2018-01-31 11:04 ` Sascha Hauer [this message]
2018-01-31 11:04 ` [PATCH 2/3] " Sascha Hauer
2018-01-31 11:04 ` [PATCH 3/3] of: fdt: add of_unflatten_dtb_const Sascha Hauer

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=20180131110438.22620-2-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.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