hwmon: (w83781d) Convert to use devm_ functions
Guenter Roeck
maintainerPATCH 83/95 hwmon: (w83781d) Convert to use devm_ functions
Convert to use devm_ functions to reduce code size and simplify the code.
--- drivers/hwmon/w83781d.c | 46 ++++++++++++++++------------------------------ 1 file changed, 16 insertions(+), 30 deletions(-)
drivers/hwmon/w83781d.c +16 -30
@@ -1213,11 +1213,9 @@ w83781d_probe(struct i2c_client *client, const struct i2c_device_id *id)struct w83781d_data *data;int err; - data =kzalloc (sizeof (struct w83781d_data ),GFP_KERNEL ); -if (!data) { - err = -ENOMEM ; - goto ERROR1; - } + data =devm_kzalloc (dev,sizeof (struct w83781d_data ),GFP_KERNEL ); +if (!data) +return -ENOMEM ;i2c_set_clientdata (client, data);mutex_init (&data->lock);
@@ -1229,7 +1227,7 @@ w83781d_probe(struct i2c_client *client, const struct i2c_device_id *id)/* attach secondary i2c lm75-like clients */ err =w83781d_detect_subclients (client);if (err) - goto ERROR3; +return err;/* Initialize the chip */ w83781d_init_device (dev);
@@ -1237,25 +1235,22 @@ w83781d_probe(struct i2c_client *client, const struct i2c_device_id *id)/* Register sysfs hooks */ err =w83781d_create_files (dev, data->type,0 );if (err) - goto ERROR4; + goto remove_files; data->hwmon_dev =hwmon_device_register (dev);if (IS_ERR (data->hwmon_dev)) { err =PTR_ERR (data->hwmon_dev); - goto ERROR4; + goto remove_files; }return 0 ; -ERROR4: +remove_files:w83781d_remove_files (dev);if (data->lm75[0 ])i2c_unregister_device (data->lm75[0 ]);if (data->lm75[1 ])i2c_unregister_device (data->lm75[1 ]); -ERROR3: -kfree (data); -ERROR1:return err; }
@@ -1273,8 +1268,6 @@ w83781d_remove(struct i2c_client *client)if (data->lm75[1 ])i2c_unregister_device (data->lm75[1 ]); -kfree (data); -return 0 ; }
@@ -1780,17 +1773,16 @@ w83781d_isa_probe(struct platform_device *pdev)/* Reserve the ISA region */ res =platform_get_resource (pdev,IORESOURCE_IO ,0 ); -if (!request_region (res->start +W83781D_ADDR_REG_OFFSET ,2 , -"w83781d" )) { - err = -EBUSY ; - goto exit; - } +if (!devm_request_region (&pdev->dev, + res->start +W83781D_ADDR_REG_OFFSET ,2 , +"w83781d" )) +return -EBUSY ; + + data =devm_kzalloc (&pdev->dev,sizeof (struct w83781d_data ), +GFP_KERNEL ); +if (!data) +return -ENOMEM ; - data =kzalloc (sizeof (struct w83781d_data ),GFP_KERNEL ); -if (!data) { - err = -ENOMEM ; - goto exit_release_region; - }mutex_init (&data->lock); data->isa_addr = res->start;platform_set_drvdata (pdev, data);
@@ -1829,10 +1821,6 @@ w83781d_isa_probe(struct platform_device *pdev) exit_remove_files:w83781d_remove_files (&pdev->dev);device_remove_file (&pdev->dev, &dev_attr_name); -kfree (data); - exit_release_region: -release_region (res->start +W83781D_ADDR_REG_OFFSET ,2 ); - exit:return err; }
@@ -1844,8 +1832,6 @@ w83781d_isa_remove(struct platform_device *pdev)hwmon_device_unregister (data->hwmon_dev);w83781d_remove_files (&pdev->dev);device_remove_file (&pdev->dev, &dev_attr_name); -release_region (data->isa_addr +W83781D_ADDR_REG_OFFSET ,2 ); -kfree (data);return 0 ; }
Signature · 7 lines
1.7.9.7 _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Quoted 20 lines · Guenter Roeck
Convert to use
devm_functions to reduce code size and simplify the code.Signed-off-by Guenter Roeck <[email protected]>--- drivers/hwmon/w83781d.c | 46 ++++++++++++++++------------------------------ 1 file changed, 16 insertions(+), 30 deletions(-)drivers/hwmon/w83781d.c +1
-1@@ -1237,25 +1235,22 @@ w83781d_probe(struct i2c_client *client, const struct i2c_device_id *id)/* Register sysfs hooks */ err =w83781d_create_files (dev, data->type,0 );if (err) - goto ERROR4; + goto remove_files; data->hwmon_dev =hwmon_device_register (dev);
drivers/hwmon/w83781d.c w83781d_probe(struct i2c_client *client, const struct i2c_device_id *id) · line 1248
Quoted 10 lines
drivers/hwmon/w83781d.c +2
-2if (IS_ERR (data->hwmon_dev)) { err =PTR_ERR (data->hwmon_dev); - goto ERROR4; + goto remove_files; }return 0 ; -ERROR4: +remove_files:
For consistency with the isa code, you could name this label "exit_remove_files", and add a leading space.
Signature · 6 lines
Jean Delvare _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Guenter Roeck
maintainerQuoted 27 lines · Jean Delvare
Quoted 26 lines · Guenter Roeck
Convert to use
devm_functions to reduce code size and simplify the code.Signed-off-by Guenter Roeck <[email protected]>--- drivers/hwmon/w83781d.c | 46 ++++++++++++++++------------------------------ 1 file changed, 16 insertions(+), 30 deletions(-)drivers/hwmon/w83781d.c +2
-2@@ -1237,25 +1235,22 @@ w83781d_probe(struct i2c_client *client, const struct i2c_device_id *id)/* Register sysfs hooks */ err =w83781d_create_files (dev, data->type,0 );if (err) - goto ERROR4; + goto remove_files; data->hwmon_dev =hwmon_device_register (dev);if (IS_ERR (data->hwmon_dev)) { err =PTR_ERR (data->hwmon_dev); - goto ERROR4; + goto remove_files; }
Quoted 8 lines
drivers/hwmon/w83781d.c w83781d_probe(struct i2c_client *client, const struct i2c_device_id *id) · line 1248
Quoted 4 lines
drivers/hwmon/w83781d.c +1
-1return 0 ; -ERROR4: +remove_files:For consistency with the isa code, you could name this label "
exit_remove_files", and add a leading space.
Done.
Quoted 2 lines
Acked-by Jean Delvare <[email protected]>
Thanks,
Guenter
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors