mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] HID: logitech-hidpp: Fix FF device cleanup on init failure
@ 2026-06-23  6:52 Haoxiang Li
  2026-07-27 13:31 ` Bastien Nocera
  2026-08-03 17:26 ` Jiri Kosina
  0 siblings, 2 replies; 3+ messages in thread
From: Haoxiang Li @ 2026-06-23  6:52 UTC (permalink / raw)
  To: lains, hadess, jikos, bentiss, e.velds
  Cc: linux-input, linux-kernel, Haoxiang Li

hidpp_ff_init() creates the input force-feedback device with
input_ff_create(), then allocates the HID++ FF private data,
effect ID array, and workqueue.

If any of those allocations fail after input_ff_create() succeeds,
the function returns an error without destroying the FF device.
Add an unwind path that frees the private allocations made by
hidpp_ff_init() and calls input_ff_destroy() for failures after
input_ff_create() succeeds.

Fixes: ff21a635dd1a ("HID: logitech-hidpp: Force feedback support for the Logitech G920")
Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com>
---
 drivers/hid/hid-logitech-hidpp.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c
index 90b0184df777..fb2062233df2 100644
--- a/drivers/hid/hid-logitech-hidpp.c
+++ b/drivers/hid/hid-logitech-hidpp.c
@@ -2861,18 +2861,19 @@ static int hidpp_ff_init(struct hidpp_device *hidpp,
 	 * ownership to FF core
 	 */
 	data = kmemdup(data, sizeof(*data), GFP_KERNEL);
-	if (!data)
-		return -ENOMEM;
+	if (!data) {
+		error = -ENOMEM;
+		goto err_destroy_ff;
+	}
 	data->effect_ids = kzalloc_objs(int, num_slots);
 	if (!data->effect_ids) {
-		kfree(data);
-		return -ENOMEM;
+		error = -ENOMEM;
+		goto err_free_data;
 	}
 	data->wq = create_singlethread_workqueue("hidpp-ff-sendqueue");
 	if (!data->wq) {
-		kfree(data->effect_ids);
-		kfree(data);
-		return -ENOMEM;
+		error = -ENOMEM;
+		goto err_free_effect_ids;
 	}
 
 	data->hidpp = hidpp;
@@ -2902,6 +2903,14 @@ static int hidpp_ff_init(struct hidpp_device *hidpp,
 		 version);
 
 	return 0;
+
+err_free_effect_ids:
+	kfree(data->effect_ids);
+err_free_data:
+	kfree(data);
+err_destroy_ff:
+	input_ff_destroy(dev);
+	return error;
 }
 
 /* ************************************************************************** */
-- 
2.25.1


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

* Re: [PATCH] HID: logitech-hidpp: Fix FF device cleanup on init failure
  2026-06-23  6:52 [PATCH] HID: logitech-hidpp: Fix FF device cleanup on init failure Haoxiang Li
@ 2026-07-27 13:31 ` Bastien Nocera
  2026-08-03 17:26 ` Jiri Kosina
  1 sibling, 0 replies; 3+ messages in thread
From: Bastien Nocera @ 2026-07-27 13:31 UTC (permalink / raw)
  To: Haoxiang Li, lains, jikos, bentiss, e.velds; +Cc: linux-input, linux-kernel

On Tue, 2026-06-23 at 14:52 +0800, Haoxiang Li wrote:
> hidpp_ff_init() creates the input force-feedback device with
> input_ff_create(), then allocates the HID++ FF private data,
> effect ID array, and workqueue.
> 
> If any of those allocations fail after input_ff_create() succeeds,
> the function returns an error without destroying the FF device.
> Add an unwind path that frees the private allocations made by
> hidpp_ff_init() and calls input_ff_destroy() for failures after
> input_ff_create() succeeds.
> 
> Fixes: ff21a635dd1a ("HID: logitech-hidpp: Force feedback support for
> the Logitech G920")
> Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com>

Looks correct. I wish there was an easier way to handle this.

It looks like hid-bigbenff.c doesn't handle post-input_ff_create*
failure properly either.

Reviewed-by: Bastien Nocera <hadess@hadess.net>

> ---
>  drivers/hid/hid-logitech-hidpp.c | 23 ++++++++++++++++-------
>  1 file changed, 16 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-
> logitech-hidpp.c
> index 90b0184df777..fb2062233df2 100644
> --- a/drivers/hid/hid-logitech-hidpp.c
> +++ b/drivers/hid/hid-logitech-hidpp.c
> @@ -2861,18 +2861,19 @@ static int hidpp_ff_init(struct hidpp_device
> *hidpp,
>  	 * ownership to FF core
>  	 */
>  	data = kmemdup(data, sizeof(*data), GFP_KERNEL);
> -	if (!data)
> -		return -ENOMEM;
> +	if (!data) {
> +		error = -ENOMEM;
> +		goto err_destroy_ff;
> +	}
>  	data->effect_ids = kzalloc_objs(int, num_slots);
>  	if (!data->effect_ids) {
> -		kfree(data);
> -		return -ENOMEM;
> +		error = -ENOMEM;
> +		goto err_free_data;
>  	}
>  	data->wq = create_singlethread_workqueue("hidpp-ff-
> sendqueue");
>  	if (!data->wq) {
> -		kfree(data->effect_ids);
> -		kfree(data);
> -		return -ENOMEM;
> +		error = -ENOMEM;
> +		goto err_free_effect_ids;
>  	}
>  
>  	data->hidpp = hidpp;
> @@ -2902,6 +2903,14 @@ static int hidpp_ff_init(struct hidpp_device
> *hidpp,
>  		 version);
>  
>  	return 0;
> +
> +err_free_effect_ids:
> +	kfree(data->effect_ids);
> +err_free_data:
> +	kfree(data);
> +err_destroy_ff:
> +	input_ff_destroy(dev);
> +	return error;
>  }
>  
>  /*
> *********************************************************************
> ***** */

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

* Re: [PATCH] HID: logitech-hidpp: Fix FF device cleanup on init failure
  2026-06-23  6:52 [PATCH] HID: logitech-hidpp: Fix FF device cleanup on init failure Haoxiang Li
  2026-07-27 13:31 ` Bastien Nocera
@ 2026-08-03 17:26 ` Jiri Kosina
  1 sibling, 0 replies; 3+ messages in thread
From: Jiri Kosina @ 2026-08-03 17:26 UTC (permalink / raw)
  To: Haoxiang Li; +Cc: lains, hadess, bentiss, e.velds, linux-input, linux-kernel

On Tue, 23 Jun 2026, Haoxiang Li wrote:

> hidpp_ff_init() creates the input force-feedback device with
> input_ff_create(), then allocates the HID++ FF private data,
> effect ID array, and workqueue.
> 
> If any of those allocations fail after input_ff_create() succeeds,
> the function returns an error without destroying the FF device.
> Add an unwind path that frees the private allocations made by
> hidpp_ff_init() and calls input_ff_destroy() for failures after
> input_ff_create() succeeds.
> 
> Fixes: ff21a635dd1a ("HID: logitech-hidpp: Force feedback support for the Logitech G920")
> Signed-off-by: Haoxiang Li <haoxiang_li2024@163.com>

Applied, thanks.

-- 
Jiri Kosina
SUSE Labs


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

end of thread, other threads:[~2026-08-03 17:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-06-23  6:52 [PATCH] HID: logitech-hidpp: Fix FF device cleanup on init failure Haoxiang Li
2026-07-27 13:31 ` Bastien Nocera
2026-08-03 17:26 ` 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®