Skip to contentSkip to conversation

drivers: usbtouchscreen: use kzalloc

PATCH NAK Michael Estner 2 participants 2 messages Mar 12, 2022 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): Michael Estner <[email protected]

#1 lore raw

PATCH 1/1 drivers: usbtouchscreen: use kzalloc

Use kzalloc instead of kmalloc + memset.

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

---
 drivers/input/touchscreen/usbtouchscreen.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/input/touchscreen/usbtouchscreen.c +1 -2
index 43c521f50c85..159e1ac6198a 100644
@@ -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);

--
2.25.1

#2 lore raw
Quoted 24 lines · Michael Estner

Use kzalloc instead of kmalloc + memset.

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

---
 drivers/input/touchscreen/usbtouchscreen.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/input/touchscreen/usbtouchscreen.c +1 -1
index 43c521f50c85..159e1ac6198a 100644
@@ -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;
 

drivers/input/touchscreen/usbtouchscreen.c static int nexio_init(struct usbtouch_usb *usbtouch) · line 1003

Quoted 7 lines
drivers/input/touchscreen/usbtouchscreen.c +0 -1
@@ -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