Skip to content

Commit e99e88a

Browse files
committed
treewide: setup_timer() -> timer_setup()
This converts all remaining cases of the old setup_timer() API into using timer_setup(), where the callback argument is the structure already holding the struct timer_list. These should have no behavioral changes, since they just change which pointer is passed into the callback with the same available pointers after conversion. It handles the following examples, in addition to some other variations. Casting from unsigned long: void my_callback(unsigned long data) { struct something *ptr = (struct something *)data; ... } ... setup_timer(&ptr->my_timer, my_callback, ptr); and forced object casts: void my_callback(struct something *ptr) { ... } ... setup_timer(&ptr->my_timer, my_callback, (unsigned long)ptr); become: void my_callback(struct timer_list *t) { struct something *ptr = from_timer(ptr, t, my_timer); ... } ... timer_setup(&ptr->my_timer, my_callback, 0); Direct function assignments: void my_callback(unsigned long data) { struct something *ptr = (struct something *)data; ... } ... ptr->my_timer.function = my_callback; have a temporary cast added, along with converting the args: void my_callback(struct timer_list *t) { struct something *ptr = from_timer(ptr, t, my_timer); ... } ... ptr->my_timer.function = (TIMER_FUNC_TYPE)my_callback; And finally, callbacks without a data assignment: void my_callback(unsigned long data) { ... } ... setup_timer(&ptr->my_timer, my_callback, 0); have their argument renamed to verify they're unused during conversion: void my_callback(struct timer_list *unused) { ... } ... timer_setup(&ptr->my_timer, my_callback, 0); The conversion is done with the following Coccinelle script: 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/timer_setup.cocci @fix_address_of@ expression e; @@ setup_timer( -&(e) +&e , ...) // Update any raw setup_timer() usages that have a NULL callback, but // would otherwise match change_timer_function_usage, since the latter // will update all function assignments done in the face of a NULL // function initialization in setup_timer(). @change_timer_function_usage_NULL@ expression _E; identifier _timer; type _cast_data; @@ ( -setup_timer(&_E->_timer, NULL, _E); +timer_setup(&_E->_timer, NULL, 0); | -setup_timer(&_E->_timer, NULL, (_cast_data)_E); +timer_setup(&_E->_timer, NULL, 0); | -setup_timer(&_E._timer, NULL, &_E); +timer_setup(&_E._timer, NULL, 0); | -setup_timer(&_E._timer, NULL, (_cast_data)&_E); +timer_setup(&_E._timer, NULL, 0); ) @change_timer_function_usage@ expression _E; identifier _timer; struct timer_list _stl; identifier _callback; type _cast_func, _cast_data; @@ ( -setup_timer(&_E->_timer, _callback, _E); +timer_setup(&_E->_timer, _callback, 0); | -setup_timer(&_E->_timer, &_callback, _E); +timer_setup(&_E->_timer, _callback, 0); | -setup_timer(&_E->_timer, _callback, (_cast_data)_E); +timer_setup(&_E->_timer, _callback, 0); | -setup_timer(&_E->_timer, &_callback, (_cast_data)_E); +timer_setup(&_E->_timer, _callback, 0); | -setup_timer(&_E->_timer, (_cast_func)_callback, _E); +timer_setup(&_E->_timer, _callback, 0); | -setup_timer(&_E->_timer, (_cast_func)&_callback, _E); +timer_setup(&_E->_timer, _callback, 0); | -setup_timer(&_E->_timer, (_cast_func)_callback, (_cast_data)_E); +timer_setup(&_E->_timer, _callback, 0); | -setup_timer(&_E->_timer, (_cast_func)&_callback, (_cast_data)_E); +timer_setup(&_E->_timer, _callback, 0); | -setup_timer(&_E._timer, _callback, (_cast_data)_E); +timer_setup(&_E._timer, _callback, 0); | -setup_timer(&_E._timer, _callback, (_cast_data)&_E); +timer_setup(&_E._timer, _callback, 0); | -setup_timer(&_E._timer, &_callback, (_cast_data)_E); +timer_setup(&_E._timer, _callback, 0); | -setup_timer(&_E._timer, &_callback, (_cast_data)&_E); +timer_setup(&_E._timer, _callback, 0); | -setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)_E); +timer_setup(&_E._timer, _callback, 0); | -setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)&_E); +timer_setup(&_E._timer, _callback, 0); | -setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)_E); +timer_setup(&_E._timer, _callback, 0); | -setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)&_E); +timer_setup(&_E._timer, _callback, 0); | _E->_timer@_stl.function = _callback; | _E->_timer@_stl.function = &_callback; | _E->_timer@_stl.function = (_cast_func)_callback; | _E->_timer@_stl.function = (_cast_func)&_callback; | _E._timer@_stl.function = _callback; | _E._timer@_stl.function = &_callback; | _E._timer@_stl.function = (_cast_func)_callback; | _E._timer@_stl.function = (_cast_func)&_callback; ) // callback(unsigned long arg) @change_callback_handle_cast depends on change_timer_function_usage@ identifier change_timer_function_usage._callback; identifier change_timer_function_usage._timer; type _origtype; identifier _origarg; type _handletype; identifier _handle; @@ void _callback( -_origtype _origarg +struct timer_list *t ) { ( ... when != _origarg _handletype *_handle = -(_handletype *)_origarg; +from_timer(_handle, t, _timer); ... when != _origarg | ... when != _origarg _handletype *_handle = -(void *)_origarg; +from_timer(_handle, t, _timer); ... when != _origarg | ... when != _origarg _handletype *_handle; ... when != _handle _handle = -(_handletype *)_origarg; +from_timer(_handle, t, _timer); ... when != _origarg | ... when != _origarg _handletype *_handle; ... when != _handle _handle = -(void *)_origarg; +from_timer(_handle, t, _timer); ... when != _origarg ) } // callback(unsigned long arg) without existing variable @change_callback_handle_cast_no_arg depends on change_timer_function_usage && !change_callback_handle_cast@ identifier change_timer_function_usage._callback; identifier change_timer_function_usage._timer; type _origtype; identifier _origarg; type _handletype; @@ void _callback( -_origtype _origarg +struct timer_list *t ) { + _handletype *_origarg = from_timer(_origarg, t, _timer); + ... when != _origarg - (_handletype *)_origarg + _origarg ... when != _origarg } // Avoid already converted callbacks. @match_callback_converted depends on change_timer_function_usage && !change_callback_handle_cast && !change_callback_handle_cast_no_arg@ identifier change_timer_function_usage._callback; identifier t; @@ void _callback(struct timer_list *t) { ... } // callback(struct something *handle) @change_callback_handle_arg depends on change_timer_function_usage && !match_callback_converted && !change_callback_handle_cast && !change_callback_handle_cast_no_arg@ identifier change_timer_function_usage._callback; identifier change_timer_function_usage._timer; type _handletype; identifier _handle; @@ void _callback( -_handletype *_handle +struct timer_list *t ) { + _handletype *_handle = from_timer(_handle, t, _timer); ... } // If change_callback_handle_arg ran on an empty function, remove // the added handler. @unchange_callback_handle_arg depends on change_timer_function_usage && change_callback_handle_arg@ identifier change_timer_function_usage._callback; identifier change_timer_function_usage._timer; type _handletype; identifier _handle; identifier t; @@ void _callback(struct timer_list *t) { - _handletype *_handle = from_timer(_handle, t, _timer); } // We only want to refactor the setup_timer() data argument if we've found // the matching callback. This undoes changes in change_timer_function_usage. @unchange_timer_function_usage depends on change_timer_function_usage && !change_callback_handle_cast && !change_callback_handle_cast_no_arg && !change_callback_handle_arg@ expression change_timer_function_usage._E; identifier change_timer_function_usage._timer; identifier change_timer_function_usage._callback; type change_timer_function_usage._cast_data; @@ ( -timer_setup(&_E->_timer, _callback, 0); +setup_timer(&_E->_timer, _callback, (_cast_data)_E); | -timer_setup(&_E._timer, _callback, 0); +setup_timer(&_E._timer, _callback, (_cast_data)&_E); ) // If we fixed a callback from a .function assignment, fix the // assignment cast now. @change_timer_function_assignment depends on change_timer_function_usage && (change_callback_handle_cast || change_callback_handle_cast_no_arg || change_callback_handle_arg)@ expression change_timer_function_usage._E; identifier change_timer_function_usage._timer; identifier change_timer_function_usage._callback; type _cast_func; typedef TIMER_FUNC_TYPE; @@ ( _E->_timer.function = -_callback +(TIMER_FUNC_TYPE)_callback ; | _E->_timer.function = -&_callback +(TIMER_FUNC_TYPE)_callback ; | _E->_timer.function = -(_cast_func)_callback; +(TIMER_FUNC_TYPE)_callback ; | _E->_timer.function = -(_cast_func)&_callback +(TIMER_FUNC_TYPE)_callback ; | _E._timer.function = -_callback +(TIMER_FUNC_TYPE)_callback ; | _E._timer.function = -&_callback; +(TIMER_FUNC_TYPE)_callback ; | _E._timer.function = -(_cast_func)_callback +(TIMER_FUNC_TYPE)_callback ; | _E._timer.function = -(_cast_func)&_callback +(TIMER_FUNC_TYPE)_callback ; ) // Sometimes timer functions are called directly. Replace matched args. @change_timer_function_calls depends on change_timer_function_usage && (change_callback_handle_cast || change_callback_handle_cast_no_arg || change_callback_handle_arg)@ expression _E; identifier change_timer_function_usage._timer; identifier change_timer_function_usage._callback; type _cast_data; @@ _callback( ( -(_cast_data)_E +&_E->_timer | -(_cast_data)&_E +&_E._timer | -_E +&_E->_timer ) ) // If a timer has been configured without a data argument, it can be // converted without regard to the callback argument, since it is unused. @match_timer_function_unused_data@ expression _E; identifier _timer; identifier _callback; @@ ( -setup_timer(&_E->_timer, _callback, 0); +timer_setup(&_E->_timer, _callback, 0); | -setup_timer(&_E->_timer, _callback, 0L); +timer_setup(&_E->_timer, _callback, 0); | -setup_timer(&_E->_timer, _callback, 0UL); +timer_setup(&_E->_timer, _callback, 0); | -setup_timer(&_E._timer, _callback, 0); +timer_setup(&_E._timer, _callback, 0); | -setup_timer(&_E._timer, _callback, 0L); +timer_setup(&_E._timer, _callback, 0); | -setup_timer(&_E._timer, _callback, 0UL); +timer_setup(&_E._timer, _callback, 0); | -setup_timer(&_timer, _callback, 0); +timer_setup(&_timer, _callback, 0); | -setup_timer(&_timer, _callback, 0L); +timer_setup(&_timer, _callback, 0); | -setup_timer(&_timer, _callback, 0UL); +timer_setup(&_timer, _callback, 0); | -setup_timer(_timer, _callback, 0); +timer_setup(_timer, _callback, 0); | -setup_timer(_timer, _callback, 0L); +timer_setup(_timer, _callback, 0); | -setup_timer(_timer, _callback, 0UL); +timer_setup(_timer, _callback, 0); ) @change_callback_unused_data depends on match_timer_function_unused_data@ identifier match_timer_function_unused_data._callback; type _origtype; identifier _origarg; @@ void _callback( -_origtype _origarg +struct timer_list *unused ) { ... when != _origarg } Signed-off-by: Kees Cook <[email protected]>
1 parent b9eaf18 commit e99e88a

File tree

227 files changed

+824
-937
lines changed

Some content is hidden

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

227 files changed

+824
-937
lines changed

arch/alpha/kernel/srmcons.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,9 @@ srmcons_do_receive_chars(struct tty_port *port)
6565
}
6666

6767
static void
68-
srmcons_receive_chars(unsigned long data)
68+
srmcons_receive_chars(struct timer_list *t)
6969
{
70-
struct srmcons_private *srmconsp = (struct srmcons_private *)data;
70+
struct srmcons_private *srmconsp = from_timer(srmconsp, t, timer);
7171
struct tty_port *port = &srmconsp->port;
7272
unsigned long flags;
7373
int incr = 10;
@@ -206,8 +206,7 @@ static const struct tty_operations srmcons_ops = {
206206
static int __init
207207
srmcons_init(void)
208208
{
209-
setup_timer(&srmcons_singleton.timer, srmcons_receive_chars,
210-
(unsigned long)&srmcons_singleton);
209+
timer_setup(&srmcons_singleton.timer, srmcons_receive_chars, 0);
211210
if (srm_is_registered_console) {
212211
struct tty_driver *driver;
213212
int err;

arch/arm/mach-iop32x/n2100.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ static void n2100_restart(enum reboot_mode mode, const char *cmd)
305305

306306
static struct timer_list power_button_poll_timer;
307307

308-
static void power_button_poll(unsigned long dummy)
308+
static void power_button_poll(struct timer_list *unused)
309309
{
310310
if (gpio_get_value(N2100_POWER_BUTTON) == 0) {
311311
ctrl_alt_del();
@@ -336,7 +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-
setup_timer(&power_button_poll_timer, power_button_poll, 0UL);
339+
timer_setup(&power_button_poll_timer, power_button_poll, 0);
340340
power_button_poll_timer.expires = jiffies + (HZ / 10);
341341
add_timer(&power_button_poll_timer);
342342
return 0;

arch/arm/mach-orion5x/db88f5281-setup.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ static struct platform_device db88f5281_nand_flash = {
172172
static void __iomem *db88f5281_7seg;
173173
static struct timer_list db88f5281_timer;
174174

175-
static void db88f5281_7seg_event(unsigned long data)
175+
static void db88f5281_7seg_event(struct timer_list *unused)
176176
{
177177
static int count = 0;
178178
writel(0, db88f5281_7seg + (count << 4));
@@ -189,7 +189,7 @@ static int __init db88f5281_7seg_init(void)
189189
printk(KERN_ERR "Failed to ioremap db88f5281_7seg\n");
190190
return -EIO;
191191
}
192-
setup_timer(&db88f5281_timer, db88f5281_7seg_event, 0);
192+
timer_setup(&db88f5281_timer, db88f5281_7seg_event, 0);
193193
mod_timer(&db88f5281_timer, jiffies + 2 * HZ);
194194
}
195195

arch/blackfin/kernel/nmi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ int check_nmi_wdt_touched(void)
166166
return 1;
167167
}
168168

169-
static void nmi_wdt_timer(unsigned long data)
169+
static void nmi_wdt_timer(struct timer_list *unused)
170170
{
171171
if (check_nmi_wdt_touched())
172172
nmi_wdt_keepalive();
@@ -180,7 +180,7 @@ static int __init init_nmi_wdt(void)
180180
nmi_wdt_start();
181181
nmi_active = true;
182182

183-
setup_timer(&ntimer, nmi_wdt_timer, 0UL);
183+
timer_setup(&ntimer, nmi_wdt_timer, 0);
184184
ntimer.expires = jiffies + NMI_CHECK_TIMEOUT;
185185
add_timer(&ntimer);
186186

arch/mips/lasat/picvue_proc.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ static const struct file_operations pvc_scroll_proc_fops = {
156156
.write = pvc_scroll_proc_write,
157157
};
158158

159-
void pvc_proc_timerfunc(unsigned long data)
159+
void pvc_proc_timerfunc(struct timer_list *unused)
160160
{
161161
if (scroll_dir < 0)
162162
pvc_move(DISPLAY|RIGHT);
@@ -197,7 +197,7 @@ static int __init pvc_proc_init(void)
197197
if (proc_entry == NULL)
198198
goto error;
199199

200-
setup_timer(&timer, pvc_proc_timerfunc, 0UL);
200+
timer_setup(&timer, pvc_proc_timerfunc, 0);
201201

202202
return 0;
203203
error:

arch/powerpc/kernel/tau_6xx.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ static void tau_timeout(void * info)
188188
local_irq_restore(flags);
189189
}
190190

191-
static void tau_timeout_smp(unsigned long unused)
191+
static void tau_timeout_smp(struct timer_list *unused)
192192
{
193193

194194
/* schedule ourselves to be run again */
@@ -230,7 +230,7 @@ int __init TAU_init(void)
230230

231231

232232
/* first, set up the window shrinking timer */
233-
setup_timer(&tau_timer, tau_timeout_smp, 0UL);
233+
timer_setup(&tau_timer, tau_timeout_smp, 0);
234234
tau_timer.expires = jiffies + shrink_timer;
235235
add_timer(&tau_timer);
236236

arch/powerpc/oprofile/op_model_cell.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ static inline void enable_ctr(u32 cpu, u32 ctr, u32 *pm07_cntrl)
451451
* This routine will alternate loading the virtual counters for
452452
* virtual CPUs
453453
*/
454-
static void cell_virtual_cntr(unsigned long data)
454+
static void cell_virtual_cntr(struct timer_list *unused)
455455
{
456456
int i, prev_hdw_thread, next_hdw_thread;
457457
u32 cpu;
@@ -555,7 +555,7 @@ static void cell_virtual_cntr(unsigned long data)
555555

556556
static void start_virt_cntrs(void)
557557
{
558-
setup_timer(&timer_virt_cntr, cell_virtual_cntr, 0UL);
558+
timer_setup(&timer_virt_cntr, cell_virtual_cntr, 0);
559559
timer_virt_cntr.expires = jiffies + HZ / 10;
560560
add_timer(&timer_virt_cntr);
561561
}
@@ -587,7 +587,7 @@ static int cell_reg_setup_spu_cycles(struct op_counter_config *ctr,
587587
* periodically based on kernel timer to switch which SPU is
588588
* being monitored in a round robbin fashion.
589589
*/
590-
static void spu_evnt_swap(unsigned long data)
590+
static void spu_evnt_swap(struct timer_list *unused)
591591
{
592592
int node;
593593
int cur_phys_spu, nxt_phys_spu, cur_spu_evnt_phys_spu_indx;
@@ -677,7 +677,7 @@ static void spu_evnt_swap(unsigned long data)
677677

678678
static void start_spu_event_swap(void)
679679
{
680-
setup_timer(&timer_spu_event_swap, spu_evnt_swap, 0UL);
680+
timer_setup(&timer_spu_event_swap, spu_evnt_swap, 0);
681681
timer_spu_event_swap.expires = jiffies + HZ / 25;
682682
add_timer(&timer_spu_event_swap);
683683
}

arch/powerpc/platforms/cell/spufs/sched.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -992,13 +992,13 @@ static void spu_calc_load(void)
992992
CALC_LOAD(spu_avenrun[2], EXP_15, active_tasks);
993993
}
994994

995-
static void spusched_wake(unsigned long data)
995+
static void spusched_wake(struct timer_list *unused)
996996
{
997997
mod_timer(&spusched_timer, jiffies + SPUSCHED_TICK);
998998
wake_up_process(spusched_task);
999999
}
10001000

1001-
static void spuloadavg_wake(unsigned long data)
1001+
static void spuloadavg_wake(struct timer_list *unused)
10021002
{
10031003
mod_timer(&spuloadavg_timer, jiffies + LOAD_FREQ);
10041004
spu_calc_load();
@@ -1124,8 +1124,8 @@ int __init spu_sched_init(void)
11241124
}
11251125
spin_lock_init(&spu_prio->runq_lock);
11261126

1127-
setup_timer(&spusched_timer, spusched_wake, 0);
1128-
setup_timer(&spuloadavg_timer, spuloadavg_wake, 0);
1127+
timer_setup(&spusched_timer, spusched_wake, 0);
1128+
timer_setup(&spuloadavg_timer, spuloadavg_wake, 0);
11291129

11301130
spusched_task = kthread_run(spusched_thread, NULL, "spusched");
11311131
if (IS_ERR(spusched_task)) {

arch/powerpc/platforms/powermac/low_i2c.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,9 @@ static irqreturn_t kw_i2c_irq(int irq, void *dev_id)
361361
return IRQ_HANDLED;
362362
}
363363

364-
static void kw_i2c_timeout(unsigned long data)
364+
static void kw_i2c_timeout(struct timer_list *t)
365365
{
366-
struct pmac_i2c_host_kw *host = (struct pmac_i2c_host_kw *)data;
366+
struct pmac_i2c_host_kw *host = from_timer(host, t, timeout_timer);
367367
unsigned long flags;
368368

369369
spin_lock_irqsave(&host->lock, flags);
@@ -513,7 +513,7 @@ static struct pmac_i2c_host_kw *__init kw_i2c_host_init(struct device_node *np)
513513
mutex_init(&host->mutex);
514514
init_completion(&host->complete);
515515
spin_lock_init(&host->lock);
516-
setup_timer(&host->timeout_timer, kw_i2c_timeout, (unsigned long)host);
516+
timer_setup(&host->timeout_timer, kw_i2c_timeout, 0);
517517

518518
psteps = of_get_property(np, "AAPL,address-step", NULL);
519519
steps = psteps ? (*psteps) : 0x10;

arch/s390/kernel/time.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ static void __init stp_reset(void)
523523
}
524524
}
525525

526-
static void stp_timeout(unsigned long dummy)
526+
static void stp_timeout(struct timer_list *unused)
527527
{
528528
queue_work(time_sync_wq, &stp_work);
529529
}
@@ -532,7 +532,7 @@ static int __init stp_init(void)
532532
{
533533
if (!test_bit(CLOCK_SYNC_HAS_STP, &clock_sync_flags))
534534
return 0;
535-
setup_timer(&stp_timer, stp_timeout, 0UL);
535+
timer_setup(&stp_timer, stp_timeout, 0);
536536
time_init_wq();
537537
if (!stp_online)
538538
return 0;

0 commit comments

Comments
 (0)