Commit b9eaf187 authored by Kees Cook's avatar Kees Cook

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: default avatarKees Cook <keescook@chromium.org>
parent 24ed960a
......@@ -336,8 +336,7 @@ static int __init n2100_request_gpios(void)
pr_err("could not set power GPIO as input\n");
}
/* Set up power button poll timer */
init_timer(&power_button_poll_timer);
power_button_poll_timer.function = power_button_poll;
setup_timer(&power_button_poll_timer, power_button_poll, 0UL);
power_button_poll_timer.expires = jiffies + (HZ / 10);
add_timer(&power_button_poll_timer);
return 0;
......
......@@ -180,8 +180,7 @@ static int __init init_nmi_wdt(void)
nmi_wdt_start();
nmi_active = true;
init_timer(&ntimer);
ntimer.function = nmi_wdt_timer;
setup_timer(&ntimer, nmi_wdt_timer, 0UL);
ntimer.expires = jiffies + NMI_CHECK_TIMEOUT;
add_timer(&ntimer);
......
......@@ -106,15 +106,13 @@ static void pcibios_enable_serr(unsigned long __data)
void pcibios_enable_timers(struct pci_channel *hose)
{
if (hose->err_irq) {
init_timer(&hose->err_timer);
hose->err_timer.data = (unsigned long)hose;
hose->err_timer.function = pcibios_enable_err;
setup_timer(&hose->err_timer, pcibios_enable_err,
(unsigned long)hose);
}
if (hose->serr_irq) {
init_timer(&hose->serr_timer);
hose->serr_timer.data = (unsigned long)hose;
hose->serr_timer.function = pcibios_enable_serr;
setup_timer(&hose->serr_timer, pcibios_enable_serr,
(unsigned long)hose);
}
}
......
......@@ -78,10 +78,7 @@ static int switch_drv_probe(struct platform_device *pdev)
}
INIT_WORK(&psw->work, switch_work_handler);
init_timer(&psw->debounce);
psw->debounce.function = switch_timer;
psw->debounce.data = (unsigned long)psw;
setup_timer(&psw->debounce, switch_timer, (unsigned long)psw);
/* Workqueue API brain-damage */
psw->pdev = pdev;
......
......@@ -1885,9 +1885,7 @@ static int fs_init(struct fs_dev *dev)
}
#ifdef FS_POLL_FREQ
init_timer (&dev->timer);
dev->timer.data = (unsigned long) dev;
dev->timer.function = fs_poll;
setup_timer (&dev->timer, fs_poll, (unsigned long)dev);
dev->timer.expires = jiffies + FS_POLL_FREQ;
add_timer (&dev->timer);
#endif
......
......@@ -1790,10 +1790,8 @@ static void lanai_timed_poll(unsigned long arg)
static inline void lanai_timed_poll_start(struct lanai_dev *lanai)
{
init_timer(&lanai->timer);
setup_timer(&lanai->timer, lanai_timed_poll, (unsigned long)lanai);
lanai->timer.expires = jiffies + LANAI_POLL_PERIOD;
lanai->timer.data = (unsigned long) lanai;
lanai->timer.function = lanai_timed_poll;
add_timer(&lanai->timer);
}
......
......@@ -284,10 +284,8 @@ static int __init nicstar_init(void)
XPRINTK("nicstar: nicstar_init() returned.\n");
if (!error) {
init_timer(&ns_timer);
setup_timer(&ns_timer, ns_poll, 0UL);
ns_timer.expires = jiffies + NS_POLL_PERIOD;
ns_timer.data = 0UL;
ns_timer.function = ns_poll;
add_timer(&ns_timer);
}
......
......@@ -3079,11 +3079,10 @@ DAC960_InitializeController(DAC960_Controller_T *Controller)
/*
Initialize the Monitoring Timer.
*/
init_timer(&Controller->MonitoringTimer);
setup_timer(&Controller->MonitoringTimer,
DAC960_MonitoringTimerFunction, (unsigned long)Controller);
Controller->MonitoringTimer.expires =
jiffies + DAC960_MonitoringTimerInterval;
Controller->MonitoringTimer.data = (unsigned long) Controller;
Controller->MonitoringTimer.function = DAC960_MonitoringTimerFunction;
add_timer(&Controller->MonitoringTimer);
Controller->ControllerInitialized = true;
return true;
......
......@@ -738,8 +738,7 @@ static void check_all_batteries(unsigned long ptr)
static void init_battery_timer(void)
{
init_timer(&battery_timer);
battery_timer.function = check_all_batteries;
setup_timer(&battery_timer, check_all_batteries, 0UL);
battery_timer.expires = jiffies + (HZ * 60);
add_timer(&battery_timer);
}
......
......@@ -5449,9 +5449,7 @@ static int dsi_bind(struct device *dev, struct device *master, void *data)
dsi_framedone_timeout_work_callback);
#ifdef DSI_CATCH_MISSING_TE
init_timer(&dsi->te_timer);
dsi->te_timer.function = dsi_te_timeout;
dsi->te_timer.data = 0;
setup_timer(&dsi->te_timer, dsi_te_timeout, 0);
#endif
dsi_mem = platform_get_resource_byname(dsidev, IORESOURCE_MEM, "proto");
......
......@@ -149,7 +149,7 @@ void mthca_start_catas_poll(struct mthca_dev *dev)
{
phys_addr_t addr;
init_timer(&dev->catas_err.timer);
setup_timer(&dev->catas_err.timer, poll_catas, (unsigned long)dev);
dev->catas_err.map = NULL;
addr = pci_resource_start(dev->pdev, 0) +
......@@ -164,8 +164,6 @@ void mthca_start_catas_poll(struct mthca_dev *dev)
return;
}
dev->catas_err.timer.data = (unsigned long) dev;
dev->catas_err.timer.function = poll_catas;
dev->catas_err.timer.expires = jiffies + MTHCA_CATAS_POLL_INTERVAL;
INIT_LIST_HEAD(&dev->catas_err.list);
add_timer(&dev->catas_err.timer);
......
......@@ -2294,8 +2294,7 @@ static int __init isdn_init(void)
printk(KERN_WARNING "isdn: Could not allocate device-struct.\n");
return -EIO;
}
init_timer(&dev->timer);
dev->timer.function = isdn_timer_funct;
setup_timer(&dev->timer, isdn_timer_funct, 0UL);
spin_lock_init(&dev->lock);
spin_lock_init(&dev->timerlock);
#ifdef MODULE
......
......@@ -1615,9 +1615,9 @@ isdn_net_ciscohdlck_connected(isdn_net_local *lp)
/* send slarp request because interface/seq.no.s reset */
isdn_net_ciscohdlck_slarp_send_request(lp);
init_timer(&lp->cisco_timer);
lp->cisco_timer.data = (unsigned long) lp;
lp->cisco_timer.function = isdn_net_ciscohdlck_slarp_send_keepalive;
setup_timer(&lp->cisco_timer,
isdn_net_ciscohdlck_slarp_send_keepalive,
(unsigned long)lp);
lp->cisco_timer.expires = jiffies + lp->cisco_keepalive_period * HZ;
add_timer(&lp->cisco_timer);
}
......
......@@ -1314,9 +1314,8 @@ static int s5p_mfc_probe(struct platform_device *pdev)
dev->hw_lock = 0;
INIT_WORK(&dev->watchdog_work, s5p_mfc_watchdog_worker);
atomic_set(&dev->watchdog_cnt, 0);
init_timer(&dev->watchdog_timer);
dev->watchdog_timer.data = (unsigned long)dev;
dev->watchdog_timer.function = s5p_mfc_watchdog;
setup_timer(&dev->watchdog_timer, s5p_mfc_watchdog,
(unsigned long)dev);
ret = v4l2_device_register(&pdev->dev, &dev->v4l2_dev);
if (ret)
......
......@@ -648,9 +648,8 @@ int au0828_dvb_register(struct au0828_dev *dev)
return ret;
}
dev->bulk_timeout.function = au0828_bulk_timeout;
dev->bulk_timeout.data = (unsigned long) dev;
init_timer(&dev->bulk_timeout);
setup_timer(&dev->bulk_timeout, au0828_bulk_timeout,
(unsigned long)dev);
return 0;
}
......
......@@ -1189,10 +1189,8 @@ static struct sta_info * ap_add_sta(struct ap_data *ap, u8 *addr)
}
#ifndef PRISM2_NO_KERNEL_IEEE80211_MGMT
init_timer(&sta->timer);
setup_timer(&sta->timer, ap_handle_timer, (unsigned long)sta);
sta->timer.expires = jiffies + ap->max_inactivity;
sta->timer.data = (unsigned long) sta;
sta->timer.function = ap_handle_timer;
if (!ap->local->hostapd)
add_timer(&sta->timer);
#endif /* PRISM2_NO_KERNEL_IEEE80211_MGMT */
......
......@@ -3225,13 +3225,10 @@ while (0)
lib80211_crypt_info_init(&local->crypt_info, dev->name, &local->lock);
init_timer(&local->passive_scan_timer);
local->passive_scan_timer.data = (unsigned long) local;
local->passive_scan_timer.function = hostap_passive_scan;
init_timer(&local->tick_timer);
local->tick_timer.data = (unsigned long) local;
local->tick_timer.function = hostap_tick_timer;
setup_timer(&local->passive_scan_timer, hostap_passive_scan,
(unsigned long)local);
setup_timer(&local->tick_timer, hostap_tick_timer,
(unsigned long)local);
local->tick_timer.expires = jiffies + 2 * HZ;
add_timer(&local->tick_timer);
......
......@@ -2632,9 +2632,8 @@ struct pn533 *pn533_register_device(u32 device_type,
if (priv->wq == NULL)
goto error;
init_timer(&priv->listen_timer);
priv->listen_timer.data = (unsigned long) priv;
priv->listen_timer.function = pn533_listen_mode_timer;
setup_timer(&priv->listen_timer, pn533_listen_mode_timer,
(unsigned long)priv);
skb_queue_head_init(&priv->resp_q);
skb_queue_head_init(&priv->fragment_skb);
......
......@@ -282,13 +282,8 @@ int ndlc_probe(void *phy_id, struct nfc_phy_ops *phy_ops, struct device *dev,
*ndlc_id = ndlc;
/* initialize timers */
init_timer(&ndlc->t1_timer);
ndlc->t1_timer.data = (unsigned long)ndlc;
ndlc->t1_timer.function = ndlc_t1_timeout;
init_timer(&ndlc->t2_timer);
ndlc->t2_timer.data = (unsigned long)ndlc;
ndlc->t2_timer.function = ndlc_t2_timeout;
setup_timer(&ndlc->t1_timer, ndlc_t1_timeout, (unsigned long)ndlc);
setup_timer(&ndlc->t2_timer, ndlc_t2_timeout, (unsigned long)ndlc);
skb_queue_head_init(&ndlc->rcv_q);
skb_queue_head_init(&ndlc->send_q);
......
......@@ -725,15 +725,12 @@ int st_nci_se_init(struct nci_dev *ndev, struct st_nci_se_status *se_status)
init_completion(&info->se_info.req_completion);
/* initialize timers */
init_timer(&info->se_info.bwi_timer);
info->se_info.bwi_timer.data = (unsigned long)info;
info->se_info.bwi_timer.function = st_nci_se_wt_timeout;
setup_timer(&info->se_info.bwi_timer, st_nci_se_wt_timeout,
(unsigned long)info);
info->se_info.bwi_active = false;
init_timer(&info->se_info.se_active_timer);
info->se_info.se_active_timer.data = (unsigned long)info;
info->se_info.se_active_timer.function =
st_nci_se_activation_timeout;
setup_timer(&info->se_info.se_active_timer,
st_nci_se_activation_timeout, (unsigned long)info);
info->se_info.se_active = false;
info->se_info.xch_error = false;
......
......@@ -392,14 +392,12 @@ void st21nfca_se_init(struct nfc_hci_dev *hdev)
init_completion(&info->se_info.req_completion);
/* initialize timers */
init_timer(&info->se_info.bwi_timer);
info->se_info.bwi_timer.data = (unsigned long)info;
info->se_info.bwi_timer.function = st21nfca_se_wt_timeout;
setup_timer(&info->se_info.bwi_timer, st21nfca_se_wt_timeout,
(unsigned long)info);
info->se_info.bwi_active = false;
init_timer(&info->se_info.se_active_timer);
info->se_info.se_active_timer.data = (unsigned long)info;
info->se_info.se_active_timer.function = st21nfca_se_activation_timeout;
setup_timer(&info->se_info.se_active_timer,
st21nfca_se_activation_timeout, (unsigned long)info);
info->se_info.se_active = false;
info->se_info.count_pipes = 0;
......
......@@ -119,9 +119,8 @@ struct dasd_device *dasd_alloc_device(void)
(void (*)(unsigned long)) dasd_device_tasklet,
(unsigned long) device);
INIT_LIST_HEAD(&device->ccw_queue);
init_timer(&device->timer);
device->timer.function = dasd_device_timeout;
device->timer.data = (unsigned long) device;
setup_timer(&device->timer, dasd_device_timeout,
(unsigned long)device);
INIT_WORK(&device->kick_work, do_kick_device);
INIT_WORK(&device->restore_device, do_restore_device);
INIT_WORK(&device->reload_device, do_reload_device);
......@@ -163,9 +162,7 @@ struct dasd_block *dasd_alloc_block(void)
(unsigned long) block);
INIT_LIST_HEAD(&block->ccw_queue);
spin_lock_init(&block->queue_lock);
init_timer(&block->timer);
block->timer.function = dasd_block_timeout;
block->timer.data = (unsigned long) block;
setup_timer(&block->timer, dasd_block_timeout, (unsigned long)block);
spin_lock_init(&block->profile.lock);
return block;
......
......@@ -142,13 +142,11 @@ void
fsm_settimer(fsm_instance *fi, fsm_timer *this)
{
this->fi = fi;
this->tl.function = (void *)fsm_expire_timer;
this->tl.data = (long)this;
#if FSM_TIMER_DEBUG
printk(KERN_DEBUG "fsm(%s): Create timer %p\n", fi->name,
this);
#endif
init_timer(&this->tl);
setup_timer(&this->tl, (void *)fsm_expire_timer, (long)this);
}
void
......
......@@ -837,10 +837,9 @@ static int arcmsr_probe(struct pci_dev *pdev, const struct pci_device_id *id)
atomic_set(&acb->rq_map_token, 16);
atomic_set(&acb->ante_token_value, 16);
acb->fw_flag = FW_NORMAL;
init_timer(&acb->eternal_timer);
setup_timer(&acb->eternal_timer, &arcmsr_request_device_map,
(unsigned long)acb);
acb->eternal_timer.expires = jiffies + msecs_to_jiffies(6 * HZ);
acb->eternal_timer.data = (unsigned long) acb;
acb->eternal_timer.function = &arcmsr_request_device_map;
add_timer(&acb->eternal_timer);
if(arcmsr_alloc_sysfs_attr(acb))
goto out_free_sysfs;
......@@ -930,10 +929,9 @@ static int arcmsr_resume(struct pci_dev *pdev)
atomic_set(&acb->rq_map_token, 16);
atomic_set(&acb->ante_token_value, 16);
acb->fw_flag = FW_NORMAL;
init_timer(&acb->eternal_timer);
setup_timer(&acb->eternal_timer, &arcmsr_request_device_map,
(unsigned long)acb);
acb->eternal_timer.expires = jiffies + msecs_to_jiffies(6 * HZ);
acb->eternal_timer.data = (unsigned long) acb;
acb->eternal_timer.function = &arcmsr_request_device_map;
add_timer(&acb->eternal_timer);
return 0;
controller_stop:
......
......@@ -2849,9 +2849,7 @@ int fas216_init(struct Scsi_Host *host)
info->rst_dev_status = -1;
info->rst_bus_status = -1;
init_waitqueue_head(&info->eh_wait);
init_timer(&info->eh_timer);
info->eh_timer.data = (unsigned long)info;
info->eh_timer.function = fas216_eh_timer;
setup_timer(&info->eh_timer, fas216_eh_timer, (unsigned long)info);
spin_lock_init(&info->host_lock);
......
......@@ -719,9 +719,7 @@ bfad_bfa_tmo(unsigned long data)
void
bfad_init_timer(struct bfad_s *bfad)
{
init_timer(&bfad->hal_tmo);
bfad->hal_tmo.function = bfad_bfa_tmo;
bfad->hal_tmo.data = (unsigned long)bfad;
setup_timer(&bfad->hal_tmo, bfad_bfa_tmo, (unsigned long)bfad);
mod_timer(&bfad->hal_tmo,
jiffies + msecs_to_jiffies(BFA_TIMER_FREQ));
......
......@@ -1635,10 +1635,8 @@ static void esas2r_timer_callback(unsigned long context);
void esas2r_kickoff_timer(struct esas2r_adapter *a)
{
init_timer(&a->timer);
setup_timer(&a->timer, esas2r_timer_callback, (unsigned long)a);
a->timer.function = esas2r_timer_callback;
a->timer.data = (unsigned long)a;
a->timer.expires = jiffies +
msecs_to_jiffies(100);
......
......@@ -8357,9 +8357,7 @@ struct Scsi_Host * __init ncr_attach(struct scsi_host_template *tpnt,
if (!np->scripth0)
goto attach_error;
init_timer(&np->timer);
np->timer.data = (unsigned long) np;
np->timer.function = ncr53c8xx_timeout;
setup_timer(&np->timer, ncr53c8xx_timeout, (unsigned long)np);
/* Try to map the controller chip to virtual and physical memory. */
......
......@@ -1351,9 +1351,7 @@ static struct Scsi_Host *sym_attach(struct scsi_host_template *tpnt, int unit,
/*
* Start the timer daemon
*/
init_timer(&np->s.timer);
np->s.timer.data = (unsigned long) np;
np->s.timer.function = sym53c8xx_timer;
setup_timer(&np->s.timer, sym53c8xx_timer, (unsigned long)np);
np->s.lasttime=0;
sym_timer (np);
......
......@@ -2542,9 +2542,7 @@ omap_ep_setup(char *name, u8 addr, u8 type,
}
if (dbuf && addr)
epn_rxtx |= UDC_EPN_RX_DB;
init_timer(&ep->timer);
ep->timer.function = pio_out_timer;
ep->timer.data = (unsigned long) ep;
setup_timer(&ep->timer, pio_out_timer, (unsigned long)ep);
}
if (addr)
epn_rxtx |= UDC_EPN_RX_VALID;
......
......@@ -290,8 +290,7 @@ static inline void clocksource_start_watchdog(void)
{
if (watchdog_running || !watchdog || list_empty(&watchdog_list))
return;
init_timer(&watchdog_timer);
watchdog_timer.function = clocksource_watchdog;
setup_timer(&watchdog_timer, clocksource_watchdog, 0UL);
watchdog_timer.expires = jiffies + WATCHDOG_INTERVAL;
add_timer_on(&watchdog_timer, cpumask_first(cpu_online_mask));
watchdog_running = 1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment