* [PATCH v2] usb: isp1760: Use kasprintf
@ 2018-03-07 18:38 Himanshu Jha
2018-03-07 19:16 ` Kees Cook
0 siblings, 1 reply; 2+ messages in thread
From: Himanshu Jha @ 2018-03-07 18:38 UTC (permalink / raw)
To: gregkh
Cc: keescook, johan, felipe.balbi, linux-usb, linux-kernel, Himanshu Jha
Use kasprintf instead of combination of kmalloc and sprintf and
therefore avoid unnecessary computation of string length.
Also, remove the useless local variable.
Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
---
drivers/usb/isp1760/isp1760-udc.c | 6 +-----
1 file changed, 1 insertion(+), 5 deletions(-)
v2:
-removed the useless local variable devname.
diff --git a/drivers/usb/isp1760/isp1760-udc.c b/drivers/usb/isp1760/isp1760-udc.c
index bac4ef5..1714b22 100644
--- a/drivers/usb/isp1760/isp1760-udc.c
+++ b/drivers/usb/isp1760/isp1760-udc.c
@@ -1441,7 +1441,6 @@ int isp1760_udc_register(struct isp1760_device *isp, int irq,
unsigned long irqflags)
{
struct isp1760_udc *udc = &isp->udc;
- const char *devname;
int ret;
udc->irq = -1;
@@ -1455,13 +1454,10 @@ int isp1760_udc_register(struct isp1760_device *isp, int irq,
if (ret < 0)
return ret;
- devname = dev_name(isp->dev);
- udc->irqname = kmalloc(strlen(devname) + 7, GFP_KERNEL);
+ udc->irqname = kasprintf(GFP_KERNEL, "%s (udc)", dev_name(isp->dev));
if (!udc->irqname)
return -ENOMEM;
- sprintf(udc->irqname, "%s (udc)", devname);
-
ret = request_irq(irq, isp1760_udc_irq, IRQF_SHARED | irqflags,
udc->irqname, udc);
if (ret < 0)
--
2.7.4
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] usb: isp1760: Use kasprintf
2018-03-07 18:38 [PATCH v2] usb: isp1760: Use kasprintf Himanshu Jha
@ 2018-03-07 19:16 ` Kees Cook
0 siblings, 0 replies; 2+ messages in thread
From: Kees Cook @ 2018-03-07 19:16 UTC (permalink / raw)
To: Himanshu Jha; +Cc: Greg KH, Johan Hovold, Felipe Balbi, linux-usb, LKML
On Wed, Mar 7, 2018 at 10:38 AM, Himanshu Jha
<himanshujha199640@gmail.com> wrote:
> Use kasprintf instead of combination of kmalloc and sprintf and
> therefore avoid unnecessary computation of string length.
> Also, remove the useless local variable.
>
> Signed-off-by: Himanshu Jha <himanshujha199640@gmail.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
-Kees
> ---
> drivers/usb/isp1760/isp1760-udc.c | 6 +-----
> 1 file changed, 1 insertion(+), 5 deletions(-)
>
> v2:
> -removed the useless local variable devname.
>
> diff --git a/drivers/usb/isp1760/isp1760-udc.c b/drivers/usb/isp1760/isp1760-udc.c
> index bac4ef5..1714b22 100644
> --- a/drivers/usb/isp1760/isp1760-udc.c
> +++ b/drivers/usb/isp1760/isp1760-udc.c
> @@ -1441,7 +1441,6 @@ int isp1760_udc_register(struct isp1760_device *isp, int irq,
> unsigned long irqflags)
> {
> struct isp1760_udc *udc = &isp->udc;
> - const char *devname;
> int ret;
>
> udc->irq = -1;
> @@ -1455,13 +1454,10 @@ int isp1760_udc_register(struct isp1760_device *isp, int irq,
> if (ret < 0)
> return ret;
>
> - devname = dev_name(isp->dev);
> - udc->irqname = kmalloc(strlen(devname) + 7, GFP_KERNEL);
> + udc->irqname = kasprintf(GFP_KERNEL, "%s (udc)", dev_name(isp->dev));
> if (!udc->irqname)
> return -ENOMEM;
>
> - sprintf(udc->irqname, "%s (udc)", devname);
> -
> ret = request_irq(irq, isp1760_udc_irq, IRQF_SHARED | irqflags,
> udc->irqname, udc);
> if (ret < 0)
> --
> 2.7.4
>
--
Kees Cook
Pixel Security
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-03-07 19:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-07 18:38 [PATCH v2] usb: isp1760: Use kasprintf Himanshu Jha
2018-03-07 19:16 ` Kees Cook
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).