Skip to content

Commit b9eaf18

Browse files
committed
treewide: init_timer() -> setup_timer()
This mechanically converts all remaining cases of ancient open-coded timer setup with the old setup_timer() API, which is the first step in timer conversions. This has no behavioral changes, since it ultimately just changes the order of assignment to fields of struct timer_list when finding variations of: init_timer(&t); f.function = timer_callback; t.data = timer_callback_arg; to be converted into: setup_timer(&t, timer_callback, timer_callback_arg); The conversion is done with the following Coccinelle script, which is an improved version of scripts/cocci/api/setup_timer.cocci, in the following ways: - assignments-before-init_timer() cases - limit the .data case removal to the specific struct timer_list instance - handling calls by dereference (timer->field vs timer.field) spatch --very-quiet --all-includes --include-headers \ -I ./arch/x86/include -I ./arch/x86/include/generated \ -I ./include -I ./arch/x86/include/uapi \ -I ./arch/x86/include/generated/uapi -I ./include/uapi \ -I ./include/generated/uapi --include ./include/linux/kconfig.h \ --dir . \ --cocci-file ~/src/data/setup_timer.cocci @fix_address_of@ expression e; @@ init_timer( -&(e) +&e , ...) // Match the common cases first to avoid Coccinelle parsing loops with // "... when" clauses. @match_immediate_function_data_after_init_timer@ expression e, func, da; @@ -init_timer +setup_timer ( \(&e\|e\) +, func, da ); ( -\(e.function\|e->function\) = func; -\(e.data\|e->data\) = da; | -\(e.data\|e->data\) = da; -\(e.function\|e->function\) = func; ) @match_immediate_function_data_before_init_timer@ expression e, func, da; @@ ( -\(e.function\|e->function\) = func; -\(e.data\|e->data\) = da; | -\(e.data\|e->data\) = da; -\(e.function\|e->function\) = func; ) -init_timer +setup_timer ( \(&e\|e\) +, func, da ); @match_function_and_data_after_init_timer@ expression e, e2, e3, e4, e5, func, da; @@ -init_timer +setup_timer ( \(&e\|e\) +, func, da ); ... when != func = e2 when != da = e3 ( -e.function = func; ... when != da = e4 -e.data = da; | -e->function = func; ... when != da = e4 -e->data = da; | -e.data = da; ... when != func = e5 -e.function = func; | -e->data = da; ... when != func = e5 -e->function = func; ) @match_function_and_data_before_init_timer@ expression e, e2, e3, e4, e5, func, da; @@ ( -e.function = func; ... when != da = e4 -e.data = da; | -e->function = func; ... when != da = e4 -e->data = da; | -e.data = da; ... when != func = e5 -e.function = func; | -e->data = da; ... when != func = e5 -e->function = func; ) ... when != func = e2 when != da = e3 -init_timer +setup_timer ( \(&e\|e\) +, func, da ); @r1 exists@ expression t; identifier f; position p; @@ f(...) { ... when any init_timer@p(\(&t\|t\)) ... when any } @r2 exists@ expression r1.t; identifier g != r1.f; expression e8; @@ g(...) { ... when any \(t.data\|t->data\) = e8 ... when any } // It is dangerous to use setup_timer if data field is initialized // in another function. @script:python depends on r2@ p << r1.p; @@ cocci.include_match(False) @r3@ expression r1.t, func, e7; position r1.p; @@ ( -init_timer@p(&t); +setup_timer(&t, func, 0UL); ... when != func = e7 -t.function = func; | -t.function = func; ... when != func = e7 -init_timer@p(&t); +setup_timer(&t, func, 0UL); | -init_timer@p(t); +setup_timer(t, func, 0UL); ... when != func = e7 -t->function = func; | -t->function = func; ... when != func = e7 -init_timer@p(t); +setup_timer(t, func, 0UL); ) Signed-off-by: Kees Cook <[email protected]>
1 parent 24ed960 commit b9eaf18

File tree

31 files changed

+55
-113
lines changed

31 files changed

+55
-113
lines changed

arch/arm/mach-iop32x/n2100.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -336,8 +336,7 @@ static int __init n2100_request_gpios(void)
336336
pr_err("could not set power GPIO as input\n");
337337
}
338338
/* Set up power button poll timer */
339-
init_timer(&power_button_poll_timer);
340-
power_button_poll_timer.function = power_button_poll;
339+
setup_timer(&power_button_poll_timer, power_button_poll, 0UL);
341340
power_button_poll_timer.expires = jiffies + (HZ / 10);
342341
add_timer(&power_button_poll_timer);
343342
return 0;

arch/blackfin/kernel/nmi.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,7 @@ static int __init init_nmi_wdt(void)
180180
nmi_wdt_start();
181181
nmi_active = true;
182182

183-
init_timer(&ntimer);
184-
ntimer.function = nmi_wdt_timer;
183+
setup_timer(&ntimer, nmi_wdt_timer, 0UL);
185184
ntimer.expires = jiffies + NMI_CHECK_TIMEOUT;
186185
add_timer(&ntimer);
187186

arch/sh/drivers/pci/common.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,13 @@ static void pcibios_enable_serr(unsigned long __data)
106106
void pcibios_enable_timers(struct pci_channel *hose)
107107
{
108108
if (hose->err_irq) {
109-
init_timer(&hose->err_timer);
110-
hose->err_timer.data = (unsigned long)hose;
111-
hose->err_timer.function = pcibios_enable_err;
109+
setup_timer(&hose->err_timer, pcibios_enable_err,
110+
(unsigned long)hose);
112111
}
113112

114113
if (hose->serr_irq) {
115-
init_timer(&hose->serr_timer);
116-
hose->serr_timer.data = (unsigned long)hose;
117-
hose->serr_timer.function = pcibios_enable_serr;
114+
setup_timer(&hose->serr_timer, pcibios_enable_serr,
115+
(unsigned long)hose);
118116
}
119117
}
120118

arch/sh/drivers/push-switch.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,7 @@ static int switch_drv_probe(struct platform_device *pdev)
7878
}
7979

8080
INIT_WORK(&psw->work, switch_work_handler);
81-
init_timer(&psw->debounce);
82-
83-
psw->debounce.function = switch_timer;
84-
psw->debounce.data = (unsigned long)psw;
81+
setup_timer(&psw->debounce, switch_timer, (unsigned long)psw);
8582

8683
/* Workqueue API brain-damage */
8784
psw->pdev = pdev;

drivers/atm/firestream.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1885,9 +1885,7 @@ static int fs_init(struct fs_dev *dev)
18851885
}
18861886

18871887
#ifdef FS_POLL_FREQ
1888-
init_timer (&dev->timer);
1889-
dev->timer.data = (unsigned long) dev;
1890-
dev->timer.function = fs_poll;
1888+
setup_timer (&dev->timer, fs_poll, (unsigned long)dev);
18911889
dev->timer.expires = jiffies + FS_POLL_FREQ;
18921890
add_timer (&dev->timer);
18931891
#endif

drivers/atm/lanai.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1790,10 +1790,8 @@ static void lanai_timed_poll(unsigned long arg)
17901790

17911791
static inline void lanai_timed_poll_start(struct lanai_dev *lanai)
17921792
{
1793-
init_timer(&lanai->timer);
1793+
setup_timer(&lanai->timer, lanai_timed_poll, (unsigned long)lanai);
17941794
lanai->timer.expires = jiffies + LANAI_POLL_PERIOD;
1795-
lanai->timer.data = (unsigned long) lanai;
1796-
lanai->timer.function = lanai_timed_poll;
17971795
add_timer(&lanai->timer);
17981796
}
17991797

drivers/atm/nicstar.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,10 +284,8 @@ static int __init nicstar_init(void)
284284
XPRINTK("nicstar: nicstar_init() returned.\n");
285285

286286
if (!error) {
287-
init_timer(&ns_timer);
287+
setup_timer(&ns_timer, ns_poll, 0UL);
288288
ns_timer.expires = jiffies + NS_POLL_PERIOD;
289-
ns_timer.data = 0UL;
290-
ns_timer.function = ns_poll;
291289
add_timer(&ns_timer);
292290
}
293291

drivers/block/DAC960.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3079,11 +3079,10 @@ DAC960_InitializeController(DAC960_Controller_T *Controller)
30793079
/*
30803080
Initialize the Monitoring Timer.
30813081
*/
3082-
init_timer(&Controller->MonitoringTimer);
3082+
setup_timer(&Controller->MonitoringTimer,
3083+
DAC960_MonitoringTimerFunction, (unsigned long)Controller);
30833084
Controller->MonitoringTimer.expires =
30843085
jiffies + DAC960_MonitoringTimerInterval;
3085-
Controller->MonitoringTimer.data = (unsigned long) Controller;
3086-
Controller->MonitoringTimer.function = DAC960_MonitoringTimerFunction;
30873086
add_timer(&Controller->MonitoringTimer);
30883087
Controller->ControllerInitialized = true;
30893088
return true;

drivers/block/umem.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -738,8 +738,7 @@ static void check_all_batteries(unsigned long ptr)
738738

739739
static void init_battery_timer(void)
740740
{
741-
init_timer(&battery_timer);
742-
battery_timer.function = check_all_batteries;
741+
setup_timer(&battery_timer, check_all_batteries, 0UL);
743742
battery_timer.expires = jiffies + (HZ * 60);
744743
add_timer(&battery_timer);
745744
}

drivers/gpu/drm/omapdrm/dss/dsi.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5449,9 +5449,7 @@ static int dsi_bind(struct device *dev, struct device *master, void *data)
54495449
dsi_framedone_timeout_work_callback);
54505450

54515451
#ifdef DSI_CATCH_MISSING_TE
5452-
init_timer(&dsi->te_timer);
5453-
dsi->te_timer.function = dsi_te_timeout;
5454-
dsi->te_timer.data = 0;
5452+
setup_timer(&dsi->te_timer, dsi_te_timeout, 0);
54555453
#endif
54565454

54575455
dsi_mem = platform_get_resource_byname(dsidev, IORESOURCE_MEM, "proto");

0 commit comments

Comments
 (0)