Skip to content

Commit

Permalink
HID: sony: Fix work queue issues.
Browse files Browse the repository at this point in the history
Don't initialize force-feedback for devices that don't support it to avoid calls
to schedule_work() with an uninitialized work_struct.

Move the cancel_work_sync() call out of sony_destroy_ff() since the state worker
is used for the LEDs even when force-feedback is disabled.

Remove sony_destroy_ff() to avoid a compiler warning since it is no longer used.

Signed-off-by: Frank Praznik <frank.praznik@oh.rr.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
  • Loading branch information
Frank Praznik authored and Jiri Kosina committed Feb 20, 2014
1 parent 3ccfd0a commit 5f5750d
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions drivers/hid/hid-sony.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#define DUALSHOCK4_CONTROLLER_BT BIT(6)

#define SONY_LED_SUPPORT (SIXAXIS_CONTROLLER_USB | BUZZ_CONTROLLER | DUALSHOCK4_CONTROLLER_USB)
#define SONY_FF_SUPPORT (SIXAXIS_CONTROLLER_USB | DUALSHOCK4_CONTROLLER_USB)

#define MAX_LEDS 4

Expand Down Expand Up @@ -499,6 +500,7 @@ struct sony_sc {
__u8 right;
#endif

__u8 worker_initialized;
__u8 led_state[MAX_LEDS];
__u8 led_count;
};
Expand Down Expand Up @@ -993,22 +995,11 @@ static int sony_init_ff(struct hid_device *hdev)
return input_ff_create_memless(input_dev, NULL, sony_play_effect);
}

static void sony_destroy_ff(struct hid_device *hdev)
{
struct sony_sc *sc = hid_get_drvdata(hdev);

cancel_work_sync(&sc->state_worker);
}

#else
static int sony_init_ff(struct hid_device *hdev)
{
return 0;
}

static void sony_destroy_ff(struct hid_device *hdev)
{
}
#endif

static int sony_set_output_report(struct sony_sc *sc, int req_id, int req_size)
Expand Down Expand Up @@ -1077,6 +1068,8 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
if (sc->quirks & SIXAXIS_CONTROLLER_USB) {
hdev->hid_output_raw_report = sixaxis_usb_output_raw_report;
ret = sixaxis_set_operational_usb(hdev);

sc->worker_initialized = 1;
INIT_WORK(&sc->state_worker, sixaxis_state_worker);
}
else if (sc->quirks & SIXAXIS_CONTROLLER_BT)
Expand All @@ -1087,6 +1080,7 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
if (ret < 0)
goto err_stop;

sc->worker_initialized = 1;
INIT_WORK(&sc->state_worker, dualshock4_state_worker);
} else {
ret = 0;
Expand All @@ -1101,9 +1095,11 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id)
goto err_stop;
}

ret = sony_init_ff(hdev);
if (ret < 0)
goto err_stop;
if (sc->quirks & SONY_FF_SUPPORT) {
ret = sony_init_ff(hdev);
if (ret < 0)
goto err_stop;
}

return 0;
err_stop:
Expand All @@ -1120,7 +1116,8 @@ static void sony_remove(struct hid_device *hdev)
if (sc->quirks & SONY_LED_SUPPORT)
sony_leds_remove(hdev);

sony_destroy_ff(hdev);
if (sc->worker_initialized)
cancel_work_sync(&sc->state_worker);

hid_hw_stop(hdev);
}
Expand Down

0 comments on commit 5f5750d

Please sign in to comment.