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

staging: r8712u: Simplify semaphores

I am preparing to convert this driver from semaphore to mutex locking,
The first step has been to eliminate a number of semaphores that were
initialized but never used, and one whose only use was a single "up"
after initialization. A total of 9 semaphores were removed in this process.

One other change was to remove some inline semaphore routines that were
unused.

In addition, several cases had the following structure:

down()
if () {
...
}
up()

The locking overhead was reduced by moving the up/down inside the if
block.

Signed-off-by: Larry Finger <Larry.Finger@lwfinger.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Larry Finger and committed by
Greg Kroah-Hartman
86587b67 d8e4cd99

+4 -42
-1
drivers/staging/rtl8712/drv_types.h
··· 138 138 u8 ishighspeed; 139 139 uint(*inirp_init)(struct _adapter *adapter); 140 140 uint(*inirp_deinit)(struct _adapter *adapter); 141 - struct semaphore usb_suspend_sema; 142 141 struct usb_device *pusbdev; 143 142 }; 144 143
-1
drivers/staging/rtl8712/os_intfs.c
··· 329 329 padapter->stapriv.padapter = padapter; 330 330 r8712_init_bcmc_stainfo(padapter); 331 331 r8712_init_pwrctrl_priv(padapter); 332 - sema_init(&(padapter->pwrctrlpriv.pnp_pwr_mgnt_sema), 0); 333 332 mp871xinit(padapter); 334 333 if (init_default_value(padapter) != _SUCCESS) 335 334 return _FAIL;
-17
drivers/staging/rtl8712/osdep_service.h
··· 72 72 #define LIST_CONTAINOR(ptr, type, member) \ 73 73 ((type *)((char *)(ptr)-(SIZE_T)(&((type *)0)->member))) 74 74 75 - static inline void _enter_hwio_critical(struct semaphore *prwlock, 76 - unsigned long *pirqL) 77 - { 78 - down(prwlock); 79 - } 80 - 81 - static inline void _exit_hwio_critical(struct semaphore *prwlock, 82 - unsigned long *pirqL) 83 - { 84 - up(prwlock); 85 - } 86 - 87 75 static inline void list_delete(struct list_head *plist) 88 76 { 89 77 list_del_init(plist); ··· 138 150 return _FAIL; 139 151 else 140 152 return _SUCCESS; 141 - } 142 - 143 - static inline void _rtl_rwlock_init(struct semaphore *prwlock) 144 - { 145 - sema_init(prwlock, 1); 146 153 } 147 154 148 155 static inline void _init_listhead(struct list_head *list)
-2
drivers/staging/rtl8712/rtl8712_recv.c
··· 55 55 int alignment = 0; 56 56 struct sk_buff *pskb = NULL; 57 57 58 - sema_init(&precvpriv->recv_sema, 0); 59 - sema_init(&precvpriv->terminate_recvthread_sema, 0); 60 58 /*init recv_buf*/ 61 59 _init_queue(&precvpriv->free_recv_buf_queue); 62 60 precvpriv->pallocated_recv_buf = _malloc(NR_RECVBUFF *
-1
drivers/staging/rtl8712/rtl871x_io.c
··· 131 131 pio_req = (struct io_req *)(pio_queue->free_ioreqs_buf); 132 132 for (i = 0; i < NUM_IOREQ; i++) { 133 133 _init_listhead(&pio_req->list); 134 - sema_init(&pio_req->sema, 0); 135 134 list_insert_tail(&pio_req->list, &pio_queue->free_ioreqs); 136 135 pio_req++; 137 136 }
-1
drivers/staging/rtl8712/rtl871x_io.h
··· 117 117 u32 command; 118 118 u32 status; 119 119 u8 *pbuf; 120 - struct semaphore sema; 121 120 void (*_async_io_callback)(struct _adapter *padater, 122 121 struct io_req *pio_req, u8 *cnxt); 123 122 u8 *cnxt;
+4 -7
drivers/staging/rtl8712/rtl871x_pwrctrl.c
··· 100 100 { 101 101 struct pwrctrl_priv *pwrpriv = &(padapter->pwrctrlpriv); 102 102 struct cmd_priv *pcmdpriv = &(padapter->cmdpriv); 103 - struct xmit_priv *pxmitpriv = &(padapter->xmitpriv); 104 103 105 104 if (pwrpriv->cpwm_tog == ((preportpwrstate->state) & 0x80)) 106 105 return; ··· 109 110 if (pwrpriv->cpwm >= PS_STATE_S2) { 110 111 if (pwrpriv->alives & CMD_ALIVE) 111 112 up(&(pcmdpriv->cmd_queue_sema)); 112 - if (pwrpriv->alives & XMIT_ALIVE) 113 - up(&(pxmitpriv->xmit_sema)); 114 113 } 115 114 pwrpriv->cpwm_tog = (preportpwrstate->state) & 0x80; 116 115 up(&pwrpriv->lock); ··· 142 145 struct pwrctrl_priv, SetPSModeWorkItem); 143 146 struct _adapter *padapter = container_of(pwrpriv, 144 147 struct _adapter, pwrctrlpriv); 145 - _enter_pwrlock(&pwrpriv->lock); 146 148 if (!pwrpriv->bSleep) { 149 + _enter_pwrlock(&pwrpriv->lock); 147 150 if (pwrpriv->pwr_mode == PS_MODE_ACTIVE) 148 151 r8712_set_rpwm(padapter, PS_STATE_S4); 152 + up(&pwrpriv->lock); 149 153 } 150 - up(&pwrpriv->lock); 151 154 } 152 155 153 156 static void rpwm_workitem_callback(struct work_struct *work) ··· 157 160 struct _adapter *padapter = container_of(pwrpriv, 158 161 struct _adapter, pwrctrlpriv); 159 162 u8 cpwm = pwrpriv->cpwm; 160 - _enter_pwrlock(&pwrpriv->lock); 161 163 if (pwrpriv->cpwm != pwrpriv->rpwm) { 164 + _enter_pwrlock(&pwrpriv->lock); 162 165 cpwm = r8712_read8(padapter, SDIO_HCPWM); 163 166 pwrpriv->rpwm_retry = 1; 164 167 r8712_set_rpwm(padapter, pwrpriv->rpwm); 168 + up(&pwrpriv->lock); 165 169 } 166 - up(&pwrpriv->lock); 167 170 } 168 171 169 172 static void rpwm_check_handler (void *FunctionContext)
-1
drivers/staging/rtl8712/rtl871x_pwrctrl.h
··· 133 133 u8 rpwm_retry; 134 134 uint bSetPSModeWorkItemInProgress; 135 135 136 - struct semaphore pnp_pwr_mgnt_sema; 137 136 spinlock_t pnp_pwr_mgnt_lock; 138 137 s32 pnp_current_pwr_state; 139 138 u8 pnp_bstop_trx;
-1
drivers/staging/rtl8712/rtl871x_recv.c
··· 93 93 precvframe++; 94 94 } 95 95 precvpriv->rx_pending_cnt = 1; 96 - sema_init(&precvpriv->allrxreturnevt, 0); 97 96 return r8712_init_recv_priv(precvpriv, padapter); 98 97 } 99 98
-3
drivers/staging/rtl8712/rtl871x_recv.h
··· 85 85 */ 86 86 struct recv_priv { 87 87 spinlock_t lock; 88 - struct semaphore recv_sema; 89 - struct semaphore terminate_recvthread_sema; 90 88 struct __queue free_recv_queue; 91 89 struct __queue recv_pending_queue; 92 90 u8 *pallocated_frame_buf; ··· 98 100 uint rx_largepacket_crcerr; 99 101 uint rx_smallpacket_crcerr; 100 102 uint rx_middlepacket_crcerr; 101 - struct semaphore allrxreturnevt; 102 103 u8 rx_pending_cnt; 103 104 uint ff_hwaddr; 104 105 struct tasklet_struct recv_tasklet;
-3
drivers/staging/rtl8712/rtl871x_xmit.c
··· 71 71 72 72 memset((unsigned char *)pxmitpriv, 0, sizeof(struct xmit_priv)); 73 73 spin_lock_init(&pxmitpriv->lock); 74 - sema_init(&pxmitpriv->xmit_sema, 0); 75 - sema_init(&pxmitpriv->terminate_xmitthread_sema, 0); 76 74 /* 77 75 Please insert all the queue initializaiton using _init_queue below 78 76 */ ··· 119 121 _r8712_init_hw_txqueue(&pxmitpriv->bmc_txqueue, BMC_QUEUE_INX); 120 122 pxmitpriv->frag_len = MAX_FRAG_THRESHOLD; 121 123 pxmitpriv->txirp_cnt = 1; 122 - sema_init(&(pxmitpriv->tx_retevt), 0); 123 124 /*per AC pending irp*/ 124 125 pxmitpriv->beq_cnt = 0; 125 126 pxmitpriv->bkq_cnt = 0;
-3
drivers/staging/rtl8712/rtl871x_xmit.h
··· 202 202 203 203 struct xmit_priv { 204 204 spinlock_t lock; 205 - struct semaphore xmit_sema; 206 - struct semaphore terminate_xmitthread_sema; 207 205 struct __queue be_pending; 208 206 struct __queue bk_pending; 209 207 struct __queue vi_pending; ··· 231 233 uint tx_drop; 232 234 struct hw_xmit *hwxmits; 233 235 u8 hwxmit_entry; 234 - struct semaphore tx_retevt;/*all tx return event;*/ 235 236 u8 txirp_cnt; 236 237 struct tasklet_struct xmit_tasklet; 237 238 _workitem xmit_pipe4_reset_wi;
-1
drivers/staging/rtl8712/usb_intf.c
··· 280 280 } 281 281 if ((r8712_alloc_io_queue(padapter)) == _FAIL) 282 282 status = _FAIL; 283 - sema_init(&(padapter->dvobjpriv.usb_suspend_sema), 0); 284 283 return status; 285 284 } 286 285