From: Thomas Petazzoni <hidden> Date: 2012-09-13 19:49:25
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 <redacted>
---
drivers/pinctrl/pinmux.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
@@ -232,14 +232,11 @@ int pinmux_request_gpio(struct pinctrl_dev *pctldev,structpinctrl_gpio_range*range,unsignedpin,unsignedgpio){-chargpiostr[16];constchar*owner;intret;/* 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;
From: Joe Perches <joe@perches.com> Date: 2012-09-14 05:19:08
On Thu, 2012-09-13 at 21:49 +0200, Thomas Petazzoni wrote:
quoted hunk
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 <redacted>
---
drivers/pinctrl/pinmux.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
@@ -232,14 +232,11 @@ int pinmux_request_gpio(struct pinctrl_dev *pctldev,structpinctrl_gpio_range*range,unsignedpin,unsignedgpio){-chargpiostr[16];constchar*owner;intret;/* 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.
From: Colin Cross <hidden> Date: 2012-09-14 07:18:55
On Thu, Sep 13, 2012 at 10:19 PM, Joe Perches [off-list ref] wrote:
On Thu, 2012-09-13 at 21:49 +0200, Thomas Petazzoni wrote:
quoted
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 <redacted>
---
drivers/pinctrl/pinmux.c | 5 +----
1 file changed, 1 insertion(+), 4 deletions(-)
@@ -232,14 +232,11 @@ int pinmux_request_gpio(struct pinctrl_dev *pctldev,structpinctrl_gpio_range*range,unsignedpin,unsignedgpio){-chargpiostr[16];constchar*owner;intret;/* 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.