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

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

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>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>

authored by

Christophe JAILLET and committed by
Sebastian Reichel
de85193c 1ff8cc2c

+7 -11
+7 -11
drivers/power/supply/sbs-charger.c
··· 18 18 #include <linux/interrupt.h> 19 19 #include <linux/regmap.h> 20 20 #include <linux/bitops.h> 21 + #include <linux/devm-helpers.h> 21 22 22 23 #define SBS_CHARGER_REG_SPEC_INFO 0x11 23 24 #define SBS_CHARGER_REG_STATUS 0x13 ··· 210 209 if (ret) 211 210 return dev_err_probe(&client->dev, ret, "Failed to request irq\n"); 212 211 } else { 213 - INIT_DELAYED_WORK(&chip->work, sbs_delayed_work); 212 + ret = devm_delayed_work_autocancel(&client->dev, &chip->work, 213 + sbs_delayed_work); 214 + if (ret) 215 + return dev_err_probe(&client->dev, ret, 216 + "Failed to init work for polling\n"); 217 + 214 218 schedule_delayed_work(&chip->work, 215 219 msecs_to_jiffies(SBS_CHARGER_POLL_TIME)); 216 220 } 217 221 218 222 dev_info(&client->dev, 219 223 "%s: smart charger device registered\n", client->name); 220 - 221 - return 0; 222 - } 223 - 224 - static int sbs_remove(struct i2c_client *client) 225 - { 226 - struct sbs_info *chip = i2c_get_clientdata(client); 227 - 228 - cancel_delayed_work_sync(&chip->work); 229 224 230 225 return 0; 231 226 } ··· 242 245 243 246 static struct i2c_driver sbs_driver = { 244 247 .probe = sbs_probe, 245 - .remove = sbs_remove, 246 248 .id_table = sbs_id, 247 249 .driver = { 248 250 .name = "sbs-charger",