hwmon: (w83l785ts) Convert to use devm_ functions
Guenter Roeck
maintainerPATCH 86/95 hwmon: (w83l785ts) Convert to use devm_ functions
Convert to use devm_ functions to reduce code size and simplify the code.
Also, in probe function, rename new_client variable to client, and introduce local variable dev to point to client->dev, to simplify the code further and improve readability.
--- drivers/hwmon/w83l785ts.c | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-)
drivers/hwmon/w83l785ts.c +11 -19
@@ -176,19 +176,18 @@ static int w83l785ts_detect(struct i2c_client *client,return 0 ; } -static int w83l785ts_probe (struct i2c_client *new_client, +static int w83l785ts_probe (struct i2c_client *client,const struct i2c_device_id *id) {struct w83l785ts_data *data; +struct device *dev = &client->dev;int err =0 ; - data =kzalloc (sizeof (struct w83l785ts_data ),GFP_KERNEL ); -if (!data) { - err = -ENOMEM ; - goto exit; - } + data =devm_kzalloc (dev,sizeof (struct w83l785ts_data ),GFP_KERNEL ); +if (!data) +return -ENOMEM ; -i2c_set_clientdata (new_client, data); +i2c_set_clientdata (client, data); data->valid =0 ;mutex_init (&data->update_lock);
@@ -200,18 +199,16 @@ static int w83l785ts_probe(struct i2c_client *new_client,* Nothing yet, assume it is already started. */ - err =device_create_file (&new_client->dev, - &sensor_dev_attr_temp1_input.dev_attr); + err =device_create_file (dev, &sensor_dev_attr_temp1_input.dev_attr);if (err) goto exit_remove; - err =device_create_file (&new_client->dev, - &sensor_dev_attr_temp1_max.dev_attr); + err =device_create_file (dev, &sensor_dev_attr_temp1_max.dev_attr);if (err) goto exit_remove;/* Register sysfs hooks */ - data->hwmon_dev =hwmon_device_register (&new_client->dev); + data->hwmon_dev =hwmon_device_register (dev);if (IS_ERR (data->hwmon_dev)) { err =PTR_ERR (data->hwmon_dev); goto exit_remove;
@@ -220,12 +217,8 @@ static int w83l785ts_probe(struct i2c_client *new_client,return 0 ; exit_remove: -device_remove_file (&new_client->dev, - &sensor_dev_attr_temp1_input.dev_attr); -device_remove_file (&new_client->dev, - &sensor_dev_attr_temp1_max.dev_attr); -kfree (data); -exit: +device_remove_file (dev, &sensor_dev_attr_temp1_input.dev_attr); +device_remove_file (dev, &sensor_dev_attr_temp1_max.dev_attr);return err; }
@@ -239,7 +232,6 @@ static int w83l785ts_remove(struct i2c_client *client)device_remove_file (&client->dev, &sensor_dev_attr_temp1_max.dev_attr); -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
Hi Guenter,
Quoted 5 lines · Guenter Roeck
Convert to use
devm_functions to reduce code size and simplify the code.Also, in probe function, rename
new_clientvariable to client, and introduce local variable dev to point toclient->dev, to simplify the code further and improve readability.
Best done as two separate patches...
Quoted 10 lines
Signed-off-by Guenter Roeck <[email protected]>--- drivers/hwmon/w83l785ts.c | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-)drivers/hwmon/w83l785ts.c +0
-0
drivers/hwmon/w83l785ts.c static int w83l785ts_detect(struct i2c_client *client, · line 184
Quoted 10 lines
drivers/hwmon/w83l785ts.c +2
-1@@ -176,19 +176,18 @@ static int w83l785ts_detect(struct i2c_client *client,return 0 ; } -static int w83l785ts_probe (struct i2c_client *new_client, +static int w83l785ts_probe (struct i2c_client *client,const struct i2c_device_id *id) {struct w83l785ts_data *data; +struct device *dev = &client->dev;int err =0 ;
Not related to your changes directly, but this initialization is not needed.
drivers/hwmon/w83l785ts.c static int w83l785ts_probe(struct i2c_client *new_client, · line 204
Quoted 10 lines
drivers/hwmon/w83l785ts.c +1
-2@@ -200,18 +199,16 @@ static int w83l785ts_probe(struct i2c_client *new_client,* Nothing yet, assume it is already started. */ - err =device_create_file (&new_client->dev, - &sensor_dev_attr_temp1_input.dev_attr); + err =device_create_file (dev, &sensor_dev_attr_temp1_input.dev_attr);if (err) goto exit_remove;
You might as well turn this into a straight return, as there is nothing to remove at this point.
Signature · 6 lines
Jean Delvare _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Guenter Roeck
maintainerQuoted 11 lines · Jean Delvare
Hi Guenter,
Quoted 5 lines · Guenter Roeck
Convert to use
devm_functions to reduce code size and simplify the code.Also, in probe function, rename
new_clientvariable to client, and introduce local variable dev to point toclient->dev, to simplify the code further and improve readability.Best done as two separate patches...
Separated ...
Quoted 13 lines
Quoted 13 lines
Signed-off-by Guenter Roeck <[email protected]>--- drivers/hwmon/w83l785ts.c | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-)drivers/hwmon/w83l785ts.c +0
-0@@ -176,19 +176,18 @@ static int w83l785ts_detect(struct i2c_client *client,return 0 ; }
Quoted 11 lines
drivers/hwmon/w83l785ts.c static int w83l785ts_detect(struct i2c_client *client, · line 184
Quoted 7 lines
drivers/hwmon/w83l785ts.c +2
-1-static int w83l785ts_probe (struct i2c_client *new_client, +static int w83l785ts_probe (struct i2c_client *client,const struct i2c_device_id *id) {struct w83l785ts_data *data; +struct device *dev = &client->dev;int err =0 ;Not related to your changes directly, but this initialization is not needed.
done
Quoted 5 lines
Quoted 5 lines
drivers/hwmon/w83l785ts.c +0
-0@@ -200,18 +199,16 @@ static int w83l785ts_probe(struct i2c_client *new_client,* Nothing yet, assume it is already started. */
Quoted 9 lines
drivers/hwmon/w83l785ts.c static int w83l785ts_probe(struct i2c_client *new_client, · line 204
Quoted 5 lines
drivers/hwmon/w83l785ts.c +1
-2- err =device_create_file (&new_client->dev, - &sensor_dev_attr_temp1_input.dev_attr); + err =device_create_file (dev, &sensor_dev_attr_temp1_input.dev_attr);if (err) goto exit_remove;You might as well turn this into a straight return, as there is nothing to remove at this point.
and 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