提交 805fd8c5 编写于 作者: G Guenter Roeck

hwmon: (dme1737) Convert to use devm_ functions

Convert to use devm_ functions to reduce code size and simplify the code.

Cc: Juerg Haefliger <juergh@gmail.com>
Signed-off-by: NGuenter Roeck <linux@roeck-us.net>
上级 64adf398
...@@ -2475,11 +2475,9 @@ static int dme1737_i2c_probe(struct i2c_client *client, ...@@ -2475,11 +2475,9 @@ static int dme1737_i2c_probe(struct i2c_client *client,
struct device *dev = &client->dev; struct device *dev = &client->dev;
int err; int err;
data = kzalloc(sizeof(struct dme1737_data), GFP_KERNEL); data = devm_kzalloc(dev, sizeof(struct dme1737_data), GFP_KERNEL);
if (!data) { if (!data)
err = -ENOMEM; return -ENOMEM;
goto exit;
}
i2c_set_clientdata(client, data); i2c_set_clientdata(client, data);
data->type = id->driver_data; data->type = id->driver_data;
...@@ -2491,14 +2489,14 @@ static int dme1737_i2c_probe(struct i2c_client *client, ...@@ -2491,14 +2489,14 @@ static int dme1737_i2c_probe(struct i2c_client *client,
err = dme1737_init_device(dev); err = dme1737_init_device(dev);
if (err) { if (err) {
dev_err(dev, "Failed to initialize device.\n"); dev_err(dev, "Failed to initialize device.\n");
goto exit_kfree; return err;
} }
/* Create sysfs files */ /* Create sysfs files */
err = dme1737_create_files(dev); err = dme1737_create_files(dev);
if (err) { if (err) {
dev_err(dev, "Failed to create sysfs files.\n"); dev_err(dev, "Failed to create sysfs files.\n");
goto exit_kfree; return err;
} }
/* Register device */ /* Register device */
...@@ -2513,9 +2511,6 @@ static int dme1737_i2c_probe(struct i2c_client *client, ...@@ -2513,9 +2511,6 @@ static int dme1737_i2c_probe(struct i2c_client *client,
exit_remove: exit_remove:
dme1737_remove_files(dev); dme1737_remove_files(dev);
exit_kfree:
kfree(data);
exit:
return err; return err;
} }
...@@ -2526,7 +2521,6 @@ static int dme1737_i2c_remove(struct i2c_client *client) ...@@ -2526,7 +2521,6 @@ static int dme1737_i2c_remove(struct i2c_client *client)
hwmon_device_unregister(data->hwmon_dev); hwmon_device_unregister(data->hwmon_dev);
dme1737_remove_files(&client->dev); dme1737_remove_files(&client->dev);
kfree(data);
return 0; return 0;
} }
...@@ -2645,19 +2639,16 @@ static int __devinit dme1737_isa_probe(struct platform_device *pdev) ...@@ -2645,19 +2639,16 @@ static int __devinit dme1737_isa_probe(struct platform_device *pdev)
int err; int err;
res = platform_get_resource(pdev, IORESOURCE_IO, 0); res = platform_get_resource(pdev, IORESOURCE_IO, 0);
if (!request_region(res->start, DME1737_EXTENT, "dme1737")) { if (!devm_request_region(dev, res->start, DME1737_EXTENT, "dme1737")) {
dev_err(dev, "Failed to request region 0x%04x-0x%04x.\n", dev_err(dev, "Failed to request region 0x%04x-0x%04x.\n",
(unsigned short)res->start, (unsigned short)res->start,
(unsigned short)res->start + DME1737_EXTENT - 1); (unsigned short)res->start + DME1737_EXTENT - 1);
err = -EBUSY; return -EBUSY;
goto exit;
} }
data = kzalloc(sizeof(struct dme1737_data), GFP_KERNEL); data = devm_kzalloc(dev, sizeof(struct dme1737_data), GFP_KERNEL);
if (!data) { if (!data)
err = -ENOMEM; return -ENOMEM;
goto exit_release_region;
}
data->addr = res->start; data->addr = res->start;
platform_set_drvdata(pdev, data); platform_set_drvdata(pdev, data);
...@@ -2683,8 +2674,7 @@ static int __devinit dme1737_isa_probe(struct platform_device *pdev) ...@@ -2683,8 +2674,7 @@ static int __devinit dme1737_isa_probe(struct platform_device *pdev)
(device == SCH5127_DEVICE)) { (device == SCH5127_DEVICE)) {
data->type = sch5127; data->type = sch5127;
} else { } else {
err = -ENODEV; return -ENODEV;
goto exit_kfree;
} }
} }
...@@ -2703,14 +2693,14 @@ static int __devinit dme1737_isa_probe(struct platform_device *pdev) ...@@ -2703,14 +2693,14 @@ static int __devinit dme1737_isa_probe(struct platform_device *pdev)
err = dme1737_init_device(dev); err = dme1737_init_device(dev);
if (err) { if (err) {
dev_err(dev, "Failed to initialize device.\n"); dev_err(dev, "Failed to initialize device.\n");
goto exit_kfree; return err;
} }
/* Create sysfs files */ /* Create sysfs files */
err = dme1737_create_files(dev); err = dme1737_create_files(dev);
if (err) { if (err) {
dev_err(dev, "Failed to create sysfs files.\n"); dev_err(dev, "Failed to create sysfs files.\n");
goto exit_kfree; return err;
} }
/* Register device */ /* Register device */
...@@ -2725,12 +2715,6 @@ static int __devinit dme1737_isa_probe(struct platform_device *pdev) ...@@ -2725,12 +2715,6 @@ static int __devinit dme1737_isa_probe(struct platform_device *pdev)
exit_remove_files: exit_remove_files:
dme1737_remove_files(dev); dme1737_remove_files(dev);
exit_kfree:
platform_set_drvdata(pdev, NULL);
kfree(data);
exit_release_region:
release_region(res->start, DME1737_EXTENT);
exit:
return err; return err;
} }
...@@ -2740,9 +2724,6 @@ static int __devexit dme1737_isa_remove(struct platform_device *pdev) ...@@ -2740,9 +2724,6 @@ static int __devexit dme1737_isa_remove(struct platform_device *pdev)
hwmon_device_unregister(data->hwmon_dev); hwmon_device_unregister(data->hwmon_dev);
dme1737_remove_files(&pdev->dev); dme1737_remove_files(&pdev->dev);
release_region(data->addr, DME1737_EXTENT);
platform_set_drvdata(pdev, NULL);
kfree(data);
return 0; return 0;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册