Commit 78a8ad79 authored by Jiri Kosina's avatar Jiri Kosina

Merge branch 'for-4.19/sony' into for-linus

devm_* API conversion for hid-sony
parents 16501e84 ea58c33d
...@@ -1353,7 +1353,7 @@ static int sony_register_touchpad(struct sony_sc *sc, int touch_count, ...@@ -1353,7 +1353,7 @@ static int sony_register_touchpad(struct sony_sc *sc, int touch_count,
char *name; char *name;
int ret; int ret;
sc->touchpad = input_allocate_device(); sc->touchpad = devm_input_allocate_device(&sc->hdev->dev);
if (!sc->touchpad) if (!sc->touchpad)
return -ENOMEM; return -ENOMEM;
...@@ -1370,11 +1370,9 @@ static int sony_register_touchpad(struct sony_sc *sc, int touch_count, ...@@ -1370,11 +1370,9 @@ static int sony_register_touchpad(struct sony_sc *sc, int touch_count,
* DS4 compatible non-Sony devices with different names. * DS4 compatible non-Sony devices with different names.
*/ */
name_sz = strlen(sc->hdev->name) + sizeof(DS4_TOUCHPAD_SUFFIX); name_sz = strlen(sc->hdev->name) + sizeof(DS4_TOUCHPAD_SUFFIX);
name = kzalloc(name_sz, GFP_KERNEL); name = devm_kzalloc(&sc->hdev->dev, name_sz, GFP_KERNEL);
if (!name) { if (!name)
ret = -ENOMEM; return -ENOMEM;
goto err;
}
snprintf(name, name_sz, "%s" DS4_TOUCHPAD_SUFFIX, sc->hdev->name); snprintf(name, name_sz, "%s" DS4_TOUCHPAD_SUFFIX, sc->hdev->name);
sc->touchpad->name = name; sc->touchpad->name = name;
...@@ -1403,34 +1401,13 @@ static int sony_register_touchpad(struct sony_sc *sc, int touch_count, ...@@ -1403,34 +1401,13 @@ static int sony_register_touchpad(struct sony_sc *sc, int touch_count,
ret = input_mt_init_slots(sc->touchpad, touch_count, INPUT_MT_POINTER); ret = input_mt_init_slots(sc->touchpad, touch_count, INPUT_MT_POINTER);
if (ret < 0) if (ret < 0)
goto err; return ret;
ret = input_register_device(sc->touchpad); ret = input_register_device(sc->touchpad);
if (ret < 0) if (ret < 0)
goto err;
return 0;
err:
kfree(sc->touchpad->name);
sc->touchpad->name = NULL;
input_free_device(sc->touchpad);
sc->touchpad = NULL;
return ret; return ret;
}
static void sony_unregister_touchpad(struct sony_sc *sc)
{
if (!sc->touchpad)
return;
kfree(sc->touchpad->name);
sc->touchpad->name = NULL;
input_unregister_device(sc->touchpad); return 0;
sc->touchpad = NULL;
} }
static int sony_register_sensors(struct sony_sc *sc) static int sony_register_sensors(struct sony_sc *sc)
...@@ -1440,7 +1417,7 @@ static int sony_register_sensors(struct sony_sc *sc) ...@@ -1440,7 +1417,7 @@ static int sony_register_sensors(struct sony_sc *sc)
int ret; int ret;
int range; int range;
sc->sensor_dev = input_allocate_device(); sc->sensor_dev = devm_input_allocate_device(&sc->hdev->dev);
if (!sc->sensor_dev) if (!sc->sensor_dev)
return -ENOMEM; return -ENOMEM;
...@@ -1457,11 +1434,9 @@ static int sony_register_sensors(struct sony_sc *sc) ...@@ -1457,11 +1434,9 @@ static int sony_register_sensors(struct sony_sc *sc)
* DS4 compatible non-Sony devices with different names. * DS4 compatible non-Sony devices with different names.
*/ */
name_sz = strlen(sc->hdev->name) + sizeof(SENSOR_SUFFIX); name_sz = strlen(sc->hdev->name) + sizeof(SENSOR_SUFFIX);
name = kzalloc(name_sz, GFP_KERNEL); name = devm_kzalloc(&sc->hdev->dev, name_sz, GFP_KERNEL);
if (!name) { if (!name)
ret = -ENOMEM; return -ENOMEM;
goto err;
}
snprintf(name, name_sz, "%s" SENSOR_SUFFIX, sc->hdev->name); snprintf(name, name_sz, "%s" SENSOR_SUFFIX, sc->hdev->name);
sc->sensor_dev->name = name; sc->sensor_dev->name = name;
...@@ -1503,33 +1478,11 @@ static int sony_register_sensors(struct sony_sc *sc) ...@@ -1503,33 +1478,11 @@ static int sony_register_sensors(struct sony_sc *sc)
ret = input_register_device(sc->sensor_dev); ret = input_register_device(sc->sensor_dev);
if (ret < 0) if (ret < 0)
goto err;
return 0;
err:
kfree(sc->sensor_dev->name);
sc->sensor_dev->name = NULL;
input_free_device(sc->sensor_dev);
sc->sensor_dev = NULL;
return ret; return ret;
}
static void sony_unregister_sensors(struct sony_sc *sc)
{
if (!sc->sensor_dev)
return;
kfree(sc->sensor_dev->name);
sc->sensor_dev->name = NULL;
input_unregister_device(sc->sensor_dev); return 0;
sc->sensor_dev = NULL;
} }
/* /*
* Sending HID_REQ_GET_REPORT changes the operation mode of the ps3 controller * Sending HID_REQ_GET_REPORT changes the operation mode of the ps3 controller
* to "operational". Without this, the ps3 controller will not report any * 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,25 +1940,6 @@ static int sony_led_blink_set(struct led_classdev *led, unsigned long *delay_on,
return 0; 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) static int sony_leds_init(struct sony_sc *sc)
{ {
struct hid_device *hdev = sc->hdev; struct hid_device *hdev = sc->hdev;
...@@ -2078,11 +2012,10 @@ static int sony_leds_init(struct sony_sc *sc) ...@@ -2078,11 +2012,10 @@ static int sony_leds_init(struct sony_sc *sc)
if (use_ds4_names) if (use_ds4_names)
name_sz = strlen(dev_name(&hdev->dev)) + strlen(ds4_name_str[n]) + 2; 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) { if (!led) {
hid_err(hdev, "Couldn't allocate memory for LED %d\n", n); hid_err(hdev, "Couldn't allocate memory for LED %d\n", n);
ret = -ENOMEM; return -ENOMEM;
goto error_leds;
} }
name = (void *)(&led[1]); name = (void *)(&led[1]);
...@@ -2103,21 +2036,14 @@ static int sony_leds_init(struct sony_sc *sc) ...@@ -2103,21 +2036,14 @@ static int sony_leds_init(struct sony_sc *sc)
sc->leds[n] = led; sc->leds[n] = led;
ret = led_classdev_register(&hdev->dev, led); ret = devm_led_classdev_register(&hdev->dev, led);
if (ret) { if (ret) {
hid_err(hdev, "Failed to register LED %d\n", n); hid_err(hdev, "Failed to register LED %d\n", n);
sc->leds[n] = NULL; return ret;
kfree(led);
goto error_leds;
} }
} }
return ret; return 0;
error_leds:
sony_leds_remove(sc);
return ret;
} }
static void sixaxis_send_output_report(struct sony_sc *sc) 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,16 +2202,20 @@ static int sony_allocate_output_report(struct sony_sc *sc)
if ((sc->quirks & SIXAXIS_CONTROLLER) || if ((sc->quirks & SIXAXIS_CONTROLLER) ||
(sc->quirks & NAVIGATION_CONTROLLER)) (sc->quirks & NAVIGATION_CONTROLLER))
sc->output_report_dmabuf = sc->output_report_dmabuf =
kmalloc(sizeof(union sixaxis_output_report_01), devm_kmalloc(&sc->hdev->dev,
sizeof(union sixaxis_output_report_01),
GFP_KERNEL); GFP_KERNEL);
else if (sc->quirks & DUALSHOCK4_CONTROLLER_BT) else if (sc->quirks & DUALSHOCK4_CONTROLLER_BT)
sc->output_report_dmabuf = kmalloc(DS4_OUTPUT_REPORT_0x11_SIZE, sc->output_report_dmabuf = devm_kmalloc(&sc->hdev->dev,
DS4_OUTPUT_REPORT_0x11_SIZE,
GFP_KERNEL); GFP_KERNEL);
else if (sc->quirks & (DUALSHOCK4_CONTROLLER_USB | DUALSHOCK4_DONGLE)) else if (sc->quirks & (DUALSHOCK4_CONTROLLER_USB | DUALSHOCK4_DONGLE))
sc->output_report_dmabuf = kmalloc(DS4_OUTPUT_REPORT_0x05_SIZE, sc->output_report_dmabuf = devm_kmalloc(&sc->hdev->dev,
DS4_OUTPUT_REPORT_0x05_SIZE,
GFP_KERNEL); GFP_KERNEL);
else if (sc->quirks & MOTION_CONTROLLER) else if (sc->quirks & MOTION_CONTROLLER)
sc->output_report_dmabuf = kmalloc(MOTION_REPORT_0x02_SIZE, sc->output_report_dmabuf = devm_kmalloc(&sc->hdev->dev,
MOTION_REPORT_0x02_SIZE,
GFP_KERNEL); GFP_KERNEL);
else else
return 0; return 0;
...@@ -2392,36 +2322,21 @@ static int sony_battery_probe(struct sony_sc *sc, int append_dev_id) ...@@ -2392,36 +2322,21 @@ static int sony_battery_probe(struct sony_sc *sc, int append_dev_id)
sc->battery_desc.get_property = sony_battery_get_property; sc->battery_desc.get_property = sony_battery_get_property;
sc->battery_desc.type = POWER_SUPPLY_TYPE_BATTERY; sc->battery_desc.type = POWER_SUPPLY_TYPE_BATTERY;
sc->battery_desc.use_for_apm = 0; sc->battery_desc.use_for_apm = 0;
sc->battery_desc.name = kasprintf(GFP_KERNEL, battery_str_fmt, sc->battery_desc.name = devm_kasprintf(&hdev->dev, GFP_KERNEL,
sc->mac_address, sc->device_id); battery_str_fmt, sc->mac_address, sc->device_id);
if (!sc->battery_desc.name) if (!sc->battery_desc.name)
return -ENOMEM; return -ENOMEM;
sc->battery = power_supply_register(&hdev->dev, &sc->battery_desc, sc->battery = devm_power_supply_register(&hdev->dev, &sc->battery_desc,
&psy_cfg); &psy_cfg);
if (IS_ERR(sc->battery)) { if (IS_ERR(sc->battery)) {
ret = PTR_ERR(sc->battery); ret = PTR_ERR(sc->battery);
hid_err(hdev, "Unable to register battery device\n"); hid_err(hdev, "Unable to register battery device\n");
goto err_free; return ret;
} }
power_supply_powers(sc->battery, &hdev->dev); power_supply_powers(sc->battery, &hdev->dev);
return 0; return 0;
err_free:
kfree(sc->battery_desc.name);
sc->battery_desc.name = NULL;
return ret;
}
static void sony_battery_remove(struct sony_sc *sc)
{
if (!sc->battery_desc.name)
return;
power_supply_unregister(sc->battery);
kfree(sc->battery_desc.name);
sc->battery_desc.name = NULL;
} }
/* /*
...@@ -2879,16 +2794,7 @@ static int sony_input_configured(struct hid_device *hdev, ...@@ -2879,16 +2794,7 @@ static int sony_input_configured(struct hid_device *hdev,
device_remove_file(&sc->hdev->dev, &dev_attr_firmware_version); device_remove_file(&sc->hdev->dev, &dev_attr_firmware_version);
if (sc->hw_version) if (sc->hw_version)
device_remove_file(&sc->hdev->dev, &dev_attr_hardware_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);
if (sc->touchpad)
sony_unregister_touchpad(sc);
if (sc->sensor_dev)
sony_unregister_sensors(sc);
sony_cancel_work_sync(sc); sony_cancel_work_sync(sc);
kfree(sc->output_report_dmabuf);
sony_remove_dev_list(sc); sony_remove_dev_list(sc);
sony_release_device_id(sc); sony_release_device_id(sc);
hid_hw_stop(hdev); hid_hw_stop(hdev);
...@@ -2965,18 +2871,6 @@ static void sony_remove(struct hid_device *hdev) ...@@ -2965,18 +2871,6 @@ static void sony_remove(struct hid_device *hdev)
hid_hw_close(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);
if (sc->touchpad)
sony_unregister_touchpad(sc);
if (sc->sensor_dev)
sony_unregister_sensors(sc);
if (sc->quirks & DUALSHOCK4_CONTROLLER_BT) if (sc->quirks & DUALSHOCK4_CONTROLLER_BT)
device_remove_file(&sc->hdev->dev, &dev_attr_bt_poll_interval); device_remove_file(&sc->hdev->dev, &dev_attr_bt_poll_interval);
...@@ -2988,8 +2882,6 @@ static void sony_remove(struct hid_device *hdev) ...@@ -2988,8 +2882,6 @@ static void sony_remove(struct hid_device *hdev)
sony_cancel_work_sync(sc); sony_cancel_work_sync(sc);
kfree(sc->output_report_dmabuf);
sony_remove_dev_list(sc); sony_remove_dev_list(sc);
sony_release_device_id(sc); sony_release_device_id(sc);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment