cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
* [cocci] [PATCH] Input: MT - Return directly after a failed kzalloc() in input_mt_init_slots()
@ 2023-12-26 19:43 Markus Elfring
       [not found] ` <ZY54hX3VLswwKgMH@google.com>
  0 siblings, 1 reply; 2+ messages in thread
From: Markus Elfring @ 2023-12-26 19:43 UTC (permalink / raw)
  To: linux-input, kernel-janitors, Dmitry Torokhov, Henrik Rydberg; +Cc: LKML, cocci

From: Markus Elfring <elfring@users.sourceforge.net>
Date: Tue, 26 Dec 2023 20:36:09 +0100

The kfree() function was called in one case by
the input_mt_init_slots() 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 “kzalloc” failed
at the beginning.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 drivers/input/input-mt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/input/input-mt.c b/drivers/input/input-mt.c
index 14b53dac1253..24064447d600 100644
--- a/drivers/input/input-mt.c
+++ b/drivers/input/input-mt.c
@@ -49,7 +49,7 @@ int input_mt_init_slots(struct input_dev *dev, unsigned int num_slots,

 	mt = kzalloc(struct_size(mt, slots, num_slots), GFP_KERNEL);
 	if (!mt)
-		goto err_mem;
+		return -ENOMEM;

 	mt->num_slots = num_slots;
 	mt->flags = flags;
--
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [cocci] Input: MT - Return directly after a failed kzalloc() in input_mt_init_slots()
       [not found] ` <ZY54hX3VLswwKgMH@google.com>
@ 2023-12-29  9:00   ` Markus Elfring
  0 siblings, 0 replies; 2+ messages in thread
From: Markus Elfring @ 2023-12-29  9:00 UTC (permalink / raw)
  To: Dmitry Torokhov, linux-input; +Cc: kernel-janitors, Henrik Rydberg, LKML, cocci

>> Thus return directly after a call of the function “kzalloc” failed
>> at the beginning.
>
> This is not needed. The same arguments as on the patch to
> usbtouchscreen.c.

I suggest 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  9:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-26 19:43 [cocci] [PATCH] Input: MT - Return directly after a failed kzalloc() in input_mt_init_slots() Markus Elfring
     [not found] ` <ZY54hX3VLswwKgMH@google.com>
2023-12-29  9:00   ` [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).