mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] HID: playstation: Fix memory leak in dualshock4_get_calibration_data()
@ 2025-11-10 17:15 Abdun Nihaal
  2025-11-10 17:49 ` Markus Elfring
  2025-11-18 17:07 ` Jiri Kosina
  0 siblings, 2 replies; 4+ messages in thread
From: Abdun Nihaal @ 2025-11-10 17:15 UTC (permalink / raw)
  To: roderick.colenbrander
  Cc: Abdun Nihaal, jikos, bentiss, linux-input, linux-kernel

The memory allocated for buf is not freed in the error paths when
ps_get_report() fails. Free buf before jumping to transfer_failed label

Fixes: 947992c7fa9e ("HID: playstation: DS4: Fix calibration workaround for clone devices")
Signed-off-by: Abdun Nihaal <nihaal@cse.iitm.ac.in>
---
Compile tested only. Found using static analysis.

 drivers/hid/hid-playstation.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c
index 63f6eb9030d1..128aa6abd10b 100644
--- a/drivers/hid/hid-playstation.c
+++ b/drivers/hid/hid-playstation.c
@@ -1942,6 +1942,7 @@ static int dualshock4_get_calibration_data(struct dualshock4 *ds4)
 					 "Failed to retrieve DualShock4 calibration info: %d\n",
 					 ret);
 				ret = -EILSEQ;
+				kfree(buf);
 				goto transfer_failed;
 			} else {
 				break;
@@ -1959,6 +1960,7 @@ static int dualshock4_get_calibration_data(struct dualshock4 *ds4)
 
 		if (ret) {
 			hid_warn(hdev, "Failed to retrieve DualShock4 calibration info: %d\n", ret);
+			kfree(buf);
 			goto transfer_failed;
 		}
 	}
-- 
2.43.0


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

* Re: [PATCH] HID: playstation: Fix memory leak in dualshock4_get_calibration_data()
  2025-11-10 17:15 [PATCH] HID: playstation: Fix memory leak in dualshock4_get_calibration_data() Abdun Nihaal
@ 2025-11-10 17:49 ` Markus Elfring
  2025-11-11 11:23   ` Abdun Nihaal
  2025-11-18 17:07 ` Jiri Kosina
  1 sibling, 1 reply; 4+ messages in thread
From: Markus Elfring @ 2025-11-10 17:49 UTC (permalink / raw)
  To: Abdun Nihaal, linux-input, Roderick Colenbrander
  Cc: LKML, Benjamin Tissoires, Jiri Kosina

> The memory allocated for buf is not freed in the error paths when
> ps_get_report() fails. Free buf before jumping to transfer_failed label

Would an additional label become helpful for this function implementation?

Regards,
Markus

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

* Re: [PATCH] HID: playstation: Fix memory leak in dualshock4_get_calibration_data()
  2025-11-10 17:49 ` Markus Elfring
@ 2025-11-11 11:23   ` Abdun Nihaal
  0 siblings, 0 replies; 4+ messages in thread
From: Abdun Nihaal @ 2025-11-11 11:23 UTC (permalink / raw)
  To: Markus Elfring
  Cc: linux-input, Roderick Colenbrander, LKML, Benjamin Tissoires,
	Jiri Kosina

On Mon, Nov 10, 2025 at 06:49:01PM +0100, Markus Elfring wrote:
> > The memory allocated for buf is not freed in the error paths when
> > ps_get_report() fails. Free buf before jumping to transfer_failed label
> 
> Would an additional label become helpful for this function implementation?

In the function, the code present at the transfer_failed label is shared 
between normal and error paths, and is not the traditional error path label,
that's why I put the kfree for the two cases immediately before the goto.

Regards,
Nihaal

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

* Re: [PATCH] HID: playstation: Fix memory leak in dualshock4_get_calibration_data()
  2025-11-10 17:15 [PATCH] HID: playstation: Fix memory leak in dualshock4_get_calibration_data() Abdun Nihaal
  2025-11-10 17:49 ` Markus Elfring
@ 2025-11-18 17:07 ` Jiri Kosina
  1 sibling, 0 replies; 4+ messages in thread
From: Jiri Kosina @ 2025-11-18 17:07 UTC (permalink / raw)
  To: Abdun Nihaal; +Cc: roderick.colenbrander, bentiss, linux-input, linux-kernel

On Mon, 10 Nov 2025, Abdun Nihaal wrote:

> The memory allocated for buf is not freed in the error paths when
> ps_get_report() fails. Free buf before jumping to transfer_failed label
> 
> Fixes: 947992c7fa9e ("HID: playstation: DS4: Fix calibration workaround for clone devices")
> Signed-off-by: Abdun Nihaal <nihaal@cse.iitm.ac.in>

Applied, thanks.

-- 
Jiri Kosina
SUSE Labs


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

end of thread, other threads:[~2025-11-18 17:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-10 17:15 [PATCH] HID: playstation: Fix memory leak in dualshock4_get_calibration_data() Abdun Nihaal
2025-11-10 17:49 ` Markus Elfring
2025-11-11 11:23   ` Abdun Nihaal
2025-11-18 17:07 ` Jiri Kosina

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®