* [cocci] [PATCH] Input: usbtouchscreen - Return directly after a failed kmalloc() in nexio_init()
@ 2023-12-26 20:08 Markus Elfring
[not found] ` <ZY54UDosMHwj6D3Y@google.com>
0 siblings, 1 reply; 2+ messages in thread
From: Markus Elfring @ 2023-12-26 20:08 UTC (permalink / raw)
To: linux-input, kernel-janitors, Dmitry Torokhov, Oliver Graute,
Uwe Kleine-König, ye xingchen
Cc: LKML, cocci
From: Markus Elfring <elfring@users.sourceforge.net>
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.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/input/touchscreen/usbtouchscreen.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/input/touchscreen/usbtouchscreen.c b/drivers/input/touchscreen/usbtouchscreen.c
index 60354ebc7242..1873c7918a78 100644
--- a/drivers/input/touchscreen/usbtouchscreen.c
+++ b/drivers/input/touchscreen/usbtouchscreen.c
@@ -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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [cocci] Input: usbtouchscreen - Return directly after a failed kmalloc() in nexio_init()
[not found] ` <ZY54UDosMHwj6D3Y@google.com>
@ 2023-12-29 8:56 ` Markus Elfring
0 siblings, 0 replies; 2+ messages in thread
From: Markus Elfring @ 2023-12-29 8:56 UTC (permalink / raw)
To: Dmitry Torokhov, linux-input
Cc: kernel-janitors, Oliver Graute, Uwe Kleine-König,
ye xingchen, LKML, cocci
>> 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.
>> 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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-12-29 8:57 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-26 20:08 [cocci] [PATCH] Input: usbtouchscreen - Return directly after a failed kmalloc() in nexio_init() Markus Elfring
[not found] ` <ZY54UDosMHwj6D3Y@google.com>
2023-12-29 8:56 ` [cocci] " Markus Elfring
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).