Skip to content

Commit b424550

Browse files
panickinggregkh
authored andcommitted
power: supply: pda_power: move from timer to delayed_work
[ Upstream commit 633e8799ddc09431be2744c4a1efdbda13af2b0b ] This changed is needed to avoid locking problem during boot as shown: <5>[ 8.824096] Registering SWP/SWPB emulation handler <6>[ 8.977294] clock: disabling unused clocks to save power <3>[ 9.108154] BUG: sleeping function called from invalid context at kernel_albert/kernel/mutex.c:269 <3>[ 9.122894] in_atomic(): 1, irqs_disabled(): 0, pid: 1, name: swapper/0 <4>[ 9.130249] 3 locks held by swapper/0/1: <4>[ 9.134613] #0: (&__lockdep_no_validate__){......}, at: [<c0342430>] __driver_attach+0x58/0xa8 <4>[ 9.144500] #1: (&__lockdep_no_validate__){......}, at: [<c0342440>] __driver_attach+0x68/0xa8 <4>[ 9.154357] AICP#2: (&polling_timer){......}, at: [<c0053770>] run_timer_softirq+0x108/0x3ec <4>[ 9.163726] Backtrace: <4>[ 9.166473] [<c001269c>] (dump_backtrace+0x0/0x114) from [<c067e5f0>] (dump_stack+0x20/0x24) <4>[ 9.175811] r6:00203230 r5:0000010d r4:d782e000 r3:60000113 <4>[ 9.182250] [<c067e5d0>] (dump_stack+0x0/0x24) from [<c007441c>] (__might_sleep+0x10c/0x128) <4>[ 9.191650] [<c0074310>] (__might_sleep+0x0/0x128) from [<c0688f60>] (mutex_lock_nested+0x34/0x36c) <4>[ 9.201660] r5:c02d5350 r4:d79a0c64 <4>[ 9.205688] [<c0688f2c>] (mutex_lock_nested+0x0/0x36c) from [<c02d5350>] (regulator_set_current_limit+0x30/0x118) <4>[ 9.217071] [<c02d5320>] (regulator_set_current_limit+0x0/0x118) from [<c0435ce0>] (update_charger+0x84/0xc4) <4>[ 9.228027] r7:d782fb20 r6:00000101 r5:c1767e94 r4:00000000 <4>[ 9.234436] [<c0435c5c>] (update_charger+0x0/0xc4) from [<c0435d40>] (psy_changed+0x20/0x48) <4>[ 9.243804] r5:d782e000 r4:c1767e94 <4>[ 9.247802] [<c0435d20>] (psy_changed+0x0/0x48) from [<c0435dec>] (polling_timer_func+0x84/0xb8) <4>[ 9.257537] r4:c1767e94 r3:00000002 <4>[ 9.261566] [<c0435d68>] (polling_timer_func+0x0/0xb8) from [<c00537e4>] (run_timer_softirq+0x17c/0x3ec) <4>[ 9.272033] r4:c1767eb0 r3:00000000 <4>[ 9.276062] [<c0053668>] (run_timer_softirq+0x0/0x3ec) from [<c004b000>] (__do_softirq+0xf0/0x298) <4>[ 9.286010] [<c004af10>] (__do_softirq+0x0/0x298) from [<c004b650>] (irq_exit+0x98/0xa0) <4>[ 9.295013] [<c004b5b8>] (irq_exit+0x0/0xa0) from [<c000edbc>] (handle_IRQ+0x60/0xc0) <4>[ 9.303680] r4:c1194e98 r3:c00bc778 <4>[ 9.307708] [<c000ed5c>] (handle_IRQ+0x0/0xc0) from [<c0008504>] (gic_handle_irq+0x34/0x68) <4>[ 9.316955] r8:000ac383 r7:d782fc3c r6:d782fc08 r5:c11936c4 r4:e0802100 <4>[ 9.324310] r3:c026ba48 <4>[ 9.327301] [<c00084d0>] (gic_handle_irq+0x0/0x68) from [<c068c2c0>] (__irq_svc+0x40/0x74) <4>[ 9.336456] Exception stack(0xd782fc08 to 0xd782fc50) <4>[ 9.342041] fc00: d6e30e6c ac383627 00000000 ac383417 ea19c000 ea200000 <4>[ 9.351104] fc20: beffffff 00000667 000ac383 d6e30670 d6e3066c d782fc94 d782fbe8 d782fc50 <4>[ 9.360168] fc40: c026ba48 c001d1f0 00000113 ffffffff Fixes: b299804 ("[BATTERY] pda_power platform driver") Signed-off-by: Michael Trimarchi <[email protected]> Signed-off-by: Anthony Brandon <[email protected]> Signed-off-by: Sebastian Reichel <[email protected]> Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 045901c commit b424550

File tree

1 file changed

+27
-22
lines changed

1 file changed

+27
-22
lines changed

drivers/power/pda_power.c

+27-22
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ static inline unsigned int get_irq_flags(struct resource *res)
3030
static struct device *dev;
3131
static struct pda_power_pdata *pdata;
3232
static struct resource *ac_irq, *usb_irq;
33-
static struct timer_list charger_timer;
34-
static struct timer_list supply_timer;
35-
static struct timer_list polling_timer;
33+
static struct delayed_work charger_work;
34+
static struct delayed_work polling_work;
35+
static struct delayed_work supply_work;
3636
static int polling;
3737

3838
#if IS_ENABLED(CONFIG_USB_PHY)
@@ -143,7 +143,7 @@ static void update_charger(void)
143143
}
144144
}
145145

146-
static void supply_timer_func(unsigned long unused)
146+
static void supply_work_func(struct work_struct *work)
147147
{
148148
if (ac_status == PDA_PSY_TO_CHANGE) {
149149
ac_status = new_ac_status;
@@ -164,11 +164,12 @@ static void psy_changed(void)
164164
* Okay, charger set. Now wait a bit before notifying supplicants,
165165
* charge power should stabilize.
166166
*/
167-
mod_timer(&supply_timer,
168-
jiffies + msecs_to_jiffies(pdata->wait_for_charger));
167+
cancel_delayed_work(&supply_work);
168+
schedule_delayed_work(&supply_work,
169+
msecs_to_jiffies(pdata->wait_for_charger));
169170
}
170171

171-
static void charger_timer_func(unsigned long unused)
172+
static void charger_work_func(struct work_struct *work)
172173
{
173174
update_status();
174175
psy_changed();
@@ -187,13 +188,14 @@ static irqreturn_t power_changed_isr(int irq, void *power_supply)
187188
* Wait a bit before reading ac/usb line status and setting charger,
188189
* because ac/usb status readings may lag from irq.
189190
*/
190-
mod_timer(&charger_timer,
191-
jiffies + msecs_to_jiffies(pdata->wait_for_status));
191+
cancel_delayed_work(&charger_work);
192+
schedule_delayed_work(&charger_work,
193+
msecs_to_jiffies(pdata->wait_for_status));
192194

193195
return IRQ_HANDLED;
194196
}
195197

196-
static void polling_timer_func(unsigned long unused)
198+
static void polling_work_func(struct work_struct *work)
197199
{
198200
int changed = 0;
199201

@@ -214,8 +216,9 @@ static void polling_timer_func(unsigned long unused)
214216
if (changed)
215217
psy_changed();
216218

217-
mod_timer(&polling_timer,
218-
jiffies + msecs_to_jiffies(pdata->polling_interval));
219+
cancel_delayed_work(&polling_work);
220+
schedule_delayed_work(&polling_work,
221+
msecs_to_jiffies(pdata->polling_interval));
219222
}
220223

221224
#if IS_ENABLED(CONFIG_USB_PHY)
@@ -253,8 +256,9 @@ static int otg_handle_notification(struct notifier_block *nb,
253256
* Wait a bit before reading ac/usb line status and setting charger,
254257
* because ac/usb status readings may lag from irq.
255258
*/
256-
mod_timer(&charger_timer,
257-
jiffies + msecs_to_jiffies(pdata->wait_for_status));
259+
cancel_delayed_work(&charger_work);
260+
schedule_delayed_work(&charger_work,
261+
msecs_to_jiffies(pdata->wait_for_status));
258262

259263
return NOTIFY_OK;
260264
}
@@ -302,8 +306,8 @@ static int pda_power_probe(struct platform_device *pdev)
302306
if (!pdata->ac_max_uA)
303307
pdata->ac_max_uA = 500000;
304308

305-
setup_timer(&charger_timer, charger_timer_func, 0);
306-
setup_timer(&supply_timer, supply_timer_func, 0);
309+
INIT_DELAYED_WORK(&charger_work, charger_work_func);
310+
INIT_DELAYED_WORK(&supply_work, supply_work_func);
307311

308312
ac_irq = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "ac");
309313
usb_irq = platform_get_resource_byname(pdev, IORESOURCE_IRQ, "usb");
@@ -381,9 +385,10 @@ static int pda_power_probe(struct platform_device *pdev)
381385

382386
if (polling) {
383387
dev_dbg(dev, "will poll for status\n");
384-
setup_timer(&polling_timer, polling_timer_func, 0);
385-
mod_timer(&polling_timer,
386-
jiffies + msecs_to_jiffies(pdata->polling_interval));
388+
INIT_DELAYED_WORK(&polling_work, polling_work_func);
389+
cancel_delayed_work(&polling_work);
390+
schedule_delayed_work(&polling_work,
391+
msecs_to_jiffies(pdata->polling_interval));
387392
}
388393

389394
if (ac_irq || usb_irq)
@@ -429,9 +434,9 @@ static int pda_power_remove(struct platform_device *pdev)
429434
free_irq(ac_irq->start, &pda_psy_ac);
430435

431436
if (polling)
432-
del_timer_sync(&polling_timer);
433-
del_timer_sync(&charger_timer);
434-
del_timer_sync(&supply_timer);
437+
cancel_delayed_work_sync(&polling_work);
438+
cancel_delayed_work_sync(&charger_work);
439+
cancel_delayed_work_sync(&supply_work);
435440

436441
if (pdata->is_usb_online)
437442
power_supply_unregister(&pda_psy_usb);

0 commit comments

Comments
 (0)