From: Pietro Borrello <borrello@diag.uniroma1.it>
To: Jiri Kosina <jikos@kernel.org>,
Benjamin Tissoires <benjamin.tissoires@redhat.com>,
Hanno Zulla <kontakt@hanno.de>, Hanno Zulla <abos@hanno.de>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Cristiano Giuffrida <c.giuffrida@vu.nl>,
"Bos, H.J." <h.j.bos@vu.nl>, Jakob Koschel <jkl820.git@gmail.com>,
Jiri Kosina <jkosina@suse.cz>,
Roderick Colenbrander <roderick@gaikai.com>,
linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
Pietro Borrello <borrello@diag.uniroma1.it>
Subject: [PATCH v4 4/5] HID: asus: use spinlock to protect concurrent accesses
Date: Sun, 12 Feb 2023 19:00:02 +0000 [thread overview]
Message-ID: <20230125-hid-unregister-leds-v4-4-7860c5763c38@diag.uniroma1.it> (raw)
In-Reply-To: <20230125-hid-unregister-leds-v4-0-7860c5763c38@diag.uniroma1.it>
asus driver has a worker that may access data concurrently.
Proct the accesses using a spinlock.
Fixes: af22a610bc38 ("HID: asus: support backlight on USB keyboards")
Signed-off-by: Pietro Borrello <borrello@diag.uniroma1.it>
---
drivers/hid/hid-asus.c | 22 +++++++++++++++++++++-
1 file changed, 21 insertions(+), 1 deletion(-)
diff --git a/drivers/hid/hid-asus.c b/drivers/hid/hid-asus.c
index f99752b998f3..9f767baf39fb 100644
--- a/drivers/hid/hid-asus.c
+++ b/drivers/hid/hid-asus.c
@@ -98,6 +98,7 @@ struct asus_kbd_leds {
struct hid_device *hdev;
struct work_struct work;
unsigned int brightness;
+ spinlock_t lock;
bool removed;
};
@@ -495,7 +496,12 @@ static void asus_kbd_backlight_set(struct led_classdev *led_cdev,
{
struct asus_kbd_leds *led = container_of(led_cdev, struct asus_kbd_leds,
cdev);
+ unsigned long flags;
+
+ spin_lock_irqsave(&led->lock, flags);
led->brightness = brightness;
+ spin_unlock_irqrestore(&led->lock, flags);
+
schedule_work(&led->work);
}
@@ -503,8 +509,14 @@ static enum led_brightness asus_kbd_backlight_get(struct led_classdev *led_cdev)
{
struct asus_kbd_leds *led = container_of(led_cdev, struct asus_kbd_leds,
cdev);
+ enum led_brightness brightness;
+ unsigned long flags;
- return led->brightness;
+ spin_lock_irqsave(&led->lock, flags);
+ brightness = led->brightness;
+ spin_unlock_irqrestore(&led->lock, flags);
+
+ return brightness;
}
static void asus_kbd_backlight_work(struct work_struct *work)
@@ -512,11 +524,14 @@ static void asus_kbd_backlight_work(struct work_struct *work)
struct asus_kbd_leds *led = container_of(work, struct asus_kbd_leds, work);
u8 buf[] = { FEATURE_KBD_REPORT_ID, 0xba, 0xc5, 0xc4, 0x00 };
int ret;
+ unsigned long flags;
if (led->removed)
return;
+ spin_lock_irqsave(&led->lock, flags);
buf[4] = led->brightness;
+ spin_unlock_irqrestore(&led->lock, flags);
ret = asus_kbd_set_report(led->hdev, buf, sizeof(buf));
if (ret < 0)
@@ -584,6 +599,7 @@ static int asus_kbd_register_leds(struct hid_device *hdev)
drvdata->kbd_backlight->cdev.brightness_set = asus_kbd_backlight_set;
drvdata->kbd_backlight->cdev.brightness_get = asus_kbd_backlight_get;
INIT_WORK(&drvdata->kbd_backlight->work, asus_kbd_backlight_work);
+ spin_lock_init(&drvdata->kbd_backlight->lock);
ret = devm_led_classdev_register(&hdev->dev, &drvdata->kbd_backlight->cdev);
if (ret < 0) {
@@ -1119,9 +1135,13 @@ static int asus_probe(struct hid_device *hdev, const struct hid_device_id *id)
static void asus_remove(struct hid_device *hdev)
{
struct asus_drvdata *drvdata = hid_get_drvdata(hdev);
+ unsigned long flags;
if (drvdata->kbd_backlight) {
+ spin_lock_irqsave(&drvdata->kbd_backlight->lock, flags);
drvdata->kbd_backlight->removed = true;
+ spin_unlock_irqrestore(&drvdata->kbd_backlight->lock, flags);
+
cancel_work_sync(&drvdata->kbd_backlight->work);
}
--
2.25.1
next prev parent reply other threads:[~2023-02-12 19:01 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-12 18:59 [PATCH v4 0/5] HID: use spinlocks to safely schedule led workers Pietro Borrello
2023-02-12 18:59 ` [PATCH v4 1/5] HID: bigben: use spinlock to protect concurrent accesses Pietro Borrello
2023-02-12 19:00 ` [PATCH v4 2/5] HID: bigben_worker() remove unneeded check on report_field Pietro Borrello
2023-02-12 19:00 ` [PATCH v4 3/5] HID: bigben: use spinlock to safely schedule workers Pietro Borrello
2023-02-12 19:00 ` Pietro Borrello [this message]
2023-02-12 19:00 ` [PATCH v4 5/5] HID: asus: " Pietro Borrello
2023-02-15 18:18 ` (subset) [PATCH v4 0/5] HID: use spinlocks to safely schedule led workers Benjamin Tissoires
2023-02-15 18:20 ` Benjamin Tissoires
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=20230125-hid-unregister-leds-v4-4-7860c5763c38@diag.uniroma1.it \
--to=borrello@diag.uniroma1.it \
--cc=abos@hanno.de \
--cc=benjamin.tissoires@redhat.com \
--cc=c.giuffrida@vu.nl \
--cc=gregkh@linuxfoundation.org \
--cc=h.j.bos@vu.nl \
--cc=jikos@kernel.org \
--cc=jkl820.git@gmail.com \
--cc=jkosina@suse.cz \
--cc=kontakt@hanno.de \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=roderick@gaikai.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.