Re: [PATCH] pinctrl: Avoid kasprintf/kfree

From: Linus Walleij
Date: Mon Feb 24 2014 - 04:50:01 EST


On Thu, Jan 30, 2014 at 9:37 PM, Joe Perches <joe@xxxxxxxxxxx> wrote:

> Avoid an unnecessary allocation/free by using stack instead.
>
> Signed-off-by; Joe Perches <joe@xxxxxxxxxxx>

Hm.

> + char propname[9 + sizeof(int) * 2 + 4] = "pinctrl-";

If you absolutely want to do this you have to

#define PINCTRL_PREFIX "pinctrl-"

char propname[strlen(PINCTRL_PREFIX) + sizeof(int)*2 + 4] = PINCTRL_PREFIX;

Then add a comment above stating why you add 4.

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

Another option would be to just add a NULL-check? This is
definately not on a performance-critical path.

Yours,
Linus Walleij
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/