Skip to content

Commit

Permalink
HID: thingm: fix workqueue race on remove
Browse files Browse the repository at this point in the history
thingm_remove_rgb() needs to flush the workqueue after all the LED classes
have been unregistered, otherwise the removal might race with another LED
event coming, causing thingm_led_set() to schedule additional work after
thingm_remove_rgb() has flushed it. This obviously causes oops later, as
the scheduled work has been freed in the meantime.

In addition to that, move the hid_hw_stop() to an earlier place, so that
dmesg is not polluted by failure messages about not being able to write
the LED while the device is being shut down.

Reported-and-tested-by: Dylan Alex Simon <dylan-kernel@dylex.net>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
  • Loading branch information
Jiri Kosina committed Sep 4, 2014
1 parent 8f507ef commit 67a9784
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions drivers/hid/hid-thingm.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,10 @@ static int thingm_init_rgb(struct thingm_rgb *rgb)

static void thingm_remove_rgb(struct thingm_rgb *rgb)
{
flush_work(&rgb->work);
led_classdev_unregister(&rgb->red.ldev);
led_classdev_unregister(&rgb->green.ldev);
led_classdev_unregister(&rgb->blue.ldev);
flush_work(&rgb->work);
}

static int thingm_probe(struct hid_device *hdev, const struct hid_device_id *id)
Expand Down Expand Up @@ -286,10 +286,10 @@ static void thingm_remove(struct hid_device *hdev)
struct thingm_device *tdev = hid_get_drvdata(hdev);
int i;

hid_hw_stop(hdev);

for (i = 0; i < tdev->fwinfo->numrgb; ++i)
thingm_remove_rgb(tdev->rgb + i);

hid_hw_stop(hdev);
}

static const struct hid_device_id thingm_table[] = {
Expand Down

0 comments on commit 67a9784

Please sign in to comment.