Skip to contentSkip to conversation

Input: usbtouchscreen - Return directly after a failed kmalloc() in nexio_init()

PATCH In review Markus Elfring 2 participants 3 messages Dec 26, 2023 – Dec 29, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Input: usbtouchscreen - Return directly after a failed kmalloc() in nexio_init()

From: Markus Elfring <[email protected]>
Date: Tue, 26 Dec 2023 21:00:25 +0100

The kfree() function was called in one case by the nexio_init() function during error handling even if the passed variable contained a null pointer. This issue was detected by using the Coccinelle software.

Thus return directly after a call of the function “kmalloc” failed at the beginning.

---
 drivers/input/touchscreen/usbtouchscreen.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/touchscreen/usbtouchscreen.c +1 -1
index 60354ebc7242..1873c7918a78 100644
@@ -977,7 +977,7 @@ static int nexio_init(struct usbtouch_usb *usbtouch)
 
 	buf = kmalloc(NEXIO_BUFSIZE, GFP_NOIO);
 	if (!buf)
-		goto out_buf;
+		return ret;
 
 	/* two empty reads */
 	for (i = 0; i < 2; i++) {

--
2.43.0

maintainer
#1 lore raw
Quoted 6 lines · Markus Elfring

From: Markus Elfring <[email protected]>
Date: Tue, 26 Dec 2023 21:00:25 +0100

The kfree() function was called in one case by the nexio_init() function during error handling even if the passed variable contained a null pointer.

Which is perfectly valid thing to do, like free(), kfree() accepts NULL argument.

Quoted 1 line

This issue was detected by using the Coccinelle software.

This tells me precisely nothing.

Quoted 3 lines

Thus return directly after a call of the function “kmalloc” failed at the beginning.

This is simply a matter of preference, the original author preferred that style, I see no objective reason to change it.

Quoted 20 lines
---
 drivers/input/touchscreen/usbtouchscreen.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/touchscreen/usbtouchscreen.c +1 -2
index 60354ebc7242..1873c7918a78 100644
@@ -977,7 +977,7 @@ static int nexio_init(struct usbtouch_usb *usbtouch)
 
 	buf = kmalloc(NEXIO_BUFSIZE, GFP_NOIO);
 	if (!buf)
-		goto out_buf;
+		return ret;
 
 	/* two empty reads */
 	for (i = 0; i < 2; i++) {
--
Quoted 2 lines

2.43.0

Thanks.

Signature · 1 line
Dmitry
#2 lore raw
Quoted 5 lines
Quoted 3 lines

The kfree() function was called in one case by the nexio_init() function during error handling even if the passed variable contained a null pointer.

Which is perfectly valid thing to do, like free(), kfree() accepts NULL argument.

I find such a function call with this special parameter not so useful.

Quoted 5 lines
Quoted 2 lines

Thus return directly after a call of the function “kmalloc” failed at the beginning.

This is simply a matter of preference, the original author preferred that style, I see no objective reason to change it.

Would you ever like to avoid redundant data processing a bit more?

Regards,
Markus