Skip to content

Commit 292a089

Browse files
rostedttorvalds
authored andcommitted
treewide: Convert del_timer*() to timer_shutdown*()
Due to several bugs caused by timers being re-armed after they are shutdown and just before they are freed, a new state of timers was added called "shutdown". After a timer is set to this state, then it can no longer be re-armed. The following script was run to find all the trivial locations where del_timer() or del_timer_sync() is called in the same function that the object holding the timer is freed. It also ignores any locations where the timer->function is modified between the del_timer*() and the free(), as that is not considered a "trivial" case. This was created by using a coccinelle script and the following commands: $ cat timer.cocci @@ expression ptr, slab; identifier timer, rfield; @@ ( - del_timer(&ptr->timer); + timer_shutdown(&ptr->timer); | - del_timer_sync(&ptr->timer); + timer_shutdown_sync(&ptr->timer); ) ... when strict when != ptr->timer ( kfree_rcu(ptr, rfield); | kmem_cache_free(slab, ptr); | kfree(ptr); ) $ spatch timer.cocci . > /tmp/t.patch $ patch -p1 < /tmp/t.patch Link: https://lore.kernel.org/lkml/20221123201306.823305113@linutronix.de/ Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org> Acked-by: Pavel Machek <pavel@ucw.cz> [ LED ] Acked-by: Kalle Valo <kvalo@kernel.org> [ wireless ] Acked-by: Paolo Abeni <pabeni@redhat.com> [ networking ] Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 72a85e2 commit 292a089

File tree

69 files changed

+97
-97
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+97
-97
lines changed

arch/sh/drivers/push-switch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ static int switch_drv_remove(struct platform_device *pdev)
102102

103103
platform_set_drvdata(pdev, NULL);
104104
flush_work(&psw->work);
105-
del_timer_sync(&psw->debounce);
105+
timer_shutdown_sync(&psw->debounce);
106106
free_irq(irq, pdev);
107107

108108
kfree(psw);

block/blk-iocost.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2820,7 +2820,7 @@ static void ioc_rqos_exit(struct rq_qos *rqos)
28202820
ioc->running = IOC_STOP;
28212821
spin_unlock_irq(&ioc->lock);
28222822

2823-
del_timer_sync(&ioc->timer);
2823+
timer_shutdown_sync(&ioc->timer);
28242824
free_percpu(ioc->pcpu_stat);
28252825
kfree(ioc);
28262826
}

block/blk-iolatency.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ static void blkcg_iolatency_exit(struct rq_qos *rqos)
644644
{
645645
struct blk_iolatency *blkiolat = BLKIOLATENCY(rqos);
646646

647-
del_timer_sync(&blkiolat->timer);
647+
timer_shutdown_sync(&blkiolat->timer);
648648
flush_work(&blkiolat->enable_work);
649649
blkcg_deactivate_policy(rqos->q, &blkcg_policy_iolatency);
650650
kfree(blkiolat);

block/kyber-iosched.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ static void kyber_exit_sched(struct elevator_queue *e)
434434
struct kyber_queue_data *kqd = e->elevator_data;
435435
int i;
436436

437-
del_timer_sync(&kqd->timer);
437+
timer_shutdown_sync(&kqd->timer);
438438
blk_stat_disable_accounting(kqd->q);
439439

440440
for (i = 0; i < KYBER_NUM_DOMAINS; i++)

drivers/acpi/apei/ghes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1431,7 +1431,7 @@ static int ghes_remove(struct platform_device *ghes_dev)
14311431
ghes->flags |= GHES_EXITING;
14321432
switch (generic->notify.type) {
14331433
case ACPI_HEST_NOTIFY_POLLED:
1434-
del_timer_sync(&ghes->timer);
1434+
timer_shutdown_sync(&ghes->timer);
14351435
break;
14361436
case ACPI_HEST_NOTIFY_EXTERNAL:
14371437
free_irq(ghes->irq, ghes);

drivers/atm/idt77252.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2213,7 +2213,7 @@ idt77252_init_ubr(struct idt77252_dev *card, struct vc_map *vc,
22132213
}
22142214
spin_unlock_irqrestore(&vc->lock, flags);
22152215
if (est) {
2216-
del_timer_sync(&est->timer);
2216+
timer_shutdown_sync(&est->timer);
22172217
kfree(est);
22182218
}
22192219

@@ -2530,7 +2530,7 @@ idt77252_close(struct atm_vcc *vcc)
25302530
vc->tx_vcc = NULL;
25312531

25322532
if (vc->estimator) {
2533-
del_timer(&vc->estimator->timer);
2533+
timer_shutdown(&vc->estimator->timer);
25342534
kfree(vc->estimator);
25352535
vc->estimator = NULL;
25362536
}
@@ -3752,7 +3752,7 @@ static void __exit idt77252_exit(void)
37523752
card = idt77252_chain;
37533753
dev = card->atmdev;
37543754
idt77252_chain = card->next;
3755-
del_timer_sync(&card->tst_timer);
3755+
timer_shutdown_sync(&card->tst_timer);
37563756

37573757
if (dev->phy->stop)
37583758
dev->phy->stop(dev);

drivers/block/drbd/drbd_main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2184,7 +2184,7 @@ void drbd_destroy_device(struct kref *kref)
21842184
struct drbd_resource *resource = device->resource;
21852185
struct drbd_peer_device *peer_device, *tmp_peer_device;
21862186

2187-
del_timer_sync(&device->request_timer);
2187+
timer_shutdown_sync(&device->request_timer);
21882188

21892189
/* paranoia asserts */
21902190
D_ASSERT(device, device->open_cnt == 0);

drivers/block/loop.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1755,7 +1755,7 @@ static void lo_free_disk(struct gendisk *disk)
17551755
if (lo->workqueue)
17561756
destroy_workqueue(lo->workqueue);
17571757
loop_free_idle_workers(lo, true);
1758-
del_timer_sync(&lo->timer);
1758+
timer_shutdown_sync(&lo->timer);
17591759
mutex_destroy(&lo->lo_mutex);
17601760
kfree(lo);
17611761
}

drivers/bluetooth/hci_bcsp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ static int bcsp_close(struct hci_uart *hu)
737737
{
738738
struct bcsp_struct *bcsp = hu->priv;
739739

740-
del_timer_sync(&bcsp->tbcsp);
740+
timer_shutdown_sync(&bcsp->tbcsp);
741741

742742
hu->priv = NULL;
743743

drivers/gpu/drm/i915/i915_sw_fence.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ static void irq_i915_sw_fence_work(struct irq_work *wrk)
465465
struct i915_sw_dma_fence_cb_timer *cb =
466466
container_of(wrk, typeof(*cb), work);
467467

468-
del_timer_sync(&cb->timer);
468+
timer_shutdown_sync(&cb->timer);
469469
dma_fence_put(cb->dma);
470470

471471
kfree_rcu(cb, rcu);

0 commit comments

Comments
 (0)