aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHanno Zulla <abos@hanno.de>2018-06-14 10:30:46 -0400
committerJiri Kosina <jkosina@suse.cz>2018-07-09 09:14:07 -0400
commitf2d98e2c020e8f33813a746ac8a92a4582ac416a (patch)
tree550f948d9ede0abcdc985db79b2e183f3f320e8b
parentea4a5fdc8d07df9115881f698c14bcfd7046a846 (diff)
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>
-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,
1940 return 0; 1940 return 0;
1941} 1941}
1942 1942
1943static void sony_leds_remove(struct sony_sc *sc)
1944{
1945 struct led_classdev *led;
1946 int n;
1947
1948 BUG_ON(!(sc->quirks & SONY_LED_SUPPORT));
1949
1950 for (n = 0; n < sc->led_count; n++) {
1951 led = sc->leds[n];
1952 sc->leds[n] = NULL;
1953 if (!led)
1954 continue;
1955 led_classdev_unregister(led);
1956 kfree(led);
1957 }
1958
1959 sc->led_count = 0;
1960}
1961
1962static int sony_leds_init(struct sony_sc *sc) 1943static int sony_leds_init(struct sony_sc *sc)
1963{ 1944{
1964 struct hid_device *hdev = sc->hdev; 1945 struct hid_device *hdev = sc->hdev;
@@ -2031,11 +2012,10 @@ static int sony_leds_init(struct sony_sc *sc)
2031 if (use_ds4_names) 2012 if (use_ds4_names)
2032 name_sz = strlen(dev_name(&hdev->dev)) + strlen(ds4_name_str[n]) + 2; 2013 name_sz = strlen(dev_name(&hdev->dev)) + strlen(ds4_name_str[n]) + 2;
2033 2014
2034 led = kzalloc(sizeof(struct led_classdev) + name_sz, GFP_KERNEL); 2015 led = devm_kzalloc(&hdev->dev, sizeof(struct led_classdev) + name_sz, GFP_KERNEL);
2035 if (!led) { 2016 if (!led) {
2036 hid_err(hdev, "Couldn't allocate memory for LED %d\n", n); 2017 hid_err(hdev, "Couldn't allocate memory for LED %d\n", n);
2037 ret = -ENOMEM; 2018 return -ENOMEM;
2038 goto error_leds;
2039 } 2019 }
2040 2020
2041 name = (void *)(&led[1]); 2021 name = (void *)(&led[1]);
@@ -2056,21 +2036,14 @@ static int sony_leds_init(struct sony_sc *sc)
2056 2036
2057 sc->leds[n] = led; 2037 sc->leds[n] = led;
2058 2038
2059 ret = led_classdev_register(&hdev->dev, led); 2039 ret = devm_led_classdev_register(&hdev->dev, led);
2060 if (ret) { 2040 if (ret) {
2061 hid_err(hdev, "Failed to register LED %d\n", n); 2041 hid_err(hdev, "Failed to register LED %d\n", n);
2062 sc->leds[n] = NULL; 2042 return ret;
2063 kfree(led);
2064 goto error_leds;
2065 } 2043 }
2066 } 2044 }
2067 2045
2068 return ret; 2046 return 0;
2069
2070error_leds:
2071 sony_leds_remove(sc);
2072
2073 return ret;
2074} 2047}
2075 2048
2076static void sixaxis_send_output_report(struct sony_sc *sc) 2049static void sixaxis_send_output_report(struct sony_sc *sc)
@@ -2832,8 +2805,6 @@ err_stop:
2832 device_remove_file(&sc->hdev->dev, &dev_attr_firmware_version); 2805 device_remove_file(&sc->hdev->dev, &dev_attr_firmware_version);
2833 if (sc->hw_version) 2806 if (sc->hw_version)
2834 device_remove_file(&sc->hdev->dev, &dev_attr_hardware_version); 2807 device_remove_file(&sc->hdev->dev, &dev_attr_hardware_version);
2835 if (sc->quirks & SONY_LED_SUPPORT)
2836 sony_leds_remove(sc);
2837 if (sc->quirks & SONY_BATTERY_SUPPORT) 2808 if (sc->quirks & SONY_BATTERY_SUPPORT)
2838 sony_battery_remove(sc); 2809 sony_battery_remove(sc);
2839 sony_cancel_work_sync(sc); 2810 sony_cancel_work_sync(sc);
@@ -2914,9 +2885,6 @@ static void sony_remove(struct hid_device *hdev)
2914 2885
2915 hid_hw_close(hdev); 2886 hid_hw_close(hdev);
2916 2887
2917 if (sc->quirks & SONY_LED_SUPPORT)
2918 sony_leds_remove(sc);
2919
2920 if (sc->quirks & SONY_BATTERY_SUPPORT) 2888 if (sc->quirks & SONY_BATTERY_SUPPORT)
2921 sony_battery_remove(sc); 2889 sony_battery_remove(sc);
2922 2890