Skip to content

Commit

Permalink
HID: hid-bigbenff: fix race condition for scheduled work during removal
Browse files Browse the repository at this point in the history
It's possible that there is scheduled work left while the device is
already being removed, which can cause a kernel crash. Adding a flag
will avoid this.

Signed-off-by: Hanno Zulla <kontakt@hanno.de>
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
  • Loading branch information
Hanno Zulla authored and Benjamin Tissoires committed Feb 18, 2020
1 parent 976a54d commit 4eb1b01
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions drivers/hid/hid-bigbenff.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ static __u8 pid0902_rdesc_fixed[] = {
struct bigben_device {
struct hid_device *hid;
struct hid_report *report;
bool removed;
u8 led_state; /* LED1 = 1 .. LED4 = 8 */
u8 right_motor_on; /* right motor off/on 0/1 */
u8 left_motor_force; /* left motor force 0-255 */
Expand All @@ -190,6 +191,9 @@ static void bigben_worker(struct work_struct *work)
struct bigben_device, worker);
struct hid_field *report_field = bigben->report->field[0];

if (bigben->removed)
return;

if (bigben->work_led) {
bigben->work_led = false;
report_field->value[0] = 0x01; /* 1 = led message */
Expand Down Expand Up @@ -304,6 +308,7 @@ static void bigben_remove(struct hid_device *hid)
{
struct bigben_device *bigben = hid_get_drvdata(hid);

bigben->removed = true;
cancel_work_sync(&bigben->worker);
hid_hw_stop(hid);
}
Expand All @@ -324,6 +329,7 @@ static int bigben_probe(struct hid_device *hid,
return -ENOMEM;
hid_set_drvdata(hid, bigben);
bigben->hid = hid;
bigben->removed = false;

error = hid_parse(hid);
if (error) {
Expand Down

0 comments on commit 4eb1b01

Please sign in to comment.