diff options
| -rw-r--r-- | drivers/hid/hid-sony.c | 164 |
1 files changed, 28 insertions, 136 deletions
diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c index e475c5073c99..9671a4bad643 100644 --- a/drivers/hid/hid-sony.c +++ b/drivers/hid/hid-sony.c | |||
| @@ -1353,7 +1353,7 @@ static int sony_register_touchpad(struct sony_sc *sc, int touch_count, | |||
| 1353 | char *name; | 1353 | char *name; |
| 1354 | int ret; | 1354 | int ret; |
| 1355 | 1355 | ||
| 1356 | sc->touchpad = input_allocate_device(); | 1356 | sc->touchpad = devm_input_allocate_device(&sc->hdev->dev); |
| 1357 | if (!sc->touchpad) | 1357 | if (!sc->touchpad) |
| 1358 | return -ENOMEM; | 1358 | return -ENOMEM; |
| 1359 | 1359 | ||
| @@ -1370,11 +1370,9 @@ static int sony_register_touchpad(struct sony_sc *sc, int touch_count, | |||
| 1370 | * DS4 compatible non-Sony devices with different names. | 1370 | * DS4 compatible non-Sony devices with different names. |
| 1371 | */ | 1371 | */ |
| 1372 | name_sz = strlen(sc->hdev->name) + sizeof(DS4_TOUCHPAD_SUFFIX); | 1372 | name_sz = strlen(sc->hdev->name) + sizeof(DS4_TOUCHPAD_SUFFIX); |
| 1373 | name = kzalloc(name_sz, GFP_KERNEL); | 1373 | name = devm_kzalloc(&sc->hdev->dev, name_sz, GFP_KERNEL); |
| 1374 | if (!name) { | 1374 | if (!name) |
| 1375 | ret = -ENOMEM; | 1375 | return -ENOMEM; |
| 1376 | goto err; | ||
| 1377 | } | ||
| 1378 | snprintf(name, name_sz, "%s" DS4_TOUCHPAD_SUFFIX, sc->hdev->name); | 1376 | snprintf(name, name_sz, "%s" DS4_TOUCHPAD_SUFFIX, sc->hdev->name); |
| 1379 | sc->touchpad->name = name; | 1377 | sc->touchpad->name = name; |
| 1380 | 1378 | ||
| @@ -1403,34 +1401,13 @@ static int sony_register_touchpad(struct sony_sc *sc, int touch_count, | |||
| 1403 | 1401 | ||
| 1404 | ret = input_mt_init_slots(sc->touchpad, touch_count, INPUT_MT_POINTER); | 1402 | ret = input_mt_init_slots(sc->touchpad, touch_count, INPUT_MT_POINTER); |
| 1405 | if (ret < 0) | 1403 | if (ret < 0) |
| 1406 | goto err; | 1404 | return ret; |
| 1407 | 1405 | ||
| 1408 | ret = input_register_device(sc->touchpad); | 1406 | ret = input_register_device(sc->touchpad); |
| 1409 | if (ret < 0) | 1407 | if (ret < 0) |
| 1410 | goto err; | 1408 | return ret; |
| 1411 | 1409 | ||
| 1412 | return 0; | 1410 | return 0; |
| 1413 | |||
| 1414 | err: | ||
| 1415 | kfree(sc->touchpad->name); | ||
| 1416 | sc->touchpad->name = NULL; | ||
| 1417 | |||
| 1418 | input_free_device(sc->touchpad); | ||
| 1419 | sc->touchpad = NULL; | ||
| 1420 | |||
| 1421 | return ret; | ||
| 1422 | } | ||
| 1423 | |||
| 1424 | static void sony_unregister_touchpad(struct sony_sc *sc) | ||
| 1425 | { | ||
| 1426 | if (!sc->touchpad) | ||
| 1427 | return; | ||
| 1428 | |||
| 1429 | kfree(sc->touchpad->name); | ||
| 1430 | sc->touchpad->name = NULL; | ||
| 1431 | |||
| 1432 | input_unregister_device(sc->touchpad); | ||
| 1433 | sc->touchpad = NULL; | ||
| 1434 | } | 1411 | } |
| 1435 | 1412 | ||
| 1436 | static int sony_register_sensors(struct sony_sc *sc) | 1413 | static int sony_register_sensors(struct sony_sc *sc) |
| @@ -1440,7 +1417,7 @@ static int sony_register_sensors(struct sony_sc *sc) | |||
| 1440 | int ret; | 1417 | int ret; |
| 1441 | int range; | 1418 | int range; |
| 1442 | 1419 | ||
| 1443 | sc->sensor_dev = input_allocate_device(); | 1420 | sc->sensor_dev = devm_input_allocate_device(&sc->hdev->dev); |
| 1444 | if (!sc->sensor_dev) | 1421 | if (!sc->sensor_dev) |
| 1445 | return -ENOMEM; | 1422 | return -ENOMEM; |
| 1446 | 1423 | ||
| @@ -1457,11 +1434,9 @@ static int sony_register_sensors(struct sony_sc *sc) | |||
| 1457 | * DS4 compatible non-Sony devices with different names. | 1434 | * DS4 compatible non-Sony devices with different names. |
| 1458 | */ | 1435 | */ |
| 1459 | name_sz = strlen(sc->hdev->name) + sizeof(SENSOR_SUFFIX); | 1436 | name_sz = strlen(sc->hdev->name) + sizeof(SENSOR_SUFFIX); |
| 1460 | name = kzalloc(name_sz, GFP_KERNEL); | 1437 | name = devm_kzalloc(&sc->hdev->dev, name_sz, GFP_KERNEL); |
| 1461 | if (!name) { | 1438 | if (!name) |
| 1462 | ret = -ENOMEM; | 1439 | return -ENOMEM; |
| 1463 | goto err; | ||
| 1464 | } | ||
| 1465 | snprintf(name, name_sz, "%s" SENSOR_SUFFIX, sc->hdev->name); | 1440 | snprintf(name, name_sz, "%s" SENSOR_SUFFIX, sc->hdev->name); |
| 1466 | sc->sensor_dev->name = name; | 1441 | sc->sensor_dev->name = name; |
| 1467 | 1442 | ||
| @@ -1503,33 +1478,11 @@ static int sony_register_sensors(struct sony_sc *sc) | |||
| 1503 | 1478 | ||
| 1504 | ret = input_register_device(sc->sensor_dev); | 1479 | ret = input_register_device(sc->sensor_dev); |
| 1505 | if (ret < 0) | 1480 | if (ret < 0) |
| 1506 | goto err; | 1481 | return ret; |
| 1507 | 1482 | ||
| 1508 | return 0; | 1483 | return 0; |
| 1509 | |||
| 1510 | err: | ||
| 1511 | kfree(sc->sensor_dev->name); | ||
| 1512 | sc->sensor_dev->name = NULL; | ||
| 1513 | |||
| 1514 | input_free_device(sc->sensor_dev); | ||
| 1515 | sc->sensor_dev = NULL; | ||
| 1516 | |||
| 1517 | return ret; | ||
| 1518 | } | 1484 | } |
| 1519 | 1485 | ||
| 1520 | static void sony_unregister_sensors(struct sony_sc *sc) | ||
| 1521 | { | ||
| 1522 | if (!sc->sensor_dev) | ||
| 1523 | return; | ||
| 1524 | |||
| 1525 | kfree(sc->sensor_dev->name); | ||
| 1526 | sc->sensor_dev->name = NULL; | ||
| 1527 | |||
| 1528 | input_unregister_device(sc->sensor_dev); | ||
| 1529 | sc->sensor_dev = NULL; | ||
| 1530 | } | ||
| 1531 | |||
| 1532 | |||
| 1533 | /* | 1486 | /* |
| 1534 | * Sending HID_REQ_GET_REPORT changes the operation mode of the ps3 controller | 1487 | * Sending HID_REQ_GET_REPORT changes the operation mode of the ps3 controller |
| 1535 | * to "operational". Without this, the ps3 controller will not report any | 1488 | * to "operational". Without this, the ps3 controller will not report any |
| @@ -1987,25 +1940,6 @@ static int sony_led_blink_set(struct led_classdev *led, unsigned long *delay_on, | |||
| 1987 | return 0; | 1940 | return 0; |
| 1988 | } | 1941 | } |
| 1989 | 1942 | ||
| 1990 | static void sony_leds_remove(struct sony_sc *sc) | ||
| 1991 | { | ||
| 1992 | struct led_classdev *led; | ||
| 1993 | int n; | ||
| 1994 | |||
| 1995 | BUG_ON(!(sc->quirks & SONY_LED_SUPPORT)); | ||
| 1996 | |||
| 1997 | for (n = 0; n < sc->led_count; n++) { | ||
| 1998 | led = sc->leds[n]; | ||
| 1999 | sc->leds[n] = NULL; | ||
| 2000 | if (!led) | ||
| 2001 | continue; | ||
| 2002 | led_classdev_unregister(led); | ||
| 2003 | kfree(led); | ||
| 2004 | } | ||
| 2005 | |||
| 2006 | sc->led_count = 0; | ||
| 2007 | } | ||
| 2008 | |||
| 2009 | static int sony_leds_init(struct sony_sc *sc) | 1943 | static int sony_leds_init(struct sony_sc *sc) |
| 2010 | { | 1944 | { |
| 2011 | struct hid_device *hdev = sc->hdev; | 1945 | struct hid_device *hdev = sc->hdev; |
| @@ -2078,11 +2012,10 @@ static int sony_leds_init(struct sony_sc *sc) | |||
| 2078 | if (use_ds4_names) | 2012 | if (use_ds4_names) |
| 2079 | 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; |
| 2080 | 2014 | ||
| 2081 | led = kzalloc(sizeof(struct led_classdev) + name_sz, GFP_KERNEL); | 2015 | led = devm_kzalloc(&hdev->dev, sizeof(struct led_classdev) + name_sz, GFP_KERNEL); |
| 2082 | if (!led) { | 2016 | if (!led) { |
| 2083 | 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); |
| 2084 | ret = -ENOMEM; | 2018 | return -ENOMEM; |
| 2085 | goto error_leds; | ||
| 2086 | } | 2019 | } |
| 2087 | 2020 | ||
| 2088 | name = (void *)(&led[1]); | 2021 | name = (void *)(&led[1]); |
| @@ -2103,21 +2036,14 @@ static int sony_leds_init(struct sony_sc *sc) | |||
| 2103 | 2036 | ||
| 2104 | sc->leds[n] = led; | 2037 | sc->leds[n] = led; |
| 2105 | 2038 | ||
| 2106 | ret = led_classdev_register(&hdev->dev, led); | 2039 | ret = devm_led_classdev_register(&hdev->dev, led); |
| 2107 | if (ret) { | 2040 | if (ret) { |
| 2108 | hid_err(hdev, "Failed to register LED %d\n", n); | 2041 | hid_err(hdev, "Failed to register LED %d\n", n); |
| 2109 | sc->leds[n] = NULL; | 2042 | return ret; |
| 2110 | kfree(led); | ||
| 2111 | goto error_leds; | ||
| 2112 | } | 2043 | } |
| 2113 | } | 2044 | } |
| 2114 | 2045 | ||
| 2115 | return ret; | 2046 | return 0; |
| 2116 | |||
| 2117 | error_leds: | ||
| 2118 | sony_leds_remove(sc); | ||
| 2119 | |||
| 2120 | return ret; | ||
| 2121 | } | 2047 | } |
| 2122 | 2048 | ||
| 2123 | static void sixaxis_send_output_report(struct sony_sc *sc) | 2049 | static void sixaxis_send_output_report(struct sony_sc *sc) |
| @@ -2276,16 +2202,20 @@ static int sony_allocate_output_report(struct sony_sc *sc) | |||
| 2276 | if ((sc->quirks & SIXAXIS_CONTROLLER) || | 2202 | if ((sc->quirks & SIXAXIS_CONTROLLER) || |
| 2277 | (sc->quirks & NAVIGATION_CONTROLLER)) | 2203 | (sc->quirks & NAVIGATION_CONTROLLER)) |
| 2278 | sc->output_report_dmabuf = | 2204 | sc->output_report_dmabuf = |
| 2279 | kmalloc(sizeof(union sixaxis_output_report_01), | 2205 | devm_kmalloc(&sc->hdev->dev, |
| 2206 | sizeof(union sixaxis_output_report_01), | ||
| 2280 | GFP_KERNEL); | 2207 | GFP_KERNEL); |
| 2281 | else if (sc->quirks & DUALSHOCK4_CONTROLLER_BT) | 2208 | else if (sc->quirks & DUALSHOCK4_CONTROLLER_BT) |
| 2282 | sc->output_report_dmabuf = kmalloc(DS4_OUTPUT_REPORT_0x11_SIZE, | 2209 | sc->output_report_dmabuf = devm_kmalloc(&sc->hdev->dev, |
| 2210 | DS4_OUTPUT_REPORT_0x11_SIZE, | ||
| 2283 | GFP_KERNEL); | 2211 | GFP_KERNEL); |
| 2284 | else if (sc->quirks & (DUALSHOCK4_CONTROLLER_USB | DUALSHOCK4_DONGLE)) | 2212 | else if (sc->quirks & (DUALSHOCK4_CONTROLLER_USB | DUALSHOCK4_DONGLE)) |
| 2285 | sc->output_report_dmabuf = kmalloc(DS4_OUTPUT_REPORT_0x05_SIZE, | 2213 | sc->output_report_dmabuf = devm_kmalloc(&sc->hdev->dev, |
| 2214 | DS4_OUTPUT_REPORT_0x05_SIZE, | ||
| 2286 | GFP_KERNEL); | 2215 | GFP_KERNEL); |
| 2287 | else if (sc->quirks & MOTION_CONTROLLER) | 2216 | else if (sc->quirks & MOTION_CONTROLLER) |
| 2288 | sc->output_report_dmabuf = kmalloc(MOTION_REPORT_0x02_SIZE, | 2217 | sc->output_report_dmabuf = devm_kmalloc(&sc->hdev->dev, |
| 2218 | MOTION_REPORT_0x02_SIZE, | ||
| 2289 | GFP_KERNEL); | 2219 | GFP_KERNEL); |
| 2290 | else | 2220 | else |
| 2291 | return 0; | 2221 | return 0; |
| @@ -2392,36 +2322,21 @@ static int sony_battery_probe(struct sony_sc *sc, int append_dev_id) | |||
| 2392 | sc->battery_desc.get_property = sony_battery_get_property; | 2322 | sc->battery_desc.get_property = sony_battery_get_property; |
| 2393 | sc->battery_desc.type = POWER_SUPPLY_TYPE_BATTERY; | 2323 | sc->battery_desc.type = POWER_SUPPLY_TYPE_BATTERY; |
| 2394 | sc->battery_desc.use_for_apm = 0; | 2324 | sc->battery_desc.use_for_apm = 0; |
| 2395 | sc->battery_desc.name = kasprintf(GFP_KERNEL, battery_str_fmt, | 2325 | sc->battery_desc.name = devm_kasprintf(&hdev->dev, GFP_KERNEL, |
| 2396 | sc->mac_address, sc->device_id); | 2326 | battery_str_fmt, sc->mac_address, sc->device_id); |
| 2397 | if (!sc->battery_desc.name) | 2327 | if (!sc->battery_desc.name) |
| 2398 | return -ENOMEM; | 2328 | return -ENOMEM; |
| 2399 | 2329 | ||
| 2400 | sc->battery = power_supply_register(&hdev->dev, &sc->battery_desc, | 2330 | sc->battery = devm_power_supply_register(&hdev->dev, &sc->battery_desc, |
| 2401 | &psy_cfg); | 2331 | &psy_cfg); |
| 2402 | if (IS_ERR(sc->battery)) { | 2332 | if (IS_ERR(sc->battery)) { |
| 2403 | ret = PTR_ERR(sc->battery); | 2333 | ret = PTR_ERR(sc->battery); |
| 2404 | hid_err(hdev, "Unable to register battery device\n"); | 2334 | hid_err(hdev, "Unable to register battery device\n"); |
| 2405 | goto err_free; | 2335 | return ret; |
| 2406 | } | 2336 | } |
| 2407 | 2337 | ||
| 2408 | power_supply_powers(sc->battery, &hdev->dev); | 2338 | power_supply_powers(sc->battery, &hdev->dev); |
| 2409 | return 0; | 2339 | return 0; |
| 2410 | |||
| 2411 | err_free: | ||
| 2412 | kfree(sc->battery_desc.name); | ||
| 2413 | sc->battery_desc.name = NULL; | ||
| 2414 | return ret; | ||
| 2415 | } | ||
| 2416 | |||
| 2417 | static void sony_battery_remove(struct sony_sc *sc) | ||
| 2418 | { | ||
| 2419 | if (!sc->battery_desc.name) | ||
| 2420 | return; | ||
| 2421 | |||
| 2422 | power_supply_unregister(sc->battery); | ||
| 2423 | kfree(sc->battery_desc.name); | ||
| 2424 | sc->battery_desc.name = NULL; | ||
| 2425 | } | 2340 | } |
| 2426 | 2341 | ||
| 2427 | /* | 2342 | /* |
| @@ -2879,16 +2794,7 @@ err_stop: | |||
| 2879 | device_remove_file(&sc->hdev->dev, &dev_attr_firmware_version); | 2794 | device_remove_file(&sc->hdev->dev, &dev_attr_firmware_version); |
| 2880 | if (sc->hw_version) | 2795 | if (sc->hw_version) |
| 2881 | device_remove_file(&sc->hdev->dev, &dev_attr_hardware_version); | 2796 | device_remove_file(&sc->hdev->dev, &dev_attr_hardware_version); |
| 2882 | if (sc->quirks & SONY_LED_SUPPORT) | ||
| 2883 | sony_leds_remove(sc); | ||
| 2884 | if (sc->quirks & SONY_BATTERY_SUPPORT) | ||
| 2885 | sony_battery_remove(sc); | ||
| 2886 | if (sc->touchpad) | ||
| 2887 | sony_unregister_touchpad(sc); | ||
| 2888 | if (sc->sensor_dev) | ||
| 2889 | sony_unregister_sensors(sc); | ||
| 2890 | sony_cancel_work_sync(sc); | 2797 | sony_cancel_work_sync(sc); |
| 2891 | kfree(sc->output_report_dmabuf); | ||
| 2892 | sony_remove_dev_list(sc); | 2798 | sony_remove_dev_list(sc); |
| 2893 | sony_release_device_id(sc); | 2799 | sony_release_device_id(sc); |
| 2894 | hid_hw_stop(hdev); | 2800 | hid_hw_stop(hdev); |
| @@ -2965,18 +2871,6 @@ static void sony_remove(struct hid_device *hdev) | |||
| 2965 | 2871 | ||
| 2966 | hid_hw_close(hdev); | 2872 | hid_hw_close(hdev); |
| 2967 | 2873 | ||
| 2968 | if (sc->quirks & SONY_LED_SUPPORT) | ||
| 2969 | sony_leds_remove(sc); | ||
| 2970 | |||
| 2971 | if (sc->quirks & SONY_BATTERY_SUPPORT) | ||
| 2972 | sony_battery_remove(sc); | ||
| 2973 | |||
| 2974 | if (sc->touchpad) | ||
| 2975 | sony_unregister_touchpad(sc); | ||
| 2976 | |||
| 2977 | if (sc->sensor_dev) | ||
| 2978 | sony_unregister_sensors(sc); | ||
| 2979 | |||
| 2980 | if (sc->quirks & DUALSHOCK4_CONTROLLER_BT) | 2874 | if (sc->quirks & DUALSHOCK4_CONTROLLER_BT) |
| 2981 | device_remove_file(&sc->hdev->dev, &dev_attr_bt_poll_interval); | 2875 | device_remove_file(&sc->hdev->dev, &dev_attr_bt_poll_interval); |
| 2982 | 2876 | ||
| @@ -2988,8 +2882,6 @@ static void sony_remove(struct hid_device *hdev) | |||
| 2988 | 2882 | ||
| 2989 | sony_cancel_work_sync(sc); | 2883 | sony_cancel_work_sync(sc); |
| 2990 | 2884 | ||
| 2991 | kfree(sc->output_report_dmabuf); | ||
| 2992 | |||
| 2993 | sony_remove_dev_list(sc); | 2885 | sony_remove_dev_list(sc); |
| 2994 | 2886 | ||
| 2995 | sony_release_device_id(sc); | 2887 | sony_release_device_id(sc); |
