diff options
-rw-r--r-- | drivers/hid/hid-sensor-hub.c | 33 |
1 files changed, 11 insertions, 22 deletions
diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c index e244e449cbba..2ac25760a9a9 100644 --- a/drivers/hid/hid-sensor-hub.c +++ b/drivers/hid/hid-sensor-hub.c | |||
@@ -604,9 +604,9 @@ static int sensor_hub_probe(struct hid_device *hdev, | |||
604 | ret = -EINVAL; | 604 | ret = -EINVAL; |
605 | goto err_stop_hw; | 605 | goto err_stop_hw; |
606 | } | 606 | } |
607 | sd->hid_sensor_hub_client_devs = kzalloc(dev_cnt * | 607 | sd->hid_sensor_hub_client_devs = devm_kzalloc(&hdev->dev, dev_cnt * |
608 | sizeof(struct mfd_cell), | 608 | sizeof(struct mfd_cell), |
609 | GFP_KERNEL); | 609 | GFP_KERNEL); |
610 | if (sd->hid_sensor_hub_client_devs == NULL) { | 610 | if (sd->hid_sensor_hub_client_devs == NULL) { |
611 | hid_err(hdev, "Failed to allocate memory for mfd cells\n"); | 611 | hid_err(hdev, "Failed to allocate memory for mfd cells\n"); |
612 | ret = -ENOMEM; | 612 | ret = -ENOMEM; |
@@ -618,11 +618,12 @@ static int sensor_hub_probe(struct hid_device *hdev, | |||
618 | 618 | ||
619 | if (collection->type == HID_COLLECTION_PHYSICAL) { | 619 | if (collection->type == HID_COLLECTION_PHYSICAL) { |
620 | 620 | ||
621 | hsdev = kzalloc(sizeof(*hsdev), GFP_KERNEL); | 621 | hsdev = devm_kzalloc(&hdev->dev, sizeof(*hsdev), |
622 | GFP_KERNEL); | ||
622 | if (!hsdev) { | 623 | if (!hsdev) { |
623 | hid_err(hdev, "cannot allocate hid_sensor_hub_device\n"); | 624 | hid_err(hdev, "cannot allocate hid_sensor_hub_device\n"); |
624 | ret = -ENOMEM; | 625 | ret = -ENOMEM; |
625 | goto err_no_mem; | 626 | goto err_stop_hw; |
626 | } | 627 | } |
627 | hsdev->hdev = hdev; | 628 | hsdev->hdev = hdev; |
628 | hsdev->vendor_id = hdev->vendor; | 629 | hsdev->vendor_id = hdev->vendor; |
@@ -631,13 +632,13 @@ static int sensor_hub_probe(struct hid_device *hdev, | |||
631 | if (last_hsdev) | 632 | if (last_hsdev) |
632 | last_hsdev->end_collection_index = i; | 633 | last_hsdev->end_collection_index = i; |
633 | last_hsdev = hsdev; | 634 | last_hsdev = hsdev; |
634 | name = kasprintf(GFP_KERNEL, "HID-SENSOR-%x", | 635 | name = devm_kasprintf(&hdev->dev, GFP_KERNEL, |
635 | collection->usage); | 636 | "HID-SENSOR-%x", |
637 | collection->usage); | ||
636 | if (name == NULL) { | 638 | if (name == NULL) { |
637 | hid_err(hdev, "Failed MFD device name\n"); | 639 | hid_err(hdev, "Failed MFD device name\n"); |
638 | ret = -ENOMEM; | 640 | ret = -ENOMEM; |
639 | kfree(hsdev); | 641 | goto err_stop_hw; |
640 | goto err_no_mem; | ||
641 | } | 642 | } |
642 | sd->hid_sensor_hub_client_devs[ | 643 | sd->hid_sensor_hub_client_devs[ |
643 | sd->hid_sensor_client_cnt].id = | 644 | sd->hid_sensor_client_cnt].id = |
@@ -661,16 +662,10 @@ static int sensor_hub_probe(struct hid_device *hdev, | |||
661 | ret = mfd_add_devices(&hdev->dev, 0, sd->hid_sensor_hub_client_devs, | 662 | ret = mfd_add_devices(&hdev->dev, 0, sd->hid_sensor_hub_client_devs, |
662 | sd->hid_sensor_client_cnt, NULL, 0, NULL); | 663 | sd->hid_sensor_client_cnt, NULL, 0, NULL); |
663 | if (ret < 0) | 664 | if (ret < 0) |
664 | goto err_no_mem; | 665 | goto err_stop_hw; |
665 | 666 | ||
666 | return ret; | 667 | return ret; |
667 | 668 | ||
668 | err_no_mem: | ||
669 | for (i = 0; i < sd->hid_sensor_client_cnt; ++i) { | ||
670 | kfree(sd->hid_sensor_hub_client_devs[i].name); | ||
671 | kfree(sd->hid_sensor_hub_client_devs[i].platform_data); | ||
672 | } | ||
673 | kfree(sd->hid_sensor_hub_client_devs); | ||
674 | err_stop_hw: | 669 | err_stop_hw: |
675 | hid_hw_stop(hdev); | 670 | hid_hw_stop(hdev); |
676 | 671 | ||
@@ -681,7 +676,6 @@ static void sensor_hub_remove(struct hid_device *hdev) | |||
681 | { | 676 | { |
682 | struct sensor_hub_data *data = hid_get_drvdata(hdev); | 677 | struct sensor_hub_data *data = hid_get_drvdata(hdev); |
683 | unsigned long flags; | 678 | unsigned long flags; |
684 | int i; | ||
685 | 679 | ||
686 | hid_dbg(hdev, " hardware removed\n"); | 680 | hid_dbg(hdev, " hardware removed\n"); |
687 | hid_hw_close(hdev); | 681 | hid_hw_close(hdev); |
@@ -691,11 +685,6 @@ static void sensor_hub_remove(struct hid_device *hdev) | |||
691 | complete(&data->pending.ready); | 685 | complete(&data->pending.ready); |
692 | spin_unlock_irqrestore(&data->lock, flags); | 686 | spin_unlock_irqrestore(&data->lock, flags); |
693 | mfd_remove_devices(&hdev->dev); | 687 | mfd_remove_devices(&hdev->dev); |
694 | for (i = 0; i < data->hid_sensor_client_cnt; ++i) { | ||
695 | kfree(data->hid_sensor_hub_client_devs[i].name); | ||
696 | kfree(data->hid_sensor_hub_client_devs[i].platform_data); | ||
697 | } | ||
698 | kfree(data->hid_sensor_hub_client_devs); | ||
699 | hid_set_drvdata(hdev, NULL); | 688 | hid_set_drvdata(hdev, NULL); |
700 | mutex_destroy(&data->mutex); | 689 | mutex_destroy(&data->mutex); |
701 | } | 690 | } |