diff options
author | Hao Peng <peng.hao2@zte.com.cn> | 2018-03-01 17:48:30 +0300 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2018-03-11 06:00:14 +0300 |
commit | 47591baa713cb23db7ea012bc1710f58efc14abf (patch) | |
tree | 302c5d456f22e4ee2ad05969e4ee698ff5ba0611 /drivers/hwmon/g762.c | |
parent | b20edea9a666235c91175ab654e440345afdcdef (diff) | |
download | linux-47591baa713cb23db7ea012bc1710f58efc14abf.tar.xz |
hwmon: (g762) handle cleanup with devm_add_action
Simplify code and use devm_add_action() to handle cleanup.
Signed-off-by: Peng Hao <peng.hao2@zte.com.cn>
[groeck: Dropped unnecessary dummy function and NULL check]
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon/g762.c')
-rw-r--r-- | drivers/hwmon/g762.c | 53 |
1 files changed, 14 insertions, 39 deletions
diff --git a/drivers/hwmon/g762.c b/drivers/hwmon/g762.c index 6d1208b2b6d2..6c83c385a7ca 100644 --- a/drivers/hwmon/g762.c +++ b/drivers/hwmon/g762.c @@ -128,7 +128,6 @@ enum g762_regs { G762_REG_FAN_CMD2_GEAR_MODE_1)) >> 2)) struct g762_data { - struct device *hwmon_dev; struct i2c_client *client; struct clk *clk; @@ -594,6 +593,14 @@ MODULE_DEVICE_TABLE(of, g762_dt_match); * call to g762_of_clock_disable(). Note that a reference to clock is kept * in our private data structure to be used in this function. */ +static void g762_of_clock_disable(void *data) +{ + struct g762_data *g762 = data; + + clk_disable_unprepare(g762->clk); + clk_put(g762->clk); +} + static int g762_of_clock_enable(struct i2c_client *client) { struct g762_data *data; @@ -626,6 +633,7 @@ static int g762_of_clock_enable(struct i2c_client *client) data = i2c_get_clientdata(client); data->clk = clk; + devm_add_action(&client->dev, g762_of_clock_disable, data); return 0; clk_unprep: @@ -637,17 +645,6 @@ static int g762_of_clock_enable(struct i2c_client *client) return ret; } -static void g762_of_clock_disable(struct i2c_client *client) -{ - struct g762_data *data = i2c_get_clientdata(client); - - if (!data->clk) - return; - - clk_disable_unprepare(data->clk); - clk_put(data->clk); -} - static int g762_of_prop_import_one(struct i2c_client *client, const char *pname, int (*psetter)(struct device *dev, @@ -698,8 +695,6 @@ static int g762_of_clock_enable(struct i2c_client *client) { return 0; } - -static void g762_of_clock_disable(struct i2c_client *client) { } #endif /* @@ -1054,6 +1049,7 @@ static inline int g762_fan_init(struct device *dev) static int g762_probe(struct i2c_client *client, const struct i2c_device_id *id) { struct device *dev = &client->dev; + struct device *hwmon_dev; struct g762_data *data; int ret; @@ -1080,35 +1076,15 @@ static int g762_probe(struct i2c_client *client, const struct i2c_device_id *id) return ret; ret = g762_of_prop_import(client); if (ret) - goto clock_dis; + return ret; /* ... or platform_data */ ret = g762_pdata_prop_import(client); if (ret) - goto clock_dis; + return ret; - data->hwmon_dev = hwmon_device_register_with_groups(dev, client->name, + hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name, data, g762_groups); - if (IS_ERR(data->hwmon_dev)) { - ret = PTR_ERR(data->hwmon_dev); - goto clock_dis; - } - - return 0; - - clock_dis: - g762_of_clock_disable(client); - - return ret; -} - -static int g762_remove(struct i2c_client *client) -{ - struct g762_data *data = i2c_get_clientdata(client); - - hwmon_device_unregister(data->hwmon_dev); - g762_of_clock_disable(client); - - return 0; + return PTR_ERR_OR_ZERO(hwmon_dev); } static struct i2c_driver g762_driver = { @@ -1117,7 +1093,6 @@ static struct i2c_driver g762_driver = { .of_match_table = of_match_ptr(g762_dt_match), }, .probe = g762_probe, - .remove = g762_remove, .id_table = g762_id, }; |