Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

power: supply: Clean-up few drivers by using managed work init

Few drivers implement remove call-back only for ensuring a delayed
work gets cancelled prior driver removal. Clean-up these by switching
to use devm_delayed_work_autocancel() instead.

This change is compile-tested only. All testing is appreciated.

Acked-by: Sebastian Reichel <sebastian.reichel@collabora.com>
Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
Link: https://lore.kernel.org/r/e5b1b0380cdd1aa066c9ac6d7a8b1a86ba1ddbbe.1616506559.git.matti.vaittinen@fi.rohmeurope.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Matti Vaittinen and committed by
Greg Kroah-Hartman
6d0c5de2 b82a7b01

+23 -46
+5 -10
drivers/power/supply/axp20x_usb_power.c
··· 8 8 9 9 #include <linux/bitops.h> 10 10 #include <linux/device.h> 11 + #include <linux/devm-helpers.h> 11 12 #include <linux/init.h> 12 13 #include <linux/interrupt.h> 13 14 #include <linux/kernel.h> ··· 647 646 } 648 647 } 649 648 649 + ret = devm_delayed_work_autocancel(&pdev->dev, &power->vbus_detect, 650 + axp20x_usb_power_poll_vbus); 651 + if (ret) 652 + return ret; 650 653 if (axp20x_usb_vbus_needs_polling(power)) 651 654 queue_delayed_work(system_power_efficient_wq, &power->vbus_detect, 0); 652 - 653 - return 0; 654 - } 655 - 656 - static int axp20x_usb_power_remove(struct platform_device *pdev) 657 - { 658 - struct axp20x_usb_power *power = platform_get_drvdata(pdev); 659 - 660 - cancel_delayed_work_sync(&power->vbus_detect); 661 655 662 656 return 0; 663 657 } ··· 676 680 677 681 static struct platform_driver axp20x_usb_power_driver = { 678 682 .probe = axp20x_usb_power_probe, 679 - .remove = axp20x_usb_power_remove, 680 683 .driver = { 681 684 .name = DRVNAME, 682 685 .of_match_table = axp20x_usb_power_match,
+6 -12
drivers/power/supply/bq24735-charger.c
··· 17 17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 18 */ 19 19 20 + #include <linux/devm-helpers.h> 20 21 #include <linux/err.h> 21 22 #include <linux/i2c.h> 22 23 #include <linux/init.h> ··· 474 473 if (!charger->poll_interval) 475 474 return 0; 476 475 477 - INIT_DELAYED_WORK(&charger->poll, bq24735_poll); 476 + ret = devm_delayed_work_autocancel(&client->dev, &charger->poll, 477 + bq24735_poll); 478 + if (ret) 479 + return ret; 480 + 478 481 schedule_delayed_work(&charger->poll, 479 482 msecs_to_jiffies(charger->poll_interval)); 480 483 } 481 - 482 - return 0; 483 - } 484 - 485 - static int bq24735_charger_remove(struct i2c_client *client) 486 - { 487 - struct bq24735 *charger = i2c_get_clientdata(client); 488 - 489 - if (charger->poll_interval) 490 - cancel_delayed_work_sync(&charger->poll); 491 484 492 485 return 0; 493 486 } ··· 504 509 .of_match_table = bq24735_match_ids, 505 510 }, 506 511 .probe = bq24735_charger_probe, 507 - .remove = bq24735_charger_remove, 508 512 .id_table = bq24735_charger_id, 509 513 }; 510 514
+7 -13
drivers/power/supply/ltc2941-battery-gauge.c
··· 8 8 * Author: Auryn Verwegen 9 9 * Author: Mike Looijmans 10 10 */ 11 + #include <linux/devm-helpers.h> 11 12 #include <linux/kernel.h> 12 13 #include <linux/module.h> 13 14 #include <linux/of_device.h> ··· 446 445 POWER_SUPPLY_PROP_CURRENT_NOW, 447 446 }; 448 447 449 - static int ltc294x_i2c_remove(struct i2c_client *client) 450 - { 451 - struct ltc294x_info *info = i2c_get_clientdata(client); 452 - 453 - cancel_delayed_work_sync(&info->work); 454 - power_supply_unregister(info->supply); 455 - return 0; 456 - } 457 - 458 448 static int ltc294x_i2c_probe(struct i2c_client *client, 459 449 const struct i2c_device_id *id) 460 450 { ··· 539 547 540 548 psy_cfg.drv_data = info; 541 549 542 - INIT_DELAYED_WORK(&info->work, ltc294x_work); 550 + ret = devm_delayed_work_autocancel(&client->dev, &info->work, 551 + ltc294x_work); 552 + if (ret) 553 + return ret; 543 554 544 555 ret = ltc294x_reset(info, prescaler_exp); 545 556 if (ret < 0) { ··· 550 555 return ret; 551 556 } 552 557 553 - info->supply = power_supply_register(&client->dev, &info->supply_desc, 554 - &psy_cfg); 558 + info->supply = devm_power_supply_register(&client->dev, 559 + &info->supply_desc, &psy_cfg); 555 560 if (IS_ERR(info->supply)) { 556 561 dev_err(&client->dev, "failed to register ltc2941\n"); 557 562 return PTR_ERR(info->supply); ··· 650 655 .pm = LTC294X_PM_OPS, 651 656 }, 652 657 .probe = ltc294x_i2c_probe, 653 - .remove = ltc294x_i2c_remove, 654 658 .shutdown = ltc294x_i2c_shutdown, 655 659 .id_table = ltc294x_i2c_id, 656 660 };
+5 -11
drivers/power/supply/sbs-battery.c
··· 7 7 8 8 #include <linux/bits.h> 9 9 #include <linux/delay.h> 10 + #include <linux/devm-helpers.h> 10 11 #include <linux/err.h> 11 12 #include <linux/gpio/consumer.h> 12 13 #include <linux/i2c.h> ··· 1166 1165 } 1167 1166 } 1168 1167 1169 - INIT_DELAYED_WORK(&chip->work, sbs_delayed_work); 1168 + rc = devm_delayed_work_autocancel(&client->dev, &chip->work, 1169 + sbs_delayed_work); 1170 + if (rc) 1171 + return rc; 1170 1172 1171 1173 chip->power_supply = devm_power_supply_register(&client->dev, sbs_desc, 1172 1174 &psy_cfg); ··· 1187 1183 1188 1184 exit_psupply: 1189 1185 return rc; 1190 - } 1191 - 1192 - static int sbs_remove(struct i2c_client *client) 1193 - { 1194 - struct sbs_info *chip = i2c_get_clientdata(client); 1195 - 1196 - cancel_delayed_work_sync(&chip->work); 1197 - 1198 - return 0; 1199 1186 } 1200 1187 1201 1188 #if defined CONFIG_PM_SLEEP ··· 1243 1248 1244 1249 static struct i2c_driver sbs_battery_driver = { 1245 1250 .probe_new = sbs_probe, 1246 - .remove = sbs_remove, 1247 1251 .alert = sbs_alert, 1248 1252 .id_table = sbs_id, 1249 1253 .driver = {