lkml.org 
[lkml]   [2014]   [Jan]   [30]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Subject[PATCH] pinctrl: Avoid kasprintf/kfree
From
Date
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;



\
 
 \ /
  Last update: 2014-01-30 21:41    [W:0.067 / U:0.492 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site