diff mbox series

power: supply: sbs-charger: Don't cancel work that is not initialized

Message ID 6a6b4c9ce80b0edb4c4c6a52d8b9a618a4325d42.1644772001.git.christophe.jaillet@wanadoo.fr
State Accepted
Commit de85193cff0d94d030a53656d8fcc41794807bef
Headers show
Series power: supply: sbs-charger: Don't cancel work that is not initialized | expand

Commit Message

Christophe JAILLET Feb. 13, 2022, 5:07 p.m. UTC
This driver can use an interrupt or polling in order get the charger's
status.

When using polling, a delayed work is used.

However, the remove() function unconditionally call
cancel_delayed_work_sync(), even if the delayed work is not used and is not
initialized.

In order to fix it, use devm_delayed_work_autocancel() and remove the now
useless remove() function.

Fixes: feb583e37f8a ("power: supply: add sbs-charger driver")
Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
2 more comments:
   - i2c_set_clientdata() looks now useless and could be removed as well.
     I've left it because removing such assigned already played me some
     unexpected trick.

   - Should this be backported, devm_delayed_work_autocancel() is not
     really old and may not be available in older kernel.
     In this case a "if (!client->irq)" in the remove function would also
     fix the issue
---
 drivers/power/supply/sbs-charger.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

Comments

Sebastian Reichel Feb. 24, 2022, 11:23 a.m. UTC | #1
Hi,

On Sun, Feb 13, 2022 at 06:07:03PM +0100, Christophe JAILLET wrote:
> This driver can use an interrupt or polling in order get the charger's
> status.
> 
> When using polling, a delayed work is used.
> 
> However, the remove() function unconditionally call
> cancel_delayed_work_sync(), even if the delayed work is not used and is not
> initialized.
> 
> In order to fix it, use devm_delayed_work_autocancel() and remove the now
> useless remove() function.
> 
> Fixes: feb583e37f8a ("power: supply: add sbs-charger driver")
> Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
> ---

Thanks, queued.

-- Sebastian
diff mbox series

Patch

diff --git a/drivers/power/supply/sbs-charger.c b/drivers/power/supply/sbs-charger.c
index 6fa65d118ec1..b08f7d0c4181 100644
--- a/drivers/power/supply/sbs-charger.c
+++ b/drivers/power/supply/sbs-charger.c
@@ -18,6 +18,7 @@ 
 #include <linux/interrupt.h>
 #include <linux/regmap.h>
 #include <linux/bitops.h>
+#include <linux/devm-helpers.h>
 
 #define SBS_CHARGER_REG_SPEC_INFO		0x11
 #define SBS_CHARGER_REG_STATUS			0x13
@@ -209,7 +210,12 @@  static int sbs_probe(struct i2c_client *client,
 		if (ret)
 			return dev_err_probe(&client->dev, ret, "Failed to request irq\n");
 	} else {
-		INIT_DELAYED_WORK(&chip->work, sbs_delayed_work);
+		ret = devm_delayed_work_autocancel(&client->dev, &chip->work,
+						   sbs_delayed_work);
+		if (ret)
+			return dev_err_probe(&client->dev, ret,
+					     "Failed to init work for polling\n");
+
 		schedule_delayed_work(&chip->work,
 				      msecs_to_jiffies(SBS_CHARGER_POLL_TIME));
 	}
@@ -220,15 +226,6 @@  static int sbs_probe(struct i2c_client *client,
 	return 0;
 }
 
-static int sbs_remove(struct i2c_client *client)
-{
-	struct sbs_info *chip = i2c_get_clientdata(client);
-
-	cancel_delayed_work_sync(&chip->work);
-
-	return 0;
-}
-
 #ifdef CONFIG_OF
 static const struct of_device_id sbs_dt_ids[] = {
 	{ .compatible = "sbs,sbs-charger" },
@@ -245,7 +242,6 @@  MODULE_DEVICE_TABLE(i2c, sbs_id);
 
 static struct i2c_driver sbs_driver = {
 	.probe		= sbs_probe,
-	.remove		= sbs_remove,
 	.id_table	= sbs_id,
 	.driver = {
 		.name	= "sbs-charger",