power: supply: cw2015: Use device managed API to simplify the code
Subsystems (2)
PATCH 1/1 power: supply: cw2015: Use device managed API to simplify the code
Use devm_delayed_work_autocancel() instead of the INIT_DELAYED_WORK() to remove the cw_bat_remove() function.
And power_supply_put_battery_info() can also be removed because the power_supply_get_battery_info() uses device managed memory allocation.
Signed-off-by Zheyu Ma <[email protected]>
--- drivers/power/supply/cw2015_battery.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-)
drivers/power/supply/cw2015_battery.c +3 -11
@@ -21,6 +21,7 @@#include <linux/regmap.h> #include <linux/time.h> #include <linux/workqueue.h> +#include <linux/devm-helpers.h> #define CW2015_SIZE_BATINFO 64
@@ -698,7 +699,8 @@ static int cw_bat_probe(struct i2c_client *client) } cw_bat->battery_workqueue =create_singlethread_workqueue ("rk_battery" ); -INIT_DELAYED_WORK (&cw_bat->battery_delay_work, cw_bat_work); +devm_delayed_work_autocancel (&client->dev, + &cw_bat->battery_delay_work, cw_bat_work);queue_delayed_work (cw_bat->battery_workqueue, &cw_bat->battery_delay_work,msecs_to_jiffies (10 ));return 0 ;
@@ -725,15 +727,6 @@ static int __maybe_unused cw_bat_resume(struct device *dev) static SIMPLE_DEV_PM_OPS(cw_bat_pm_ops, cw_bat_suspend, cw_bat_resume); -static int cw_bat_remove (struct i2c_client *client) -{ -struct cw_battery *cw_bat =i2c_get_clientdata (client); - -cancel_delayed_work_sync (&cw_bat->battery_delay_work); -power_supply_put_battery_info (cw_bat->rk_bat, cw_bat->battery); -return 0 ; -} -static const struct i2c_device_id cw_bat_id_table[] = { {"cw2015" ,0 }, { }
@@ -752,7 +745,6 @@ static struct i2c_driver cw_bat_driver = { .pm = &cw_bat_pm_ops, }, .probe_new = cw_bat_probe, - .remove = cw_bat_remove, .id_table = cw_bat_id_table, };
Signature · 1 line
2.25.1
Hi,
Quoted 8 lines · Zheyu Ma
Use
devm_delayed_work_autocancel()instead of theINIT_DELAYED_WORK()to remove thecw_bat_remove()function.And
power_supply_put_battery_info()can also be removed because thepower_supply_get_battery_info()uses device managed memory allocation.Signed-off-by Zheyu Ma <[email protected]>---
Thanks, queued.
-- Sebastian
Quoted 52 lines
drivers/power/supply/cw2015_battery.c | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-)drivers/power/supply/cw2015_battery.c +3
-11@@ -21,6 +21,7 @@#include <linux/regmap.h> #include <linux/time.h> #include <linux/workqueue.h> +#include <linux/devm-helpers.h> #define CW2015_SIZE_BATINFO 64@@ -698,7 +699,8 @@ static int cw_bat_probe(struct i2c_client *client) } cw_bat->battery_workqueue =create_singlethread_workqueue ("rk_battery" ); -INIT_DELAYED_WORK (&cw_bat->battery_delay_work, cw_bat_work); +devm_delayed_work_autocancel (&client->dev, + &cw_bat->battery_delay_work, cw_bat_work);queue_delayed_work (cw_bat->battery_workqueue, &cw_bat->battery_delay_work,msecs_to_jiffies (10 ));return 0 ;@@ -725,15 +727,6 @@ static int __maybe_unused cw_bat_resume(struct device *dev) static SIMPLE_DEV_PM_OPS(cw_bat_pm_ops, cw_bat_suspend, cw_bat_resume); -static int cw_bat_remove (struct i2c_client *client) -{ -struct cw_battery *cw_bat =i2c_get_clientdata (client); - -cancel_delayed_work_sync (&cw_bat->battery_delay_work); -power_supply_put_battery_info (cw_bat->rk_bat, cw_bat->battery); -return 0 ; -} -static const struct i2c_device_id cw_bat_id_table[] = { {"cw2015" ,0 }, { }@@ -752,7 +745,6 @@ static struct i2c_driver cw_bat_driver = { .pm = &cw_bat_pm_ops, }, .probe_new = cw_bat_probe, - .remove = cw_bat_remove, .id_table = cw_bat_id_table, };Signature · 1 line
2.25.1