mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jiri Slaby <jirislaby@kernel.org>
To: Eslam Khafagy <eslam.medhat1993@gmail.com>,
	roderick.colenbrander@sony.com, jikos@kernel.org,
	bentiss@kernel.org, max@enpas.org
Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
	syzbot+4f5f81e1456a1f645bf8@syzkaller.appspotmail.com,
	stable@vger.kernel.org
Subject: Re: [PATCH v3] HID: memory leak in dualshock4_get_calibration_data
Date: Mon, 24 Nov 2025 07:32:30 +0100	[thread overview]
Message-ID: <6251f6df-d4ac-4681-8e8b-6df2514e655b@kernel.org> (raw)
In-Reply-To: <20251122173712.76397-1-eslam.medhat1993@gmail.com>

On 22. 11. 25, 18:37, Eslam Khafagy wrote:
> Function dualshock4_get_calibration_data allocates memory to pointer
> buf .However, the function may exit prematurely due to transfer_failure
> in this case it does not handle freeing memory.
> 
> This patch handles memory deallocation at exit.

Isn't this fixed already by:
commit 8513c154f8ad7097653dd9bf43d6155e5aad4ab3
Author: Abdun Nihaal <nihaal@cse.iitm.ac.in>
Date:   Mon Nov 10 22:45:50 2025 +0530

     HID: playstation: Fix memory leak in dualshock4_get_calibration_data()
?

Anyway, this is a typical use-case for __free(). Why not to use that?

> Reported-by: syzbot+4f5f81e1456a1f645bf8@syzkaller.appspotmail.com
> Closes: https://lore.kernel.org/all/691560c4.a70a0220.3124cb.0019.GAE@google.com/T/
> Tested-by: syzbot+4f5f81e1456a1f645bf8@syzkaller.appspotmail.com
> Fixes: 947992c7fa9e0 ("HID: playstation: DS4: Fix calibration workaround for clone devices")
> Cc: stable@vger.kernel.org
> Signed-off-by: Eslam Khafagy <eslam.medhat1993@gmail.com>
> ---
> v3:
> * Address issues reported by checkpatch and re-format commit message
> for better readability
> * kfree() is safe so no need to check for NULL pointer
> 
> v2: https://lore.kernel.org/all/20251116022723.29857-1-eslam.medhat1993@gmail.com/
> * Adding tag "Cc: stable@vger.kernel.org"
> 
> v1: https://lore.kernel.org/all/20251115022323.1395726-1-eslam.medhat1993@gmail.com/
>   
> 
>   drivers/hid/hid-playstation.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/hid/hid-playstation.c b/drivers/hid/hid-playstation.c
> index 128aa6abd10b..05a8522ace4f 100644
> --- a/drivers/hid/hid-playstation.c
> +++ b/drivers/hid/hid-playstation.c
> @@ -1994,9 +1994,6 @@ static int dualshock4_get_calibration_data(struct dualshock4 *ds4)
>   	acc_z_plus       = get_unaligned_le16(&buf[31]);
>   	acc_z_minus      = get_unaligned_le16(&buf[33]);
>   
> -	/* Done parsing the buffer, so let's free it. */
> -	kfree(buf);
> -
>   	/*
>   	 * Set gyroscope calibration and normalization parameters.
>   	 * Data values will be normalized to 1/DS4_GYRO_RES_PER_DEG_S degree/s.
> @@ -2043,6 +2040,9 @@ static int dualshock4_get_calibration_data(struct dualshock4 *ds4)
>   	ds4->accel_calib_data[2].sens_denom = range_2g;
>   
>   transfer_failed:
> +	/* First free buf if still allocated */
> +	kfree(buf);
> +
>   	/*
>   	 * Sanity check gyro calibration data. This is needed to prevent crashes
>   	 * during report handling of virtual, clone or broken devices not implementing

-- 
js
suse labs


  parent reply	other threads:[~2025-11-24  6:32 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-22 17:37 Eslam Khafagy
2025-11-22 18:09 ` Max Staudt
2025-11-22 18:15 ` Markus Elfring
2025-11-24  6:32 ` Jiri Slaby [this message]
2025-11-24 14:06   ` Max Staudt
2025-11-25 18:19     ` Eslam Khafagy
2025-11-27 16:55       ` Max Staudt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=6251f6df-d4ac-4681-8e8b-6df2514e655b@kernel.org \
    --to=jirislaby@kernel.org \
    --cc=bentiss@kernel.org \
    --cc=eslam.medhat1993@gmail.com \
    --cc=jikos@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=max@enpas.org \
    --cc=roderick.colenbrander@sony.com \
    --cc=stable@vger.kernel.org \
    --cc=syzbot+4f5f81e1456a1f645bf8@syzkaller.appspotmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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®