aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2012-06-02 14:20:20 -0400
committerGuenter Roeck <linux@roeck-us.net>2012-07-22 00:48:41 -0400
commit5e0c876920e6cc5cd074f1a5a8d4c30783f9baf9 (patch)
tree385a2da8db92095e7220056167ff901b5d8c4831
parent3fafb0ce92f13d14ba1c1340ac185e5c78fc7eae (diff)
hwmon: (pc87427) Convert to use devm_ functions
Convert to use devm_ functions to reduce code size and simplify the code. Cc: Jean Delvare <khali@linux-fr.org> Signed-off-by: Guenter Roeck <linux@roeck-us.net> Acked-by: Jean Delvare <khali@linux-fr.org>
-rw-r--r--drivers/hwmon/pc87427.c51
1 files changed, 11 insertions, 40 deletions
diff --git a/drivers/hwmon/pc87427.c b/drivers/hwmon/pc87427.c
index 37059a3755e9..f185b1fa53e5 100644
--- a/drivers/hwmon/pc87427.c
+++ b/drivers/hwmon/pc87427.c
@@ -956,44 +956,28 @@ static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
956 * Device detection, attach and detach 956 * Device detection, attach and detach
957 */ 957 */
958 958
959static void pc87427_release_regions(struct platform_device *pdev, int count)
960{
961 struct resource *res;
962 int i;
963
964 for (i = 0; i < count; i++) {
965 res = platform_get_resource(pdev, IORESOURCE_IO, i);
966 release_region(res->start, resource_size(res));
967 }
968}
969
970static int __devinit pc87427_request_regions(struct platform_device *pdev, 959static int __devinit pc87427_request_regions(struct platform_device *pdev,
971 int count) 960 int count)
972{ 961{
973 struct resource *res; 962 struct resource *res;
974 int i, err = 0; 963 int i;
975 964
976 for (i = 0; i < count; i++) { 965 for (i = 0; i < count; i++) {
977 res = platform_get_resource(pdev, IORESOURCE_IO, i); 966 res = platform_get_resource(pdev, IORESOURCE_IO, i);
978 if (!res) { 967 if (!res) {
979 err = -ENOENT;
980 dev_err(&pdev->dev, "Missing resource #%d\n", i); 968 dev_err(&pdev->dev, "Missing resource #%d\n", i);
981 break; 969 return -ENOENT;
982 } 970 }
983 if (!request_region(res->start, resource_size(res), DRVNAME)) { 971 if (!devm_request_region(&pdev->dev, res->start,
984 err = -EBUSY; 972 resource_size(res), DRVNAME)) {
985 dev_err(&pdev->dev, 973 dev_err(&pdev->dev,
986 "Failed to request region 0x%lx-0x%lx\n", 974 "Failed to request region 0x%lx-0x%lx\n",
987 (unsigned long)res->start, 975 (unsigned long)res->start,
988 (unsigned long)res->end); 976 (unsigned long)res->end);
989 break; 977 return -EBUSY;
990 } 978 }
991 } 979 }
992 980 return 0;
993 if (err && i)
994 pc87427_release_regions(pdev, i);
995
996 return err;
997} 981}
998 982
999static void __devinit pc87427_init_device(struct device *dev) 983static void __devinit pc87427_init_device(struct device *dev)
@@ -1094,11 +1078,11 @@ static int __devinit pc87427_probe(struct platform_device *pdev)
1094 struct pc87427_data *data; 1078 struct pc87427_data *data;
1095 int i, err, res_count; 1079 int i, err, res_count;
1096 1080
1097 data = kzalloc(sizeof(struct pc87427_data), GFP_KERNEL); 1081 data = devm_kzalloc(&pdev->dev, sizeof(struct pc87427_data),
1082 GFP_KERNEL);
1098 if (!data) { 1083 if (!data) {
1099 err = -ENOMEM;
1100 pr_err("Out of memory\n"); 1084 pr_err("Out of memory\n");
1101 goto exit; 1085 return -ENOMEM;
1102 } 1086 }
1103 1087
1104 data->address[0] = sio_data->address[0]; 1088 data->address[0] = sio_data->address[0];
@@ -1107,7 +1091,7 @@ static int __devinit pc87427_probe(struct platform_device *pdev)
1107 1091
1108 err = pc87427_request_regions(pdev, res_count); 1092 err = pc87427_request_regions(pdev, res_count);
1109 if (err) 1093 if (err)
1110 goto exit_kfree; 1094 return err;
1111 1095
1112 mutex_init(&data->lock); 1096 mutex_init(&data->lock);
1113 data->name = "pc87427"; 1097 data->name = "pc87427";
@@ -1117,7 +1101,7 @@ static int __devinit pc87427_probe(struct platform_device *pdev)
1117 /* Register sysfs hooks */ 1101 /* Register sysfs hooks */
1118 err = device_create_file(&pdev->dev, &dev_attr_name); 1102 err = device_create_file(&pdev->dev, &dev_attr_name);
1119 if (err) 1103 if (err)
1120 goto exit_release_region; 1104 return err;
1121 for (i = 0; i < 8; i++) { 1105 for (i = 0; i < 8; i++) {
1122 if (!(data->fan_enabled & (1 << i))) 1106 if (!(data->fan_enabled & (1 << i)))
1123 continue; 1107 continue;
@@ -1154,28 +1138,15 @@ static int __devinit pc87427_probe(struct platform_device *pdev)
1154 1138
1155exit_remove_files: 1139exit_remove_files:
1156 pc87427_remove_files(&pdev->dev); 1140 pc87427_remove_files(&pdev->dev);
1157exit_release_region:
1158 pc87427_release_regions(pdev, res_count);
1159exit_kfree:
1160 platform_set_drvdata(pdev, NULL);
1161 kfree(data);
1162exit:
1163 return err; 1141 return err;
1164} 1142}
1165 1143
1166static int __devexit pc87427_remove(struct platform_device *pdev) 1144static int __devexit pc87427_remove(struct platform_device *pdev)
1167{ 1145{
1168 struct pc87427_data *data = platform_get_drvdata(pdev); 1146 struct pc87427_data *data = platform_get_drvdata(pdev);
1169 int res_count;
1170
1171 res_count = (data->address[0] != 0) + (data->address[1] != 0);
1172 1147
1173 hwmon_device_unregister(data->hwmon_dev); 1148 hwmon_device_unregister(data->hwmon_dev);
1174 pc87427_remove_files(&pdev->dev); 1149 pc87427_remove_files(&pdev->dev);
1175 platform_set_drvdata(pdev, NULL);
1176 kfree(data);
1177
1178 pc87427_release_regions(pdev, res_count);
1179 1150
1180 return 0; 1151 return 0;
1181} 1152}