diff options
author | Guenter Roeck <linux@roeck-us.net> | 2012-06-02 15:04:07 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2012-07-22 00:48:43 -0400 |
commit | 08ad7c9522c22eea1912d41ee9418154b8760ea9 (patch) | |
tree | 9e1aebf1700740cf2602f0be91c99c0ebca5b200 /drivers/hwmon | |
parent | e43d5fefa7fe4e5d0999033753c15e1f30e06ff6 (diff) |
hwmon: (smsc47m1) Convert to use devm_ functions
Convert to use devm_ functions to reduce code size and simplify the code.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Acked-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r-- | drivers/hwmon/smsc47m1.c | 45 |
1 files changed, 11 insertions, 34 deletions
diff --git a/drivers/hwmon/smsc47m1.c b/drivers/hwmon/smsc47m1.c index b5aa38dd7ab9..dba0c567e7a1 100644 --- a/drivers/hwmon/smsc47m1.c +++ b/drivers/hwmon/smsc47m1.c | |||
@@ -584,18 +584,17 @@ static void smsc47m1_restore(const struct smsc47m1_sio_data *sio_data) | |||
584 | 584 | ||
585 | #define CHECK 1 | 585 | #define CHECK 1 |
586 | #define REQUEST 2 | 586 | #define REQUEST 2 |
587 | #define RELEASE 3 | ||
588 | 587 | ||
589 | /* | 588 | /* |
590 | * This function can be used to: | 589 | * This function can be used to: |
591 | * - test for resource conflicts with ACPI | 590 | * - test for resource conflicts with ACPI |
592 | * - request the resources | 591 | * - request the resources |
593 | * - release the resources | ||
594 | * We only allocate the I/O ports we really need, to minimize the risk of | 592 | * We only allocate the I/O ports we really need, to minimize the risk of |
595 | * conflicts with ACPI or with other drivers. | 593 | * conflicts with ACPI or with other drivers. |
596 | */ | 594 | */ |
597 | static int smsc47m1_handle_resources(unsigned short address, enum chips type, | 595 | static int __init smsc47m1_handle_resources(unsigned short address, |
598 | int action, struct device *dev) | 596 | enum chips type, int action, |
597 | struct device *dev) | ||
599 | { | 598 | { |
600 | static const u8 ports_m1[] = { | 599 | static const u8 ports_m1[] = { |
601 | /* register, region length */ | 600 | /* register, region length */ |
@@ -642,21 +641,13 @@ static int smsc47m1_handle_resources(unsigned short address, enum chips type, | |||
642 | break; | 641 | break; |
643 | case REQUEST: | 642 | case REQUEST: |
644 | /* Request the resources */ | 643 | /* Request the resources */ |
645 | if (!request_region(start, len, DRVNAME)) { | 644 | if (!devm_request_region(dev, start, len, DRVNAME)) { |
646 | dev_err(dev, "Region 0x%hx-0x%hx already in " | 645 | dev_err(dev, |
647 | "use!\n", start, start + len); | 646 | "Region 0x%hx-0x%hx already in use!\n", |
648 | 647 | start, start + len); | |
649 | /* Undo all requests */ | ||
650 | for (i -= 2; i >= 0; i -= 2) | ||
651 | release_region(address + ports[i], | ||
652 | ports[i + 1]); | ||
653 | return -EBUSY; | 648 | return -EBUSY; |
654 | } | 649 | } |
655 | break; | 650 | break; |
656 | case RELEASE: | ||
657 | /* Release the resources */ | ||
658 | release_region(start, len); | ||
659 | break; | ||
660 | } | 651 | } |
661 | } | 652 | } |
662 | 653 | ||
@@ -694,11 +685,9 @@ static int __init smsc47m1_probe(struct platform_device *pdev) | |||
694 | if (err < 0) | 685 | if (err < 0) |
695 | return err; | 686 | return err; |
696 | 687 | ||
697 | data = kzalloc(sizeof(struct smsc47m1_data), GFP_KERNEL); | 688 | data = devm_kzalloc(dev, sizeof(struct smsc47m1_data), GFP_KERNEL); |
698 | if (!data) { | 689 | if (!data) |
699 | err = -ENOMEM; | 690 | return -ENOMEM; |
700 | goto error_release; | ||
701 | } | ||
702 | 691 | ||
703 | data->addr = res->start; | 692 | data->addr = res->start; |
704 | data->type = sio_data->type; | 693 | data->type = sio_data->type; |
@@ -733,8 +722,7 @@ static int __init smsc47m1_probe(struct platform_device *pdev) | |||
733 | } | 722 | } |
734 | if (!(fan1 || fan2 || fan3 || pwm1 || pwm2 || pwm3)) { | 723 | if (!(fan1 || fan2 || fan3 || pwm1 || pwm2 || pwm3)) { |
735 | dev_warn(dev, "Device not configured, will not use\n"); | 724 | dev_warn(dev, "Device not configured, will not use\n"); |
736 | err = -ENODEV; | 725 | return -ENODEV; |
737 | goto error_free; | ||
738 | } | 726 | } |
739 | 727 | ||
740 | /* | 728 | /* |
@@ -810,27 +798,16 @@ static int __init smsc47m1_probe(struct platform_device *pdev) | |||
810 | 798 | ||
811 | error_remove_files: | 799 | error_remove_files: |
812 | smsc47m1_remove_files(dev); | 800 | smsc47m1_remove_files(dev); |
813 | error_free: | ||
814 | platform_set_drvdata(pdev, NULL); | ||
815 | kfree(data); | ||
816 | error_release: | ||
817 | smsc47m1_handle_resources(res->start, sio_data->type, RELEASE, dev); | ||
818 | return err; | 801 | return err; |
819 | } | 802 | } |
820 | 803 | ||
821 | static int __exit smsc47m1_remove(struct platform_device *pdev) | 804 | static int __exit smsc47m1_remove(struct platform_device *pdev) |
822 | { | 805 | { |
823 | struct smsc47m1_data *data = platform_get_drvdata(pdev); | 806 | struct smsc47m1_data *data = platform_get_drvdata(pdev); |
824 | struct resource *res; | ||
825 | 807 | ||
826 | hwmon_device_unregister(data->hwmon_dev); | 808 | hwmon_device_unregister(data->hwmon_dev); |
827 | smsc47m1_remove_files(&pdev->dev); | 809 | smsc47m1_remove_files(&pdev->dev); |
828 | 810 | ||
829 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); | ||
830 | smsc47m1_handle_resources(res->start, data->type, RELEASE, &pdev->dev); | ||
831 | platform_set_drvdata(pdev, NULL); | ||
832 | kfree(data); | ||
833 | |||
834 | return 0; | 811 | return 0; |
835 | } | 812 | } |
836 | 813 | ||