Skip to content

Commit 4eb1b01

Browse files
Hanno Zullabentiss
authored andcommitted
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: Hanno Zulla <[email protected]> Signed-off-by: Benjamin Tissoires <[email protected]>
1 parent 976a54d commit 4eb1b01

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

drivers/hid/hid-bigbenff.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ static __u8 pid0902_rdesc_fixed[] = {
174174
struct bigben_device {
175175
struct hid_device *hid;
176176
struct hid_report *report;
177+
bool removed;
177178
u8 led_state; /* LED1 = 1 .. LED4 = 8 */
178179
u8 right_motor_on; /* right motor off/on 0/1 */
179180
u8 left_motor_force; /* left motor force 0-255 */
@@ -190,6 +191,9 @@ static void bigben_worker(struct work_struct *work)
190191
struct bigben_device, worker);
191192
struct hid_field *report_field = bigben->report->field[0];
192193

194+
if (bigben->removed)
195+
return;
196+
193197
if (bigben->work_led) {
194198
bigben->work_led = false;
195199
report_field->value[0] = 0x01; /* 1 = led message */
@@ -304,6 +308,7 @@ static void bigben_remove(struct hid_device *hid)
304308
{
305309
struct bigben_device *bigben = hid_get_drvdata(hid);
306310

311+
bigben->removed = true;
307312
cancel_work_sync(&bigben->worker);
308313
hid_hw_stop(hid);
309314
}
@@ -324,6 +329,7 @@ static int bigben_probe(struct hid_device *hid,
324329
return -ENOMEM;
325330
hid_set_drvdata(hid, bigben);
326331
bigben->hid = hid;
332+
bigben->removed = false;
327333

328334
error = hid_parse(hid);
329335
if (error) {

0 commit comments

Comments
 (0)