mirror of
https://github.com/Fishwaldo/linux-bl808.git
synced 2025-06-17 20:25:19 +00:00
HID: trivial devm conversion for special hid drivers
It is safe to use devres allocation within the hid subsystem: - the devres release is called _after_ the call to .remove(), meaning that no freed pointers will exists while removing the device - if a .probe() fails, devres releases all the allocated ressources before going to the next driver: there will not be ghost ressources attached to a hid device if several drivers are probed. Given that, we can clean up a little some of the HID drivers. These ones are trivial: - there is only one kzalloc in the driver - the .remove() callback contains only one kfree on top of hid_hw_stop() - the error path in the probe is easy enough to be manually checked Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
This commit is contained in:
parent
3366dd9fa8
commit
abf832bfc3
5 changed files with 16 additions and 66 deletions
|
@ -90,11 +90,10 @@ static int a4_probe(struct hid_device *hdev, const struct hid_device_id *id)
|
|||
struct a4tech_sc *a4;
|
||||
int ret;
|
||||
|
||||
a4 = kzalloc(sizeof(*a4), GFP_KERNEL);
|
||||
a4 = devm_kzalloc(&hdev->dev, sizeof(*a4), GFP_KERNEL);
|
||||
if (a4 == NULL) {
|
||||
hid_err(hdev, "can't alloc device descriptor\n");
|
||||
ret = -ENOMEM;
|
||||
goto err_free;
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
a4->quirks = id->driver_data;
|
||||
|
@ -104,27 +103,16 @@ static int a4_probe(struct hid_device *hdev, const struct hid_device_id *id)
|
|||
ret = hid_parse(hdev);
|
||||
if (ret) {
|
||||
hid_err(hdev, "parse failed\n");
|
||||
goto err_free;
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT);
|
||||
if (ret) {
|
||||
hid_err(hdev, "hw start failed\n");
|
||||
goto err_free;
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
err_free:
|
||||
kfree(a4);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void a4_remove(struct hid_device *hdev)
|
||||
{
|
||||
struct a4tech_sc *a4 = hid_get_drvdata(hdev);
|
||||
|
||||
hid_hw_stop(hdev);
|
||||
kfree(a4);
|
||||
}
|
||||
|
||||
static const struct hid_device_id a4_devices[] = {
|
||||
|
@ -144,7 +132,6 @@ static struct hid_driver a4_driver = {
|
|||
.input_mapped = a4_input_mapped,
|
||||
.event = a4_event,
|
||||
.probe = a4_probe,
|
||||
.remove = a4_remove,
|
||||
};
|
||||
module_hid_driver(a4_driver);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue