mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Mark Brown <broonie@kernel.org>
Cc: Linus Walleij <linus.walleij@linaro.org>,
	linux-kernel@vger.kernel.org, linaro-kernel@lists.linaro.org,
	Mark Brown <broonie@linaro.org>
Subject: [PATCH] pinctrl: Avoid kasprintf/kfree
Date: Thu, 30 Jan 2014 12:37:36 -0800	[thread overview]
Message-ID: <1391114256.2422.71.camel@joe-AO722> (raw)
In-Reply-To: <1391108694.2422.59.camel@joe-AO722>

Avoid an unnecessary allocation/free by using stack instead.

Signed-off-by; Joe Perches <joe@perches.com>
---

This allocation seems unnecessary and the kasprintf isn't
checked for non-null, so maybe this is better.

 drivers/pinctrl/devicetree.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/pinctrl/devicetree.c b/drivers/pinctrl/devicetree.c
index 340fb4e..ffb59c8 100644
--- a/drivers/pinctrl/devicetree.c
+++ b/drivers/pinctrl/devicetree.c
@@ -176,13 +176,13 @@ int pinctrl_dt_to_map(struct pinctrl *p)
 {
 	struct device_node *np = p->dev->of_node;
 	int state, ret;
-	char *propname;
 	struct property *prop;
 	const char *statename;
 	const __be32 *list;
 	int size, config;
 	phandle phandle;
 	struct device_node *np_config;
+	char propname[9 + sizeof(int) * 2 + 4] = "pinctrl-";
 
 	/* CONFIG_OF enabled, p->dev not instantiated from DT */
 	if (!np) {
@@ -196,9 +196,8 @@ int pinctrl_dt_to_map(struct pinctrl *p)
 	/* For each defined state ID */
 	for (state = 0; ; state++) {
 		/* Retrieve the pinctrl-* property */
-		propname = kasprintf(GFP_KERNEL, "pinctrl-%d", state);
+		snprintf(&propname[8], ARRAY_SIZE(propname) - 9, "%d", state);
 		prop = of_find_property(np, propname, &size);
-		kfree(propname);
 		if (!prop)
 			break;
 		list = prop->value;



  reply	other threads:[~2014-01-30 20:37 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-30 18:57 [PATCH] pinctrl: Quiet logging about missing DT nodes when not using DT Mark Brown
2014-01-30 19:04 ` Joe Perches
2014-01-30 20:37   ` Joe Perches [this message]
2014-01-30 20:50     ` [PATCH] pinctrl: Avoid kasprintf/kfree Mark Brown
2014-02-24  9:49     ` Linus Walleij
2014-02-24 18:16       ` Joe Perches
2014-02-24  9:45 ` [PATCH] pinctrl: Quiet logging about missing DT nodes when not using DT Linus Walleij

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=1391114256.2422.71.camel@joe-AO722 \
    --to=joe@perches.com \
    --cc=broonie@kernel.org \
    --cc=broonie@linaro.org \
    --cc=linaro-kernel@lists.linaro.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-kernel@vger.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®