aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/lm78.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/lm78.c')
-rw-r--r--drivers/hwmon/lm78.c36
1 files changed, 11 insertions, 25 deletions
diff --git a/drivers/hwmon/lm78.c b/drivers/hwmon/lm78.c
index f6bc414e1e91..c6ffafe600ad 100644
--- a/drivers/hwmon/lm78.c
+++ b/drivers/hwmon/lm78.c
@@ -660,7 +660,7 @@ static int lm78_i2c_probe(struct i2c_client *client,
660 struct lm78_data *data; 660 struct lm78_data *data;
661 int err; 661 int err;
662 662
663 data = kzalloc(sizeof(struct lm78_data), GFP_KERNEL); 663 data = devm_kzalloc(&client->dev, sizeof(struct lm78_data), GFP_KERNEL);
664 if (!data) 664 if (!data)
665 return -ENOMEM; 665 return -ENOMEM;
666 666
@@ -674,20 +674,18 @@ static int lm78_i2c_probe(struct i2c_client *client,
674 /* Register sysfs hooks */ 674 /* Register sysfs hooks */
675 err = sysfs_create_group(&client->dev.kobj, &lm78_group); 675 err = sysfs_create_group(&client->dev.kobj, &lm78_group);
676 if (err) 676 if (err)
677 goto ERROR3; 677 return err;
678 678
679 data->hwmon_dev = hwmon_device_register(&client->dev); 679 data->hwmon_dev = hwmon_device_register(&client->dev);
680 if (IS_ERR(data->hwmon_dev)) { 680 if (IS_ERR(data->hwmon_dev)) {
681 err = PTR_ERR(data->hwmon_dev); 681 err = PTR_ERR(data->hwmon_dev);
682 goto ERROR4; 682 goto error;
683 } 683 }
684 684
685 return 0; 685 return 0;
686 686
687ERROR4: 687error:
688 sysfs_remove_group(&client->dev.kobj, &lm78_group); 688 sysfs_remove_group(&client->dev.kobj, &lm78_group);
689ERROR3:
690 kfree(data);
691 return err; 689 return err;
692} 690}
693 691
@@ -697,7 +695,6 @@ static int lm78_i2c_remove(struct i2c_client *client)
697 695
698 hwmon_device_unregister(data->hwmon_dev); 696 hwmon_device_unregister(data->hwmon_dev);
699 sysfs_remove_group(&client->dev.kobj, &lm78_group); 697 sysfs_remove_group(&client->dev.kobj, &lm78_group);
700 kfree(data);
701 698
702 return 0; 699 return 0;
703} 700}
@@ -844,16 +841,14 @@ static int __devinit lm78_isa_probe(struct platform_device *pdev)
844 841
845 /* Reserve the ISA region */ 842 /* Reserve the ISA region */
846 res = platform_get_resource(pdev, IORESOURCE_IO, 0); 843 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
847 if (!request_region(res->start + LM78_ADDR_REG_OFFSET, 2, "lm78")) { 844 if (!devm_request_region(&pdev->dev, res->start + LM78_ADDR_REG_OFFSET,
848 err = -EBUSY; 845 2, "lm78"))
849 goto exit; 846 return -EBUSY;
850 } 847
848 data = devm_kzalloc(&pdev->dev, sizeof(struct lm78_data), GFP_KERNEL);
849 if (!data)
850 return -ENOMEM;
851 851
852 data = kzalloc(sizeof(struct lm78_data), GFP_KERNEL);
853 if (!data) {
854 err = -ENOMEM;
855 goto exit_release_region;
856 }
857 mutex_init(&data->lock); 852 mutex_init(&data->lock);
858 data->isa_addr = res->start; 853 data->isa_addr = res->start;
859 platform_set_drvdata(pdev, data); 854 platform_set_drvdata(pdev, data);
@@ -888,25 +883,16 @@ static int __devinit lm78_isa_probe(struct platform_device *pdev)
888 exit_remove_files: 883 exit_remove_files:
889 sysfs_remove_group(&pdev->dev.kobj, &lm78_group); 884 sysfs_remove_group(&pdev->dev.kobj, &lm78_group);
890 device_remove_file(&pdev->dev, &dev_attr_name); 885 device_remove_file(&pdev->dev, &dev_attr_name);
891 kfree(data);
892 exit_release_region:
893 release_region(res->start + LM78_ADDR_REG_OFFSET, 2);
894 exit:
895 return err; 886 return err;
896} 887}
897 888
898static int __devexit lm78_isa_remove(struct platform_device *pdev) 889static int __devexit lm78_isa_remove(struct platform_device *pdev)
899{ 890{
900 struct lm78_data *data = platform_get_drvdata(pdev); 891 struct lm78_data *data = platform_get_drvdata(pdev);
901 struct resource *res;
902 892
903 hwmon_device_unregister(data->hwmon_dev); 893 hwmon_device_unregister(data->hwmon_dev);
904 sysfs_remove_group(&pdev->dev.kobj, &lm78_group); 894 sysfs_remove_group(&pdev->dev.kobj, &lm78_group);
905 device_remove_file(&pdev->dev, &dev_attr_name); 895 device_remove_file(&pdev->dev, &dev_attr_name);
906 kfree(data);
907
908 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
909 release_region(res->start + LM78_ADDR_REG_OFFSET, 2);
910 896
911 return 0; 897 return 0;
912} 898}