Commit 47591baa authored by Hao Peng's avatar Hao Peng Committed by Guenter Roeck

hwmon: (g762) handle cleanup with devm_add_action

Simplify code and use devm_add_action() to handle cleanup.
Signed-off-by: default avatarPeng Hao <peng.hao2@zte.com.cn>
[groeck: Dropped unnecessary dummy function and NULL check]
Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
parent b20edea9
...@@ -128,7 +128,6 @@ enum g762_regs { ...@@ -128,7 +128,6 @@ enum g762_regs {
G762_REG_FAN_CMD2_GEAR_MODE_1)) >> 2)) G762_REG_FAN_CMD2_GEAR_MODE_1)) >> 2))
struct g762_data { struct g762_data {
struct device *hwmon_dev;
struct i2c_client *client; struct i2c_client *client;
struct clk *clk; struct clk *clk;
...@@ -594,6 +593,14 @@ MODULE_DEVICE_TABLE(of, g762_dt_match); ...@@ -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 * 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. * 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) static int g762_of_clock_enable(struct i2c_client *client)
{ {
struct g762_data *data; struct g762_data *data;
...@@ -626,6 +633,7 @@ static int g762_of_clock_enable(struct i2c_client *client) ...@@ -626,6 +633,7 @@ static int g762_of_clock_enable(struct i2c_client *client)
data = i2c_get_clientdata(client); data = i2c_get_clientdata(client);
data->clk = clk; data->clk = clk;
devm_add_action(&client->dev, g762_of_clock_disable, data);
return 0; return 0;
clk_unprep: clk_unprep:
...@@ -637,17 +645,6 @@ static int g762_of_clock_enable(struct i2c_client *client) ...@@ -637,17 +645,6 @@ static int g762_of_clock_enable(struct i2c_client *client)
return ret; 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, static int g762_of_prop_import_one(struct i2c_client *client,
const char *pname, const char *pname,
int (*psetter)(struct device *dev, int (*psetter)(struct device *dev,
...@@ -698,8 +695,6 @@ static int g762_of_clock_enable(struct i2c_client *client) ...@@ -698,8 +695,6 @@ static int g762_of_clock_enable(struct i2c_client *client)
{ {
return 0; return 0;
} }
static void g762_of_clock_disable(struct i2c_client *client) { }
#endif #endif
/* /*
...@@ -1054,6 +1049,7 @@ static inline int g762_fan_init(struct device *dev) ...@@ -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) static int g762_probe(struct i2c_client *client, const struct i2c_device_id *id)
{ {
struct device *dev = &client->dev; struct device *dev = &client->dev;
struct device *hwmon_dev;
struct g762_data *data; struct g762_data *data;
int ret; int ret;
...@@ -1080,35 +1076,15 @@ static int g762_probe(struct i2c_client *client, const struct i2c_device_id *id) ...@@ -1080,35 +1076,15 @@ static int g762_probe(struct i2c_client *client, const struct i2c_device_id *id)
return ret; return ret;
ret = g762_of_prop_import(client); ret = g762_of_prop_import(client);
if (ret) if (ret)
goto clock_dis; return ret;
/* ... or platform_data */ /* ... or platform_data */
ret = g762_pdata_prop_import(client); ret = g762_pdata_prop_import(client);
if (ret) if (ret)
goto clock_dis;
data->hwmon_dev = 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; return ret;
}
static int g762_remove(struct i2c_client *client)
{
struct g762_data *data = i2c_get_clientdata(client);
hwmon_device_unregister(data->hwmon_dev); hwmon_dev = devm_hwmon_device_register_with_groups(dev, client->name,
g762_of_clock_disable(client); data, g762_groups);
return PTR_ERR_OR_ZERO(hwmon_dev);
return 0;
} }
static struct i2c_driver g762_driver = { static struct i2c_driver g762_driver = {
...@@ -1117,7 +1093,6 @@ 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), .of_match_table = of_match_ptr(g762_dt_match),
}, },
.probe = g762_probe, .probe = g762_probe,
.remove = g762_remove,
.id_table = g762_id, .id_table = g762_id,
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment