aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAxel Lin <axel.lin@ingics.com>2014-07-07 21:27:38 -0400
committerGuenter Roeck <linux@roeck-us.net>2014-09-22 14:14:52 -0400
commit9b993e36611bd8029b81637ad53a262fa7882af1 (patch)
tree3568db610b43f5b3634ebcf348d77fe891b903e4
parent93c090b36ae977bc719f7ea2fcbf4a2e8e92e439 (diff)
hwmon: (smsc47b397) Convert to devm_hwmon_device_register_with_groups
Use ATTRIBUTE_GROUPS macro and devm_hwmon_device_register_with_groups() to simplify the code a bit. Signed-off-by: Axel Lin <axel.lin@ingics.com> Tested-by: Jean Delvare <jdelvare@suse.de> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
-rw-r--r--drivers/hwmon/smsc47b397.c51
1 files changed, 7 insertions, 44 deletions
diff --git a/drivers/hwmon/smsc47b397.c b/drivers/hwmon/smsc47b397.c
index bd89e87bd6ae..221f0931bf1c 100644
--- a/drivers/hwmon/smsc47b397.c
+++ b/drivers/hwmon/smsc47b397.c
@@ -100,8 +100,6 @@ static u8 smsc47b397_reg_temp[] = {0x25, 0x26, 0x27, 0x80};
100 100
101struct smsc47b397_data { 101struct smsc47b397_data {
102 unsigned short addr; 102 unsigned short addr;
103 const char *name;
104 struct device *hwmon_dev;
105 struct mutex lock; 103 struct mutex lock;
106 104
107 struct mutex update_lock; 105 struct mutex update_lock;
@@ -202,15 +200,7 @@ static SENSOR_DEVICE_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1);
202static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2); 200static SENSOR_DEVICE_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2);
203static SENSOR_DEVICE_ATTR(fan4_input, S_IRUGO, show_fan, NULL, 3); 201static SENSOR_DEVICE_ATTR(fan4_input, S_IRUGO, show_fan, NULL, 3);
204 202
205static ssize_t show_name(struct device *dev, struct device_attribute 203static struct attribute *smsc47b397_attrs[] = {
206 *devattr, char *buf)
207{
208 struct smsc47b397_data *data = dev_get_drvdata(dev);
209 return sprintf(buf, "%s\n", data->name);
210}
211static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
212
213static struct attribute *smsc47b397_attributes[] = {
214 &sensor_dev_attr_temp1_input.dev_attr.attr, 204 &sensor_dev_attr_temp1_input.dev_attr.attr,
215 &sensor_dev_attr_temp2_input.dev_attr.attr, 205 &sensor_dev_attr_temp2_input.dev_attr.attr,
216 &sensor_dev_attr_temp3_input.dev_attr.attr, 206 &sensor_dev_attr_temp3_input.dev_attr.attr,
@@ -220,23 +210,10 @@ static struct attribute *smsc47b397_attributes[] = {
220 &sensor_dev_attr_fan3_input.dev_attr.attr, 210 &sensor_dev_attr_fan3_input.dev_attr.attr,
221 &sensor_dev_attr_fan4_input.dev_attr.attr, 211 &sensor_dev_attr_fan4_input.dev_attr.attr,
222 212
223 &dev_attr_name.attr,
224 NULL 213 NULL
225}; 214};
226 215
227static const struct attribute_group smsc47b397_group = { 216ATTRIBUTE_GROUPS(smsc47b397);
228 .attrs = smsc47b397_attributes,
229};
230
231static int smsc47b397_remove(struct platform_device *pdev)
232{
233 struct smsc47b397_data *data = platform_get_drvdata(pdev);
234
235 hwmon_device_unregister(data->hwmon_dev);
236 sysfs_remove_group(&pdev->dev.kobj, &smsc47b397_group);
237
238 return 0;
239}
240 217
241static int smsc47b397_probe(struct platform_device *pdev); 218static int smsc47b397_probe(struct platform_device *pdev);
242 219
@@ -246,15 +223,14 @@ static struct platform_driver smsc47b397_driver = {
246 .name = DRVNAME, 223 .name = DRVNAME,
247 }, 224 },
248 .probe = smsc47b397_probe, 225 .probe = smsc47b397_probe,
249 .remove = smsc47b397_remove,
250}; 226};
251 227
252static int smsc47b397_probe(struct platform_device *pdev) 228static int smsc47b397_probe(struct platform_device *pdev)
253{ 229{
254 struct device *dev = &pdev->dev; 230 struct device *dev = &pdev->dev;
255 struct smsc47b397_data *data; 231 struct smsc47b397_data *data;
232 struct device *hwmon_dev;
256 struct resource *res; 233 struct resource *res;
257 int err = 0;
258 234
259 res = platform_get_resource(pdev, IORESOURCE_IO, 0); 235 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
260 if (!devm_request_region(dev, res->start, SMSC_EXTENT, 236 if (!devm_request_region(dev, res->start, SMSC_EXTENT,
@@ -270,26 +246,13 @@ static int smsc47b397_probe(struct platform_device *pdev)
270 return -ENOMEM; 246 return -ENOMEM;
271 247
272 data->addr = res->start; 248 data->addr = res->start;
273 data->name = "smsc47b397";
274 mutex_init(&data->lock); 249 mutex_init(&data->lock);
275 mutex_init(&data->update_lock); 250 mutex_init(&data->update_lock);
276 platform_set_drvdata(pdev, data);
277
278 err = sysfs_create_group(&dev->kobj, &smsc47b397_group);
279 if (err)
280 return err;
281 251
282 data->hwmon_dev = hwmon_device_register(dev); 252 hwmon_dev = devm_hwmon_device_register_with_groups(dev, "smsc47b397",
283 if (IS_ERR(data->hwmon_dev)) { 253 data,
284 err = PTR_ERR(data->hwmon_dev); 254 smsc47b397_groups);
285 goto error_remove; 255 return PTR_ERR_OR_ZERO(hwmon_dev);
286 }
287
288 return 0;
289
290error_remove:
291 sysfs_remove_group(&dev->kobj, &smsc47b397_group);
292 return err;
293} 256}
294 257
295static int __init smsc47b397_device_add(unsigned short address) 258static int __init smsc47b397_device_add(unsigned short address)