* [PATCH] pinctrl: use kasprintf() in pinmux_request_gpio()
@ 2012-09-13 19:49 Thomas Petazzoni
2012-09-14 5:19 ` Joe Perches
0 siblings, 1 reply; 4+ messages in thread
From: Thomas Petazzoni @ 2012-09-13 19:49 UTC (permalink / raw)
To: linux-arm-kernel
Instead of using a temporary buffer, snprintf() and kstrdup(), just
use kasprintf() that does the same thing in just oneline.
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
---
drivers/pinctrl/pinmux.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
diff --git a/drivers/pinctrl/pinmux.c b/drivers/pinctrl/pinmux.c
index 3d5ac73..9301a7a 100644
--- a/drivers/pinctrl/pinmux.c
+++ b/drivers/pinctrl/pinmux.c
@@ -232,14 +232,11 @@ int pinmux_request_gpio(struct pinctrl_dev *pctldev,
struct pinctrl_gpio_range *range,
unsigned pin, unsigned gpio)
{
- char gpiostr[16];
const char *owner;
int ret;
/* Conjure some name stating what chip and pin this is taken by */
- snprintf(gpiostr, 15, "%s:%d", range->name, gpio);
-
- owner = kstrdup(gpiostr, GFP_KERNEL);
+ owner = kasprintf(GFP_KERNEL, "%s:%d", range->name, gpio);
if (!owner)
return -EINVAL;
--
1.7.9.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH] pinctrl: use kasprintf() in pinmux_request_gpio()
2012-09-13 19:49 [PATCH] pinctrl: use kasprintf() in pinmux_request_gpio() Thomas Petazzoni
@ 2012-09-14 5:19 ` Joe Perches
2012-09-14 7:18 ` Colin Cross
0 siblings, 1 reply; 4+ messages in thread
From: Joe Perches @ 2012-09-14 5:19 UTC (permalink / raw)
To: linux-arm-kernel
On Thu, 2012-09-13 at 21:49 +0200, Thomas Petazzoni wrote:
> Instead of using a temporary buffer, snprintf() and kstrdup(), just
> use kasprintf() that does the same thing in just oneline.
>
> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
> ---
> drivers/pinctrl/pinmux.c | 5 +----
> 1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/drivers/pinctrl/pinmux.c b/drivers/pinctrl/pinmux.c
> index 3d5ac73..9301a7a 100644
> --- a/drivers/pinctrl/pinmux.c
> +++ b/drivers/pinctrl/pinmux.c
> @@ -232,14 +232,11 @@ int pinmux_request_gpio(struct pinctrl_dev *pctldev,
> struct pinctrl_gpio_range *range,
> unsigned pin, unsigned gpio)
> {
> - char gpiostr[16];
> const char *owner;
> int ret;
>
> /* Conjure some name stating what chip and pin this is taken by */
> - snprintf(gpiostr, 15, "%s:%d", range->name, gpio);
> -
> - owner = kstrdup(gpiostr, GFP_KERNEL);
> + owner = kasprintf(GFP_KERNEL, "%s:%d", range->name, gpio);
> if (!owner)
> return -EINVAL;
>
No not really. It's a bit different because the first
snprintf is length limited but the kasprintf is not.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] pinctrl: use kasprintf() in pinmux_request_gpio()
2012-09-14 5:19 ` Joe Perches
@ 2012-09-14 7:18 ` Colin Cross
2012-09-14 13:54 ` Linus Walleij
0 siblings, 1 reply; 4+ messages in thread
From: Colin Cross @ 2012-09-14 7:18 UTC (permalink / raw)
To: linux-arm-kernel
On Thu, Sep 13, 2012 at 10:19 PM, Joe Perches <joe@perches.com> wrote:
> On Thu, 2012-09-13 at 21:49 +0200, Thomas Petazzoni wrote:
>> Instead of using a temporary buffer, snprintf() and kstrdup(), just
>> use kasprintf() that does the same thing in just oneline.
>>
>> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
>> ---
>> drivers/pinctrl/pinmux.c | 5 +----
>> 1 file changed, 1 insertion(+), 4 deletions(-)
>>
>> diff --git a/drivers/pinctrl/pinmux.c b/drivers/pinctrl/pinmux.c
>> index 3d5ac73..9301a7a 100644
>> --- a/drivers/pinctrl/pinmux.c
>> +++ b/drivers/pinctrl/pinmux.c
>> @@ -232,14 +232,11 @@ int pinmux_request_gpio(struct pinctrl_dev *pctldev,
>> struct pinctrl_gpio_range *range,
>> unsigned pin, unsigned gpio)
>> {
>> - char gpiostr[16];
>> const char *owner;
>> int ret;
>>
>> /* Conjure some name stating what chip and pin this is taken by */
>> - snprintf(gpiostr, 15, "%s:%d", range->name, gpio);
>> -
>> - owner = kstrdup(gpiostr, GFP_KERNEL);
>> + owner = kasprintf(GFP_KERNEL, "%s:%d", range->name, gpio);
>> if (!owner)
>> return -EINVAL;
>>
>
> No not really. It's a bit different because the first
> snprintf is length limited but the kasprintf is not.
The one it's replacing is worse, it never sets gpiostr[15] to 0 and
kstrdup will read past the end of the buffer if the string is
truncated.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] pinctrl: use kasprintf() in pinmux_request_gpio()
2012-09-14 7:18 ` Colin Cross
@ 2012-09-14 13:54 ` Linus Walleij
0 siblings, 0 replies; 4+ messages in thread
From: Linus Walleij @ 2012-09-14 13:54 UTC (permalink / raw)
To: linux-arm-kernel
On Fri, Sep 14, 2012 at 9:18 AM, Colin Cross <ccross@google.com> wrote:
> The one it's replacing is worse, it never sets gpiostr[15] to 0 and
> kstrdup will read past the end of the buffer if the string is
> truncated.
I recorded this as an Acked-by ... :-)
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2012-09-14 13:54 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-13 19:49 [PATCH] pinctrl: use kasprintf() in pinmux_request_gpio() Thomas Petazzoni
2012-09-14 5:19 ` Joe Perches
2012-09-14 7:18 ` Colin Cross
2012-09-14 13:54 ` Linus Walleij
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox