diff mbox series

drivers: usbtouchscreen: use kzalloc

Message ID 20220312172232.13146-1-michaelestner@web.de (mailing list archive)
State New, archived
Headers show
Series drivers: usbtouchscreen: use kzalloc | expand

Commit Message

Michael Estner March 12, 2022, 5:22 p.m. UTC
Use kzalloc instead of kmalloc + memset.

The semantic patch that makes this change is:
(https://coccinelle.gitlabpages.inria.fr/website/)

Signed-off-by: Michael Estner <michaelestner@web.de>
---
 drivers/input/touchscreen/usbtouchscreen.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

--
2.25.1

Comments

Johan Hovold March 12, 2022, 6:14 p.m. UTC | #1
On Sat, Mar 12, 2022 at 06:22:30PM +0100, Michael Estner wrote:
> Use kzalloc instead of kmalloc + memset.
> 
> The semantic patch that makes this change is:
> (https://coccinelle.gitlabpages.inria.fr/website/)
> 
> Signed-off-by: Michael Estner <michaelestner@web.de>
> ---
>  drivers/input/touchscreen/usbtouchscreen.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/input/touchscreen/usbtouchscreen.c b/drivers/input/touchscreen/usbtouchscreen.c
> index 43c521f50c85..159e1ac6198a 100644
> --- a/drivers/input/touchscreen/usbtouchscreen.c
> +++ b/drivers/input/touchscreen/usbtouchscreen.c
> @@ -975,7 +975,7 @@ static int nexio_init(struct usbtouch_usb *usbtouch)
>  	if (!input_ep || !output_ep)
>  		return -ENXIO;
> 
> -	buf = kmalloc(NEXIO_BUFSIZE, GFP_NOIO);
> +	buf = kzalloc(NEXIO_BUFSIZE, GFP_NOIO);
>  	if (!buf)
>  		goto out_buf;
> 
> @@ -998,7 +998,6 @@ static int nexio_init(struct usbtouch_usb *usbtouch)
> 
>  	/* read replies */
>  	for (i = 0; i < 3; i++) {
> -		memset(buf, 0, NEXIO_BUFSIZE);
>  		ret = usb_bulk_msg(dev, usb_rcvbulkpipe(dev, input_ep),
>  				   buf, NEXIO_BUFSIZE, &actual_len,
>  				   NEXIO_TIMEOUT);

NAK

The new code is not equivalent to the old so that semantic patch must be
broken.

The current code is clearing the buffer before each read, after this
patch it would only be cleared once.

Johan
diff mbox series

Patch

diff --git a/drivers/input/touchscreen/usbtouchscreen.c b/drivers/input/touchscreen/usbtouchscreen.c
index 43c521f50c85..159e1ac6198a 100644
--- a/drivers/input/touchscreen/usbtouchscreen.c
+++ b/drivers/input/touchscreen/usbtouchscreen.c
@@ -975,7 +975,7 @@  static int nexio_init(struct usbtouch_usb *usbtouch)
 	if (!input_ep || !output_ep)
 		return -ENXIO;

-	buf = kmalloc(NEXIO_BUFSIZE, GFP_NOIO);
+	buf = kzalloc(NEXIO_BUFSIZE, GFP_NOIO);
 	if (!buf)
 		goto out_buf;

@@ -998,7 +998,6 @@  static int nexio_init(struct usbtouch_usb *usbtouch)

 	/* read replies */
 	for (i = 0; i < 3; i++) {
-		memset(buf, 0, NEXIO_BUFSIZE);
 		ret = usb_bulk_msg(dev, usb_rcvbulkpipe(dev, input_ep),
 				   buf, NEXIO_BUFSIZE, &actual_len,
 				   NEXIO_TIMEOUT);