Commit 4eb1b01d authored by Hanno Zulla's avatar Hanno Zulla Committed by Benjamin Tissoires

HID: hid-bigbenff: fix race condition for scheduled work during removal

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: default avatarHanno Zulla <kontakt@hanno.de>
Signed-off-by: default avatarBenjamin Tissoires <benjamin.tissoires@redhat.com>
parent 976a54d0
...@@ -174,6 +174,7 @@ static __u8 pid0902_rdesc_fixed[] = { ...@@ -174,6 +174,7 @@ static __u8 pid0902_rdesc_fixed[] = {
struct bigben_device { struct bigben_device {
struct hid_device *hid; struct hid_device *hid;
struct hid_report *report; struct hid_report *report;
bool removed;
u8 led_state; /* LED1 = 1 .. LED4 = 8 */ u8 led_state; /* LED1 = 1 .. LED4 = 8 */
u8 right_motor_on; /* right motor off/on 0/1 */ u8 right_motor_on; /* right motor off/on 0/1 */
u8 left_motor_force; /* left motor force 0-255 */ u8 left_motor_force; /* left motor force 0-255 */
...@@ -190,6 +191,9 @@ static void bigben_worker(struct work_struct *work) ...@@ -190,6 +191,9 @@ static void bigben_worker(struct work_struct *work)
struct bigben_device, worker); struct bigben_device, worker);
struct hid_field *report_field = bigben->report->field[0]; struct hid_field *report_field = bigben->report->field[0];
if (bigben->removed)
return;
if (bigben->work_led) { if (bigben->work_led) {
bigben->work_led = false; bigben->work_led = false;
report_field->value[0] = 0x01; /* 1 = led message */ report_field->value[0] = 0x01; /* 1 = led message */
...@@ -304,6 +308,7 @@ static void bigben_remove(struct hid_device *hid) ...@@ -304,6 +308,7 @@ static void bigben_remove(struct hid_device *hid)
{ {
struct bigben_device *bigben = hid_get_drvdata(hid); struct bigben_device *bigben = hid_get_drvdata(hid);
bigben->removed = true;
cancel_work_sync(&bigben->worker); cancel_work_sync(&bigben->worker);
hid_hw_stop(hid); hid_hw_stop(hid);
} }
...@@ -324,6 +329,7 @@ static int bigben_probe(struct hid_device *hid, ...@@ -324,6 +329,7 @@ static int bigben_probe(struct hid_device *hid,
return -ENOMEM; return -ENOMEM;
hid_set_drvdata(hid, bigben); hid_set_drvdata(hid, bigben);
bigben->hid = hid; bigben->hid = hid;
bigben->removed = false;
error = hid_parse(hid); error = hid_parse(hid);
if (error) { if (error) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment