[PATCH] usb: gadget: udc: atmel: used managed kasprintf

From
Felipe Balbi <balbi@kernel.org>
Date
2017-01-16 10:29:14
Also in
lkml
Reply to
David Laight, 2016-12-05
Hi,

David Laight [off-list ref] writes:
From: Alexandre Belloni
quoted
Sent: 02 December 2016 16:19
On 02/12/2016 at 15:59:57 +0000, David Laight wrote :
quoted
From: Alexandre Belloni
quoted
Sent: 01 December 2016 10:27
Use devm_kasprintf instead of simple kasprintf to free the allocated memory
when needed.
s/when needed/when the device is freed/
quoted
Suggested-by: Peter Rosin <redacted>
Signed-off-by: Alexandre Belloni <redacted>
---
 drivers/usb/gadget/udc/atmel_usba_udc.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c b/drivers/usb/gadget/udc/atmel_usba_udc.c
index 45bc997d0711..aec72fe8273c 100644
--- a/drivers/usb/gadget/udc/atmel_usba_udc.c
+++ b/drivers/usb/gadget/udc/atmel_usba_udc.c
@@ -1978,7 +1978,8 @@ static struct usba_ep * atmel_udc_of_init(struct platform_device *pdev,
 			dev_err(&pdev->dev, "of_probe: name error(%d)\n", ret);
 			goto err;
 		}
-		ep->ep.name = kasprintf(GFP_KERNEL, "ep%d", ep->index);
+		ep->ep.name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "ep%d",
+					     ep->index);
Acually why bother mallocing such a small string at all.
The maximum length is 12 bytes even if 'index' are unrestricted.
IIRC, using statically allocated string is failing somewhere is the USB
core but I don't remember all the details.
I can't imagine that changing ep->ep.name from 'char *' to 'char [12]' would
make any difference.
the actual name is managed by the UDC. Meaning, ep->ep.name should be a
pointer, but it could very well just point to ep->name which would be
char [12].

-- 
balbi
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170116/9893a195/attachment.sig>
Thread (8 messages) 8 messages, 4 authors, last reply 2017-01-16
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help