aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hid
diff options
context:
space:
mode:
authorHanno Zulla <abos@hanno.de>2018-06-14 10:30:02 -0400
committerJiri Kosina <jkosina@suse.cz>2018-07-09 09:14:07 -0400
commitea4a5fdc8d07df9115881f698c14bcfd7046a846 (patch)
tree2a7ddee6df53c23013066c883179a57efcf7a9b3 /drivers/hid
parentcc070a847bc0b6fb66e4c05b5bd036d2ea80fb9a (diff)
HID: hid-sony.c: Use devm_ api to simplify sony_register_sensors()
[PATCH 2/5] HID: hid-sony.c: Use devm_ api to simplify sony_register_sensors() 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')
-rw-r--r--drivers/hid/hid-sony.c39
1 files changed, 5 insertions, 34 deletions
diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c
index f14286e62e15..ebad1381e177 100644
--- a/drivers/hid/hid-sony.c
+++ b/drivers/hid/hid-sony.c
@@ -1417,7 +1417,7 @@ static int sony_register_sensors(struct sony_sc *sc)
1417 int ret; 1417 int ret;
1418 int range; 1418 int range;
1419 1419
1420 sc->sensor_dev = input_allocate_device(); 1420 sc->sensor_dev = devm_input_allocate_device(&sc->hdev->dev);
1421 if (!sc->sensor_dev) 1421 if (!sc->sensor_dev)
1422 return -ENOMEM; 1422 return -ENOMEM;
1423 1423
@@ -1434,11 +1434,9 @@ static int sony_register_sensors(struct sony_sc *sc)
1434 * DS4 compatible non-Sony devices with different names. 1434 * DS4 compatible non-Sony devices with different names.
1435 */ 1435 */
1436 name_sz = strlen(sc->hdev->name) + sizeof(SENSOR_SUFFIX); 1436 name_sz = strlen(sc->hdev->name) + sizeof(SENSOR_SUFFIX);
1437 name = kzalloc(name_sz, GFP_KERNEL); 1437 name = devm_kzalloc(&sc->hdev->dev, name_sz, GFP_KERNEL);
1438 if (!name) { 1438 if (!name)
1439 ret = -ENOMEM; 1439 return -ENOMEM;
1440 goto err;
1441 }
1442 snprintf(name, name_sz, "%s" SENSOR_SUFFIX, sc->hdev->name); 1440 snprintf(name, name_sz, "%s" SENSOR_SUFFIX, sc->hdev->name);
1443 sc->sensor_dev->name = name; 1441 sc->sensor_dev->name = name;
1444 1442
@@ -1480,33 +1478,11 @@ static int sony_register_sensors(struct sony_sc *sc)
1480 1478
1481 ret = input_register_device(sc->sensor_dev); 1479 ret = input_register_device(sc->sensor_dev);
1482 if (ret < 0) 1480 if (ret < 0)
1483 goto err; 1481 return ret;
1484 1482
1485 return 0; 1483 return 0;
1486
1487err:
1488 kfree(sc->sensor_dev->name);
1489 sc->sensor_dev->name = NULL;
1490
1491 input_free_device(sc->sensor_dev);
1492 sc->sensor_dev = NULL;
1493
1494 return ret;
1495} 1484}
1496 1485
1497static void sony_unregister_sensors(struct sony_sc *sc)
1498{
1499 if (!sc->sensor_dev)
1500 return;
1501
1502 kfree(sc->sensor_dev->name);
1503 sc->sensor_dev->name = NULL;
1504
1505 input_unregister_device(sc->sensor_dev);
1506 sc->sensor_dev = NULL;
1507}
1508
1509
1510/* 1486/*
1511 * 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
1512 * to "operational". Without this, the ps3 controller will not report any 1488 * to "operational". Without this, the ps3 controller will not report any
@@ -2860,8 +2836,6 @@ err_stop:
2860 sony_leds_remove(sc); 2836 sony_leds_remove(sc);
2861 if (sc->quirks & SONY_BATTERY_SUPPORT) 2837 if (sc->quirks & SONY_BATTERY_SUPPORT)
2862 sony_battery_remove(sc); 2838 sony_battery_remove(sc);
2863 if (sc->sensor_dev)
2864 sony_unregister_sensors(sc);
2865 sony_cancel_work_sync(sc); 2839 sony_cancel_work_sync(sc);
2866 kfree(sc->output_report_dmabuf); 2840 kfree(sc->output_report_dmabuf);
2867 sony_remove_dev_list(sc); 2841 sony_remove_dev_list(sc);
@@ -2946,9 +2920,6 @@ static void sony_remove(struct hid_device *hdev)
2946 if (sc->quirks & SONY_BATTERY_SUPPORT) 2920 if (sc->quirks & SONY_BATTERY_SUPPORT)
2947 sony_battery_remove(sc); 2921 sony_battery_remove(sc);
2948 2922
2949 if (sc->sensor_dev)
2950 sony_unregister_sensors(sc);
2951
2952 if (sc->quirks & DUALSHOCK4_CONTROLLER_BT) 2923 if (sc->quirks & DUALSHOCK4_CONTROLLER_BT)
2953 device_remove_file(&sc->hdev->dev, &dev_attr_bt_poll_interval); 2924 device_remove_file(&sc->hdev->dev, &dev_attr_bt_poll_interval);
2954 2925