aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hid/hid-sensor-hub.c
diff options
context:
space:
mode:
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>2013-08-14 04:07:10 -0400
committerJiri Kosina <jkosina@suse.cz>2013-09-04 06:19:13 -0400
commit905cc1991aa839fc4c9030f505966ab34637379a (patch)
tree2e329e7f6c38a9837c4da615271a904f3e61de5b /drivers/hid/hid-sensor-hub.c
parent5902fde19a3b3e51a0a246e98d337f291bbc07b0 (diff)
HID: hid-sensor-hub: move to devm_kzalloc
devm_kzalloc() will manage resources freeing and allows to make error path smaller and nicer. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers/hid/hid-sensor-hub.c')
-rw-r--r--drivers/hid/hid-sensor-hub.c17
1 files changed, 5 insertions, 12 deletions
diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c
index 7ebef9c7444a..1877a2552483 100644
--- a/drivers/hid/hid-sensor-hub.c
+++ b/drivers/hid/hid-sensor-hub.c
@@ -477,16 +477,15 @@ static int sensor_hub_probe(struct hid_device *hdev,
477 struct hid_field *field; 477 struct hid_field *field;
478 int dev_cnt; 478 int dev_cnt;
479 479
480 sd = kzalloc(sizeof(struct sensor_hub_data), GFP_KERNEL); 480 sd = devm_kzalloc(&hdev->dev, sizeof(*sd), GFP_KERNEL);
481 if (!sd) { 481 if (!sd) {
482 hid_err(hdev, "cannot allocate Sensor data\n"); 482 hid_err(hdev, "cannot allocate Sensor data\n");
483 return -ENOMEM; 483 return -ENOMEM;
484 } 484 }
485 sd->hsdev = kzalloc(sizeof(struct hid_sensor_hub_device), GFP_KERNEL); 485 sd->hsdev = devm_kzalloc(&hdev->dev, sizeof(*sd->hsdev), GFP_KERNEL);
486 if (!sd->hsdev) { 486 if (!sd->hsdev) {
487 hid_err(hdev, "cannot allocate hid_sensor_hub_device\n"); 487 hid_err(hdev, "cannot allocate hid_sensor_hub_device\n");
488 ret = -ENOMEM; 488 return -ENOMEM;
489 goto err_free_hub;
490 } 489 }
491 hid_set_drvdata(hdev, sd); 490 hid_set_drvdata(hdev, sd);
492 sd->hsdev->hdev = hdev; 491 sd->hsdev->hdev = hdev;
@@ -498,14 +497,14 @@ static int sensor_hub_probe(struct hid_device *hdev,
498 ret = hid_parse(hdev); 497 ret = hid_parse(hdev);
499 if (ret) { 498 if (ret) {
500 hid_err(hdev, "parse failed\n"); 499 hid_err(hdev, "parse failed\n");
501 goto err_free; 500 return ret;
502 } 501 }
503 INIT_LIST_HEAD(&hdev->inputs); 502 INIT_LIST_HEAD(&hdev->inputs);
504 503
505 ret = hid_hw_start(hdev, 0); 504 ret = hid_hw_start(hdev, 0);
506 if (ret) { 505 if (ret) {
507 hid_err(hdev, "hw start failed\n"); 506 hid_err(hdev, "hw start failed\n");
508 goto err_free; 507 return ret;
509 } 508 }
510 ret = hid_hw_open(hdev); 509 ret = hid_hw_open(hdev);
511 if (ret) { 510 if (ret) {
@@ -570,10 +569,6 @@ err_close:
570 hid_hw_close(hdev); 569 hid_hw_close(hdev);
571err_stop_hw: 570err_stop_hw:
572 hid_hw_stop(hdev); 571 hid_hw_stop(hdev);
573err_free:
574 kfree(sd->hsdev);
575err_free_hub:
576 kfree(sd);
577 572
578 return ret; 573 return ret;
579} 574}
@@ -597,8 +592,6 @@ static void sensor_hub_remove(struct hid_device *hdev)
597 kfree(data->hid_sensor_hub_client_devs); 592 kfree(data->hid_sensor_hub_client_devs);
598 hid_set_drvdata(hdev, NULL); 593 hid_set_drvdata(hdev, NULL);
599 mutex_destroy(&data->mutex); 594 mutex_destroy(&data->mutex);
600 kfree(data->hsdev);
601 kfree(data);
602} 595}
603 596
604static const struct hid_device_id sensor_hub_devices[] = { 597static const struct hid_device_id sensor_hub_devices[] = {