treewide: Convert del_timer*() to timer_shutdown*()
authorSteven Rostedt (Google) <rostedt@goodmis.org>
Tue, 20 Dec 2022 18:45:19 +0000 (13:45 -0500)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sun, 25 Dec 2022 21:38:09 +0000 (13:38 -0800)
commit292a089d78d3e2f7944e60bb897c977785a321e3
treec9bdd3ea73fe57a35b358770998396cbc5813031
parent72a85e2b0a1e1e6fb4ee51ae902730212b2de25c
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>
69 files changed:
arch/sh/drivers/push-switch.c
block/blk-iocost.c
block/blk-iolatency.c
block/kyber-iosched.c
drivers/acpi/apei/ghes.c
drivers/atm/idt77252.c
drivers/block/drbd/drbd_main.c
drivers/block/loop.c
drivers/bluetooth/hci_bcsp.c
drivers/gpu/drm/i915/i915_sw_fence.c
drivers/hid/hid-wiimote-core.c
drivers/input/keyboard/locomokbd.c
drivers/input/keyboard/omap-keypad.c
drivers/input/mouse/alps.c
drivers/isdn/mISDN/l1oip_core.c
drivers/isdn/mISDN/timerdev.c
drivers/leds/trigger/ledtrig-activity.c
drivers/leds/trigger/ledtrig-heartbeat.c
drivers/leds/trigger/ledtrig-pattern.c
drivers/leds/trigger/ledtrig-transient.c
drivers/media/pci/ivtv/ivtv-driver.c
drivers/media/usb/pvrusb2/pvrusb2-hdw.c
drivers/media/usb/s2255/s2255drv.c
drivers/net/ethernet/intel/i40e/i40e_main.c
drivers/net/ethernet/marvell/sky2.c
drivers/net/ethernet/sun/sunvnet.c
drivers/net/usb/sierra_net.c
drivers/net/wireless/broadcom/brcm80211/brcmfmac/btcoex.c
drivers/net/wireless/intel/iwlwifi/iwl-dbg-tlv.c
drivers/net/wireless/intel/iwlwifi/mvm/sta.c
drivers/net/wireless/intersil/hostap/hostap_ap.c
drivers/net/wireless/marvell/mwifiex/main.c
drivers/net/wireless/microchip/wilc1000/hif.c
drivers/nfc/pn533/pn533.c
drivers/nfc/pn533/uart.c
drivers/pcmcia/bcm63xx_pcmcia.c
drivers/pcmcia/electra_cf.c
drivers/pcmcia/omap_cf.c
drivers/pcmcia/pd6729.c
drivers/pcmcia/yenta_socket.c
drivers/scsi/qla2xxx/qla_edif.c
drivers/staging/media/atomisp/i2c/atomisp-lm3554.c
drivers/staging/wlan-ng/prism2usb.c
drivers/tty/n_gsm.c
drivers/tty/sysrq.c
drivers/usb/gadget/udc/m66592-udc.c
drivers/usb/serial/garmin_gps.c
drivers/usb/serial/mos7840.c
fs/ext4/super.c
fs/nilfs2/segment.c
net/802/garp.c
net/802/mrp.c
net/bridge/br_multicast.c
net/bridge/br_multicast_eht.c
net/core/gen_estimator.c
net/ipv4/ipmr.c
net/ipv6/ip6mr.c
net/mac80211/mesh_pathtbl.c
net/netfilter/ipset/ip_set_list_set.c
net/netfilter/ipvs/ip_vs_lblc.c
net/netfilter/ipvs/ip_vs_lblcr.c
net/netfilter/xt_IDLETIMER.c
net/netfilter/xt_LED.c
net/sched/cls_flow.c
net/sunrpc/svc.c
net/tipc/discover.c
net/tipc/monitor.c
sound/i2c/other/ak4117.c
sound/synth/emux/emux.c