Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scsi: megaraid: Convert timers to use timer_setup()

In preparation for unconditionally passing the struct timer_list pointer to
all timer callbacks, switch to using the new timer_setup() and from_timer()
to pass the timer pointer explicitly. Also consolidates the timer setup
functions arguments, which are all identical, and corrects on-stack timer
usage.

Cc: Kashyap Desai <kashyap.desai@broadcom.com>
Cc: Sumit Saxena <sumit.saxena@broadcom.com>
Cc: Shivasharan S <shivasharan.srikanteshwara@broadcom.com>
Cc: "James E.J. Bottomley" <jejb@linux.vnet.ibm.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: megaraidlinux.pdl@broadcom.com
Cc: linux-scsi@vger.kernel.org
Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Martin K. Petersen <martin.petersen@oracle.com>

+46 -61
+6
drivers/scsi/megaraid/megaraid_ioctl.h
··· 19 19 20 20 #include <linux/types.h> 21 21 #include <linux/semaphore.h> 22 + #include <linux/timer.h> 22 23 23 24 #include "mbox_defs.h" 24 25 ··· 154 153 155 154 } __attribute__ ((aligned(1024),packed)) uioc_t; 156 155 156 + /* For on-stack uioc timers. */ 157 + struct uioc_timeout { 158 + struct timer_list timer; 159 + uioc_t *uioc; 160 + }; 157 161 158 162 /** 159 163 * struct mraid_hba_info - information about the controller
+12 -14
drivers/scsi/megaraid/megaraid_mbox.c
··· 3904 3904 wake_up(&raid_dev->sysfs_wait_q); 3905 3905 } 3906 3906 3907 - 3908 3907 /** 3909 3908 * megaraid_sysfs_get_ldmap_timeout - timeout handling for get ldmap 3910 - * @data : timed out packet 3909 + * @t : timed out timer 3911 3910 * 3912 3911 * Timeout routine to recover and return to application, in case the adapter 3913 3912 * has stopped responding. A timeout of 60 seconds for this command seems like 3914 3913 * a good value. 3915 3914 */ 3916 3915 static void 3917 - megaraid_sysfs_get_ldmap_timeout(unsigned long data) 3916 + megaraid_sysfs_get_ldmap_timeout(struct timer_list *t) 3918 3917 { 3919 - uioc_t *uioc = (uioc_t *)data; 3918 + struct uioc_timeout *timeout = from_timer(timeout, t, timer); 3919 + uioc_t *uioc = timeout->uioc; 3920 3920 adapter_t *adapter = (adapter_t *)uioc->buf_vaddr; 3921 3921 mraid_device_t *raid_dev = ADAP2RAIDDEV(adapter); 3922 3922 ··· 3951 3951 mbox64_t *mbox64; 3952 3952 mbox_t *mbox; 3953 3953 char *raw_mbox; 3954 - struct timer_list sysfs_timer; 3955 - struct timer_list *timerp; 3954 + struct uioc_timeout timeout; 3956 3955 caddr_t ldmap; 3957 3956 int rval = 0; 3958 3957 ··· 3987 3988 /* 3988 3989 * Setup a timer to recover from a non-responding controller 3989 3990 */ 3990 - timerp = &sysfs_timer; 3991 - init_timer(timerp); 3991 + timeout.uioc = uioc; 3992 + timer_setup_on_stack(&timeout.timer, 3993 + megaraid_sysfs_get_ldmap_timeout, 0); 3992 3994 3993 - timerp->function = megaraid_sysfs_get_ldmap_timeout; 3994 - timerp->data = (unsigned long)uioc; 3995 - timerp->expires = jiffies + 60 * HZ; 3996 - 3997 - add_timer(timerp); 3995 + timeout.timer.expires = jiffies + 60 * HZ; 3996 + add_timer(&timeout.timer); 3998 3997 3999 3998 /* 4000 3999 * Send the command to the firmware ··· 4030 4033 } 4031 4034 4032 4035 4033 - del_timer_sync(timerp); 4036 + del_timer_sync(&timeout.timer); 4037 + destroy_timer_on_stack(&timeout.timer); 4034 4038 4035 4039 mutex_unlock(&raid_dev->sysfs_mtx); 4036 4040
+13 -14
drivers/scsi/megaraid/megaraid_mm.c
··· 35 35 static int handle_drvrcmd(void __user *, uint8_t, int *); 36 36 static int lld_ioctl(mraid_mmadp_t *, uioc_t *); 37 37 static void ioctl_done(uioc_t *); 38 - static void lld_timedout(unsigned long); 38 + static void lld_timedout(struct timer_list *); 39 39 static void hinfo_to_cinfo(mraid_hba_info_t *, mcontroller_t *); 40 40 static mraid_mmadp_t *mraid_mm_get_adapter(mimd_t __user *, int *); 41 41 static uioc_t *mraid_mm_alloc_kioc(mraid_mmadp_t *); ··· 686 686 lld_ioctl(mraid_mmadp_t *adp, uioc_t *kioc) 687 687 { 688 688 int rval; 689 - struct timer_list timer; 690 - struct timer_list *tp = NULL; 689 + struct uioc_timeout timeout = { }; 691 690 692 691 kioc->status = -ENODATA; 693 692 rval = adp->issue_uioc(adp->drvr_data, kioc, IOCTL_ISSUE); ··· 697 698 * Start the timer 698 699 */ 699 700 if (adp->timeout > 0) { 700 - tp = &timer; 701 - init_timer(tp); 701 + timeout.uioc = kioc; 702 + timer_setup_on_stack(&timeout.timer, lld_timedout, 0); 702 703 703 - tp->function = lld_timedout; 704 - tp->data = (unsigned long)kioc; 705 - tp->expires = jiffies + adp->timeout * HZ; 704 + timeout.timer.expires = jiffies + adp->timeout * HZ; 706 705 707 - add_timer(tp); 706 + add_timer(&timeout.timer); 708 707 } 709 708 710 709 /* ··· 710 713 * call, the ioctl either completed successfully or timedout. 711 714 */ 712 715 wait_event(wait_q, (kioc->status != -ENODATA)); 713 - if (tp) { 714 - del_timer_sync(tp); 716 + if (timeout.timer.function) { 717 + del_timer_sync(&timeout.timer); 718 + destroy_timer_on_stack(&timeout.timer); 715 719 } 716 720 717 721 /* ··· 781 783 782 784 /** 783 785 * lld_timedout - callback from the expired timer 784 - * @ptr : ioctl packet that timed out 786 + * @t : timer that timed out 785 787 */ 786 788 static void 787 - lld_timedout(unsigned long ptr) 789 + lld_timedout(struct timer_list *t) 788 790 { 789 - uioc_t *kioc = (uioc_t *)ptr; 791 + struct uioc_timeout *timeout = from_timer(timeout, t, timer); 792 + uioc_t *kioc = timeout->uioc; 790 793 791 794 kioc->status = -ETIME; 792 795 kioc->timedout = 1;
+12 -21
drivers/scsi/megaraid/megaraid_sas_base.c
··· 2114 2114 megasas_check_and_restore_queue_depth(instance); 2115 2115 } 2116 2116 2117 + static void megasas_sriov_heartbeat_handler(struct timer_list *t); 2118 + 2117 2119 /** 2118 - * megasas_start_timer - Initializes a timer object 2120 + * megasas_start_timer - Initializes sriov heartbeat timer object 2119 2121 * @instance: Adapter soft state 2120 - * @timer: timer object to be initialized 2121 - * @fn: timer function 2122 - * @interval: time interval between timer function call 2123 2122 * 2124 2123 */ 2125 - void megasas_start_timer(struct megasas_instance *instance, 2126 - struct timer_list *timer, 2127 - void *fn, unsigned long interval) 2124 + void megasas_start_timer(struct megasas_instance *instance) 2128 2125 { 2129 - init_timer(timer); 2130 - timer->expires = jiffies + interval; 2131 - timer->data = (unsigned long)instance; 2132 - timer->function = fn; 2126 + struct timer_list *timer = &instance->sriov_heartbeat_timer; 2127 + 2128 + timer_setup(timer, megasas_sriov_heartbeat_handler, 0); 2129 + timer->expires = jiffies + MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF; 2133 2130 add_timer(timer); 2134 2131 } 2135 2132 ··· 2512 2515 } 2513 2516 2514 2517 /* Handler for SR-IOV heartbeat */ 2515 - void megasas_sriov_heartbeat_handler(unsigned long instance_addr) 2518 + static void megasas_sriov_heartbeat_handler(struct timer_list *t) 2516 2519 { 2517 2520 struct megasas_instance *instance = 2518 - (struct megasas_instance *)instance_addr; 2521 + from_timer(instance, t, sriov_heartbeat_timer); 2519 2522 2520 2523 if (instance->hb_host_mem->HB.fwCounter != 2521 2524 instance->hb_host_mem->HB.driverCounter) { ··· 5490 5493 /* Launch SR-IOV heartbeat timer */ 5491 5494 if (instance->requestorId) { 5492 5495 if (!megasas_sriov_start_heartbeat(instance, 1)) 5493 - megasas_start_timer(instance, 5494 - &instance->sriov_heartbeat_timer, 5495 - megasas_sriov_heartbeat_handler, 5496 - MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF); 5496 + megasas_start_timer(instance); 5497 5497 else 5498 5498 instance->skip_heartbeat_timer_del = 1; 5499 5499 } ··· 6501 6507 /* Re-launch SR-IOV heartbeat timer */ 6502 6508 if (instance->requestorId) { 6503 6509 if (!megasas_sriov_start_heartbeat(instance, 0)) 6504 - megasas_start_timer(instance, 6505 - &instance->sriov_heartbeat_timer, 6506 - megasas_sriov_heartbeat_handler, 6507 - MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF); 6510 + megasas_start_timer(instance); 6508 6511 else { 6509 6512 instance->skip_heartbeat_timer_del = 1; 6510 6513 goto fail_init_mfi;
+3 -12
drivers/scsi/megaraid/megaraid_sas_fusion.c
··· 85 85 void megaraid_sas_kill_hba(struct megasas_instance *instance); 86 86 87 87 extern u32 megasas_dbg_lvl; 88 - void megasas_sriov_heartbeat_handler(unsigned long instance_addr); 89 88 int megasas_sriov_start_heartbeat(struct megasas_instance *instance, 90 89 int initial); 91 - void megasas_start_timer(struct megasas_instance *instance, 92 - struct timer_list *timer, 93 - void *fn, unsigned long interval); 90 + void megasas_start_timer(struct megasas_instance *instance); 94 91 extern struct megasas_mgmt_info megasas_mgmt_info; 95 92 extern unsigned int resetwaittime; 96 93 extern unsigned int dual_qdepth_disable; ··· 4366 4369 /* Restart SR-IOV heartbeat */ 4367 4370 if (instance->requestorId) { 4368 4371 if (!megasas_sriov_start_heartbeat(instance, 0)) 4369 - megasas_start_timer(instance, 4370 - &instance->sriov_heartbeat_timer, 4371 - megasas_sriov_heartbeat_handler, 4372 - MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF); 4372 + megasas_start_timer(instance); 4373 4373 else 4374 4374 instance->skip_heartbeat_timer_del = 1; 4375 4375 } ··· 4398 4404 } else { 4399 4405 /* For VF: Restart HB timer if we didn't OCR */ 4400 4406 if (instance->requestorId) { 4401 - megasas_start_timer(instance, 4402 - &instance->sriov_heartbeat_timer, 4403 - megasas_sriov_heartbeat_handler, 4404 - MEGASAS_SRIOV_HEARTBEAT_INTERVAL_VF); 4407 + megasas_start_timer(instance); 4405 4408 } 4406 4409 clear_bit(MEGASAS_FUSION_IN_RESET, &instance->reset_flags); 4407 4410 instance->instancet->enable_intr(instance);