summaryrefslogtreecommitdiffstats
path: root/drivers/hid/hid-sony.c
diff options
context:
space:
mode:
authorHanno Zulla <abos@hanno.de>2018-06-14 16:30:46 +0200
committerJiri Kosina <jkosina@suse.cz>2018-07-09 15:14:07 +0200
commitf2d98e2c020e8f33813a746ac8a92a4582ac416a (patch)
tree550f948d9ede0abcdc985db79b2e183f3f320e8b /drivers/hid/hid-sony.c
parentea4a5fdc8d07df9115881f698c14bcfd7046a846 (diff)
downloadlinux-f2d98e2c020e8f33813a746ac8a92a4582ac416a.tar.bz2
HID: hid-sony.c: Use devm_ api to simplify sony_leds_init()
[PATCH 3/5] HID: hid-sony.c: Use devm_ api to simplify sony_leds_init() Using devm_ calls, the resources of the Sony game devices's features are tied to the main device handle, making it easier to handle errors and teardown inside the device driver. Altogether, this reduces complexity of the driver source. Signed-off-by: Hanno Zulla <kontakt@hanno.de> Reviewed-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers/hid/hid-sony.c')
-rw-r--r--drivers/hid/hid-sony.c42
1 files changed, 5 insertions, 37 deletions
diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c
index ebad1381e177..7c1c56d13122 100644
--- a/drivers/hid/hid-sony.c
+++ b/drivers/hid/hid-sony.c
@@ -1940,25 +1940,6 @@ static int sony_led_blink_set(struct led_classdev *led, unsigned long *delay_on,
return 0;
}
-static void sony_leds_remove(struct sony_sc *sc)
-{
- struct led_classdev *led;
- int n;
-
- BUG_ON(!(sc->quirks & SONY_LED_SUPPORT));
-
- for (n = 0; n < sc->led_count; n++) {
- led = sc->leds[n];
- sc->leds[n] = NULL;
- if (!led)
- continue;
- led_classdev_unregister(led);
- kfree(led);
- }
-
- sc->led_count = 0;
-}
-
static int sony_leds_init(struct sony_sc *sc)
{
struct hid_device *hdev = sc->hdev;
@@ -2031,11 +2012,10 @@ static int sony_leds_init(struct sony_sc *sc)
if (use_ds4_names)
name_sz = strlen(dev_name(&hdev->dev)) + strlen(ds4_name_str[n]) + 2;
- led = kzalloc(sizeof(struct led_classdev) + name_sz, GFP_KERNEL);
+ led = devm_kzalloc(&hdev->dev, sizeof(struct led_classdev) + name_sz, GFP_KERNEL);
if (!led) {
hid_err(hdev, "Couldn't allocate memory for LED %d\n", n);
- ret = -ENOMEM;
- goto error_leds;
+ return -ENOMEM;
}
name = (void *)(&led[1]);
@@ -2056,21 +2036,14 @@ static int sony_leds_init(struct sony_sc *sc)
sc->leds[n] = led;
- ret = led_classdev_register(&hdev->dev, led);
+ ret = devm_led_classdev_register(&hdev->dev, led);
if (ret) {
hid_err(hdev, "Failed to register LED %d\n", n);
- sc->leds[n] = NULL;
- kfree(led);
- goto error_leds;
+ return ret;
}
}
- return ret;
-
-error_leds:
- sony_leds_remove(sc);
-
- return ret;
+ return 0;
}
static void sixaxis_send_output_report(struct sony_sc *sc)
@@ -2832,8 +2805,6 @@ err_stop:
device_remove_file(&sc->hdev->dev, &dev_attr_firmware_version);
if (sc->hw_version)
device_remove_file(&sc->hdev->dev, &dev_attr_hardware_version);
- if (sc->quirks & SONY_LED_SUPPORT)
- sony_leds_remove(sc);
if (sc->quirks & SONY_BATTERY_SUPPORT)
sony_battery_remove(sc);
sony_cancel_work_sync(sc);
@@ -2914,9 +2885,6 @@ static void sony_remove(struct hid_device *hdev)
hid_hw_close(hdev);
- if (sc->quirks & SONY_LED_SUPPORT)
- sony_leds_remove(sc);
-
if (sc->quirks & SONY_BATTERY_SUPPORT)
sony_battery_remove(sc);