From: Hans de Goede <hansg@kernel.org>
To: Torstein Eide <torsteine+linux@gmail.com>,
Jiri Kosina <jikos@kernel.org>,
Benjamin Tissoires <bentiss@kernel.org>
Cc: Maoyi Xie <maoyixie.tju@gmail.com>,
linux-input@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 4/4] HID: lg-g15: cancel LED work only after stopping the hardware
Date: Mon, 9 Nov 2026 15:01:19 +0100 [thread overview]
Message-ID: <a66f889b-f827-4b4f-9d3d-abe4fc939780@kernel.org> (raw)
In-Reply-To: <20261109094426.1432465-5-torsteine+linux@gmail.com>
Hi,
On 9-Nov-26 10:44, Torstein Eide wrote:
> lg_g15_remove() cancels g15->work before calling hid_hw_stop(). In
> between, a backlight or game-mode key press makes raw_event call
> schedule_work() again. The work then runs after remove() has returned
> and devm has freed g15, which is a use-after-free in
> lg_g15_leds_changed_work().
>
> Cancel the work after hid_hw_stop(), once no more raw events can arrive.
This is not necessary the hid-core avoids the raw_event callback getting
called during remove() by hid_device_remove() doing:
down(&hdev->driver_input_lock);
before calling the drivers remove callback.
Regards,
Hans
>
> Fixes: 7705b4140d18 ("HID: lg-g15: cancel pending work on remove to fix a use-after-free")
> Signed-off-by: Torstein Eide <torsteine+linux@gmail.com>
> Assisted-by: Claude:claude-opus-5-5
> ---
> drivers/hid/hid-lg-g15.c | 13 +++++++------
> 1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/hid/hid-lg-g15.c b/drivers/hid/hid-lg-g15.c
> index 592c9747738e..a341b0aca249 100644
> --- a/drivers/hid/hid-lg-g15.c
> +++ b/drivers/hid/hid-lg-g15.c
> @@ -1927,18 +1927,19 @@ static void lg_g15_remove(struct hid_device *hdev)
>
> g15 = hid_get_drvdata(hdev);
>
> + if (g15)
> + lg_g15_unregister_fb(g15);
> +
> + hid_hw_stop(hdev);
> +
> /*
> * g15->work is only initialized for the models that schedule it
> * (G15, G15 v2, G510). The G13 and Z-10 leave it zeroed, so only
> - * cancel it when it was set up.
> + * cancel it when it was set up. Cancel it after hid_hw_stop(), as
> + * until then raw_event can still schedule it again.
> */
> if (g15 && g15->work.func)
> cancel_work_sync(&g15->work);
> -
> - if (g15)
> - lg_g15_unregister_fb(g15);
> -
> - hid_hw_stop(hdev);
> }
>
> /*
next prev parent reply other threads:[~2026-11-09 14:01 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-09 9:44 [PATCH 0/4] HID: lg-g15: G15 v2 LCD and game-mode support Torstein Eide
2026-11-09 9:44 ` [PATCH 1/4] HID: lg-g15: add LCD contrast LED Torstein Eide
2026-11-09 9:44 ` [PATCH 2/4] HID: lg-g15: add LCD pixel-content framebuffer Torstein Eide
2026-11-09 9:44 ` [PATCH 3/4] HID: lg-g15: report Super-key-lock state on G15 v2's keyboard interface Torstein Eide
2026-11-09 9:44 ` [PATCH 4/4] HID: lg-g15: cancel LED work only after stopping the hardware Torstein Eide
2026-11-09 14:01 ` Hans de Goede [this message]
2026-11-09 13:49 ` [PATCH 0/4] HID: lg-g15: G15 v2 LCD and game-mode support Hans de Goede
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=a66f889b-f827-4b4f-9d3d-abe4fc939780@kernel.org \
--to=hansg@kernel.org \
--cc=bentiss@kernel.org \
--cc=jikos@kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maoyixie.tju@gmail.com \
--cc=torsteine+linux@gmail.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®