staging: r8188eu: shorten and simplify calls chains
PATCH v9 10/16 staging: r8188eu: shorten and simplify calls chains
--- Preface ---
This is v10 of "shorten and simplify calls chain". The 14 (v7) + 2 (v8) patches have already been applied to staging-testing, so we have been requested to reset the numbering of the remaining patches to 01/16, while discarding from v9 the above-mentioned 16 patches (otherwise we would have submitted a series containing 32 patches, that is 1 patch less than v8 because it has been dropped by us in what we considered it unnecessary - it was about fixing a misspelled word in a comment).
The following commit message is provided as it was in v8, both for the purpose of presenting the whole picture to Maintainers, Reviewers, and to anybody else who may be interested in knowing the entire design and the evolution since v1 to the current v10.
--- Commit message ---
io_ops abstraction is useless in this driver, since there is only one ops registration. Without io_ops we can get rid of indirect calls mess and shorten the calls chain.
Shorten the calls chain of rtw_read8/16/32() down to the actual reads. For this purpose unify the three usb_read8/16/32 into the new usb_read(); make the latter parameterizable with 'size'; embed most of the code of usbctrl_vendorreq() into usb_read() and use in it the new usb_control_msg_recv() API of USB Core.
Shorten the calls chain of rtw_write8/16/32() down to the actual writes. For this purpose unify the four usb_write8/16/32/N() into the new usb_write(); make the latter parameterizable with 'size'; embed most of the code of usbctrl_vendorreq() into usb_write() and use in it the new usb_control_msg_send() API of USB Core.
The code with the modifications was thoroughly tested by Pavel Skripkin using a TP-Link TL-WN722N v2 / v3 [Realtek RTL8188EUS] and by Fabio M. De Francesco using a ASUSTek Computer, Inc. Realtek 8188EUS [USB-N10 Nano].
--- Changelog ---
v9-v10:
- 1-15:
No changes;
- 16:
Fix a bug inadvertently introduced in v8.
v8->v9 (after numbering reset in v8):
- 1-7,9,10,12:
Clean-up patches with no significant changes in code. We've applied some fixes required by Greg Kroah-Hartman:
(1) rename of an argument (intfhdl => intf), (2) explanation of why "!io_buf" test is redundant and unnecessary, (3) deletion of comments for single line 'if' statements, (4) fix of a coding style issue by removing unnecessary braces;
- 8,11:
Add more detailed motivation in support of changing the type of two variables, one in rtw_read16() and the other in rtw_write16();
- 13,14:
No significant changes in the code; just rebase on top of minor changes introduced by the patches 1-12;
- 15,16:
No changes.
v7->v8 (old numbering):
- 1-14:
Patches applied to staging-testing, so they are dropped from the current v8;
- 15-19:
Split into 19 patches. Numbering reset to 01. After this reset, 15-19/19 become 01-19/19 (so we have a total of 33 patches in this series.
v7->v8 (new numbering for the old 15-19/19):
- 1-15:
Old 15/19 and 16/19 are split into 15 patches (as it is required by Greg Kroah-Hartman) in order to make them more easily reviewable and for checking that the logic is not broken; no significant changes to the resulting code;
- 16-17:
Old 17/19 and 18/19 become 16/19 and 17/19: There are no significant changes to the code, with the sole exception of moving the acquiring of a mutex before the test for "bSurpriseRemoved" being 'true';
- 18-19:
Old 19/19 is split into new 18/19 and 19/19. The changes are split into a first patch that remove a shared buffer and a second that remove the mutex protecting the receiving (in usb_read()) and sending (in usb_write()) of the USB control messages.
v6->v7:
- 1-14:
Add Dan Carpenter's "Reviewed-by" tag. No code changes;
- 15:
Add a list of clean-up changes to the commit messages and restore an empty line inadvertently deleted in a previous version;
- 16:
Add a list of clean-up changes to the commit messages;
- 17-18:
No changes;
- 19:
Delete an unnecessary test.
v5->v6:
- 1-14:
Minimal changes to patch subjects to achieve consistent style;
- 15:
Fix a mistake in the checks of values returned by usb_control_msg();
- 16-19:
No changes.
v4->v5:
- 1-14:
No changes;
- 15-16:
Fix minor formatting issues and use "Reverse Xmas Tree" style, according to suggestions by David Laight and Dan Carpenter;
- 17-18:
Pavel Skripkin found logical errors in the checks of the values returned by usb_control_msg_{recv,send}(), so fix them; Dan Carpenter suggested to do error handling before success handling, so change the code accordingly;
- 19:
Add this patch in order to get rid of the shared buffer in usb_read() and usb_write() and remove this field from struct "dvobj_priv".
v3->v4:
- 1-14:
Split a patch into fourteen;
- 15-16:
Add these patches for clean-ups of the code that is going to be reused in 17-18/18;
- 17-18:
Make some changes according to a first review of Greg Kroah-Hartman; furthermore, remove the unnecessary while loop and a couple of if' test; handle the errors returned by usb_control_msg_recv().
v2->v3:
- 1-2:
No changes;
- 3:
Fix the version number of the patch.
v1->v2:
- 1-2:
No changes;
- 3:
Replace parameter REALTEK_USB_VENQT_READ with REALTEK_USB_VENQT_WRITE in usb_control_msg_send().
--- List of links to previous versions of the cover letters ---
v1: https://lore.kernel.org/lkml/[email protected]/
v2: https://lore.kernel.org/lkml/[email protected]/
v3: https://lore.kernel.org/lkml/[email protected]/
v4: https://lore.kernel.org/lkml/[email protected]/
v5: https://lore.kernel.org/lkml/[email protected]/
v6: https://lore.kernel.org/lkml/[email protected]/
v7: https://lore.kernel.org/lkml/[email protected]/
v8: https://lore.kernel.org/lkml/[email protected]/
v9: https://lore.kernel.org/lkml/[email protected]/
--- List of patches not yet applied, authorship, diff stats ---
Fabio M. De Francesco (14):
staging: r8188eu: clean up symbols in usbctrl_vendorreq()
staging: r8188eu: reorder declarations in usbctrl_vendorreq()
staging: r8188eu: remove unnecessary test in usbctrl_vendorreq()
staging: r8188eu: reorder comments in usbctrl_vendorreq()
staging: r8188eu: remove a comment from usbctrl_vendorreq()
staging: r8188eu: rename symbols in rtw_read*() and rtw_write*()
staging: r8188eu: remove casts from rtw_{read,write}*()
staging: r8188eu: change the type of a variable in rtw_write16()
staging: r8188eu: remove an buffer from rtw_writeN()
staging: r8188eu: remove a bitwise AND from rtw_writeN()
staging: r8188eu: change the type of a variable in rtw_read16()
staging: r8188eu: Remove a test from usbctrl_vendorreq()
staging: r8188eu: call new usb_read() from rtw_read{8,16,32}()
staging: r8188eu: call new usb_write() from rtw_write{8,16,32,N}()
Pavel Skripkin (2):
staging: r8188eu: remove shared buffer for USB requests
staging: r8188eu: remove usb_vendor_req_mutex
drivers/staging/r8188eu/hal/usb_ops_linux.c | 213 ++++++++++---------- drivers/staging/r8188eu/include/drv_types.h | 3 - drivers/staging/r8188eu/os_dep/usb_intf.c | 36 ---- 3 files changed, 107 insertions(+), 145 deletions(-)
--
2.33.0
PATCH v10 1/16 staging: r8188eu: clean up symbols in usbctrl_vendorreq()
Clean up symbol names in usbctrl_vendorreq():
pdata => data; pio_priv => io_priv; pintfhdl => intf.
--- drivers/staging/r8188eu/hal/usb_ops_linux.c | 28 ++++++++++----------- 1 file changed, 14 insertions(+), 14 deletions(-)
drivers/staging/r8188eu/hal/usb_ops_linux.c +14 -14
@@ -8,14 +8,14 @@#include "../include/recv_osdep.h" #include "../include/rtl8188e_hal.h" -static int usbctrl_vendorreq (struct intf_hdl *pintfhdl,u16 value,void *pdata,u16 len,u8 requesttype) +static int usbctrl_vendorreq (struct intf_hdl *intf,u16 value,void *data,u16 len,u8 requesttype) { -struct adapter *adapt = pintfhdl->padapter; -struct dvobj_priv *dvobjpriv =adapter_to_dvobj (adapt); +struct adapter *adapt = intf->padapter; +struct dvobj_priv *dvobjpriv =adapter_to_dvobj (adapt);struct usb_device *udev = dvobjpriv->pusbdev;unsigned int pipe;int status =0 ; -u8 *pIo_buf; +u8 *io_buf;int vendorreq_times =0 ;if ((adapt->bSurpriseRemoved) || (adapt->pwrctrlpriv.pnp_bstop_trx)) {
@@ -32,10 +32,10 @@ static int usbctrl_vendorreq(struct intf_hdl *pintfhdl, u16 value, void *pdata,mutex_lock (&dvobjpriv->usb_vendor_req_mutex);/* Acquire IO memory for vendorreq */ - pIo_buf = dvobjpriv->usb_vendor_req_buf; + io_buf = dvobjpriv->usb_vendor_req_buf; -if (!pIo_buf) { -DBG_88E ("[%s] pIo_buf == NULL\n" , __func__); +if (!io_buf) { +DBG_88E ("[%s] io_buf == NULL\n" , __func__); status = -ENOMEM ; goto release_mutex; }
@@ -47,22 +47,22 @@ static int usbctrl_vendorreq(struct intf_hdl *pintfhdl, u16 value, void *pdata,while (++vendorreq_times <=MAX_USBCTRL_VENDORREQ_TIMES ) {if (requesttype ==REALTEK_USB_VENQT_READ ) -memset (pIo_buf,0 , len); +memset (io_buf,0 , len);else -memcpy (pIo_buf, pdata, len); +memcpy (io_buf, data, len); status =usb_control_msg (udev, pipe,REALTEK_USB_VENQT_CMD_REQ , requesttype, value,REALTEK_USB_VENQT_CMD_IDX , - pIo_buf, len,RTW_USB_CONTROL_MSG_TIMEOUT ); + io_buf, len,RTW_USB_CONTROL_MSG_TIMEOUT );if (status == len) {/* Success this control transfer. */ rtw_reset_continual_urb_error (dvobjpriv);if (requesttype ==REALTEK_USB_VENQT_READ ) -memcpy (pdata, pIo_buf, len); +memcpy (data, io_buf, len); }else {/* error cases */ DBG_88E ("reg 0x%x, usb %s %u fail, status:%d value=0x%x, vendorreq_times:%d\n" , value, (requesttype ==REALTEK_USB_VENQT_READ ) ?"read" :"write" , - len, status, *(u32 *)pdata, vendorreq_times); + len, status, *(u32 *)data, vendorreq_times);if (status <0 ) {if (status == -ESHUTDOWN || status == -ENODEV ) {
@@ -74,8 +74,8 @@ static int usbctrl_vendorreq(struct intf_hdl *pintfhdl, u16 value, void *pdata, }else {/* status != len && status >= 0 */ if (status >0 ) {if (requesttype ==REALTEK_USB_VENQT_READ ) { -/* For Control read transfer, we have to copy the read data from pIo_buf to pdata. */ -memcpy (pdata, pIo_buf, len); +/* For Control read transfer, we have to copy the read data from io_buf to data. */ +memcpy (data, io_buf, len); } } }
Signature · 1 line
2.33.0
PATCH v10 2/16 staging: r8188eu: reorder declarations in usbctrl_vendorreq()
In reply to Fabio M. De FrancescoReorder variables declarations according to the "Reverse Xmas Tree" style.
--- drivers/staging/r8188eu/hal/usb_ops_linux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/r8188eu/hal/usb_ops_linux.c +1 -1
@@ -13,10 +13,10 @@ static int usbctrl_vendorreq(struct intf_hdl *intf, u16 value, void *data, u16 lstruct adapter *adapt = intf->padapter;struct dvobj_priv *dvobjpriv =adapter_to_dvobj (adapt);struct usb_device *udev = dvobjpriv->pusbdev; +int vendorreq_times =0 ;unsigned int pipe;int status =0 ;u8 *io_buf; -int vendorreq_times =0 ;if ((adapt->bSurpriseRemoved) || (adapt->pwrctrlpriv.pnp_bstop_trx)) { status = -EPERM ;
Signature · 1 line
2.33.0
PATCH v10 3/16 staging: r8188eu: remove test in usbctrl_vendorreq()
In reply to Fabio M. De FrancescoRemove unnecessary test for "!io_buf" in usbctrl_vendorreq(). This test is not necessary because io_buf has been assigned with the address of a region of dynamically allocated memory (dvobj->usb_alloc_vendor_req_buf) by rtw_init_intf_priv() in os_dep/usb_intf.c.
--- drivers/staging/r8188eu/hal/usb_ops_linux.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/staging/r8188eu/hal/usb_ops_linux.c +1 -7
@@ -34,12 +34,6 @@ static int usbctrl_vendorreq(struct intf_hdl *intf, u16 value, void *data, u16 l/* Acquire IO memory for vendorreq */ io_buf = dvobjpriv->usb_vendor_req_buf; -if (!io_buf) { -DBG_88E ("[%s] io_buf == NULL\n" , __func__); - status = -ENOMEM ; - goto release_mutex; - } -if (requesttype ==REALTEK_USB_VENQT_READ ) pipe =usb_rcvctrlpipe (udev,0 );/* read_in */ else
@@ -91,7 +85,7 @@ static int usbctrl_vendorreq(struct intf_hdl *intf, u16 value, void *data, u16 lif ((value >=FW_8188E_START_ADDRESS && value <=FW_8188E_END_ADDRESS ) || status == len)break ; } -release_mutex: +mutex_unlock (&dvobjpriv->usb_vendor_req_mutex); exit:return status;
Signature · 1 line
2.33.0
PATCH v10 4/16 staging: r8188eu: reorder comments in usbctrl_vendorreq()
In reply to Fabio M. De FrancescoReorder comments in usbctrl_vendorreq() to follow Linux coding style. Delete two of them because they are "obvious".
--- drivers/staging/r8188eu/hal/usb_ops_linux.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/staging/r8188eu/hal/usb_ops_linux.c +8 -5
@@ -35,9 +35,9 @@ static int usbctrl_vendorreq(struct intf_hdl *intf, u16 value, void *data, u16 l io_buf = dvobjpriv->usb_vendor_req_buf;if (requesttype ==REALTEK_USB_VENQT_READ ) - pipe =usb_rcvctrlpipe (udev,0 );/* read_in */ + pipe =usb_rcvctrlpipe (udev,0 );else - pipe =usb_sndctrlpipe (udev,0 );/* write_out */ + pipe =usb_sndctrlpipe (udev,0 );while (++vendorreq_times <=MAX_USBCTRL_VENDORREQ_TIMES ) {if (requesttype ==REALTEK_USB_VENQT_READ )
@@ -49,11 +49,13 @@ static int usbctrl_vendorreq(struct intf_hdl *intf, u16 value, void *data, u16 l requesttype, value,REALTEK_USB_VENQT_CMD_IDX , io_buf, len, RTW_USB_CONTROL_MSG_TIMEOUT); -if (status == len) {/* Success this control transfer. */ +if (status == len) { +/* success */ rtw_reset_continual_urb_error (dvobjpriv);if (requesttype ==REALTEK_USB_VENQT_READ )memcpy (data, io_buf, len); - }else {/* error cases */ + }else { +/* error cases */ DBG_88E ("reg 0x%x, usb %s %u fail, status:%d value=0x%x, vendorreq_times:%d\n" , value, (requesttype ==REALTEK_USB_VENQT_READ ) ?"read" :"write" , len, status, *(u32 *)data, vendorreq_times);
@@ -65,7 +67,8 @@ static int usbctrl_vendorreq(struct intf_hdl *intf, u16 value, void *data, u16 lstruct hal_data_8188e *haldata =GET_HAL_DATA (adapt); haldata->srestpriv.wifi_error_status =USB_VEN_REQ_CMD_FAIL ; } - }else {/* status != len && status >= 0 */ + }else { +/* status != len && status >= 0 */ if (status >0 ) {if (requesttype ==REALTEK_USB_VENQT_READ ) {/* For Control read transfer, we have to copy the read data from io_buf to data. */
Signature · 1 line
2.33.0
PATCH v10 5/16 staging: r8188eu: remove a comment from usbctrl_vendorreq()
In reply to Fabio M. De FrancescoRemove an unnecessary comment from usbctrl_vendorreq().
--- drivers/staging/r8188eu/hal/usb_ops_linux.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/staging/r8188eu/hal/usb_ops_linux.c +1 -3
@@ -70,10 +70,8 @@ static int usbctrl_vendorreq(struct intf_hdl *intf, u16 value, void *data, u16 l }else {/* status != len && status >= 0 */ if (status >0 ) { -if (requesttype ==REALTEK_USB_VENQT_READ ) { -/* For Control read transfer, we have to copy the read data from io_buf to data. */ +if (requesttype ==REALTEK_USB_VENQT_READ )memcpy (data, io_buf, len); - } } }
Signature · 1 line
2.33.0
PATCH v10 6/16 staging: r8188eu: rename symbols in rtw_read*() and rtw_write*()
In reply to Fabio M. De FrancescoRename variables in rtw_read{8.16.32}() and in rtw_write{8,16,32,N}() because of unnecessary 'p' (that probably stand for "pointer to") and 'w' (that probably stands for "word"):
pio_priv => io_priv; pintfhdl => intf; wvalue => value.
--- drivers/staging/r8188eu/hal/usb_ops_linux.c | 60 ++++++++++----------- 1 file changed, 30 insertions(+), 30 deletions(-)
drivers/staging/r8188eu/hal/usb_ops_linux.c +30 -30
@@ -94,91 +94,91 @@ static int usbctrl_vendorreq(struct intf_hdl *intf, u16 value, void *data, u16 lu8 rtw_read8 (struct adapter *adapter,u32 addr) { -struct io_priv *pio_priv = &adapter->iopriv; -struct intf_hdl *pintfhdl = &pio_priv->intf; -u16 wvalue = (u16)(addr &0x0000ffff ); +struct io_priv *io_priv = &adapter->iopriv; +struct intf_hdl *intf = &io_priv->intf; +u16 value = (u16)(addr &0x0000ffff );u8 data; -usbctrl_vendorreq (pintfhdl, wvalue, &data,1 ,REALTEK_USB_VENQT_READ ); +usbctrl_vendorreq (intf, value, &data,1 ,REALTEK_USB_VENQT_READ );return data; }u16 rtw_read16 (struct adapter *adapter,u32 addr) { -struct io_priv *pio_priv = &adapter->iopriv; -struct intf_hdl *pintfhdl = &pio_priv->intf; -u16 wvalue = (u16)(addr &0x0000ffff ); +struct io_priv *io_priv = &adapter->iopriv; +struct intf_hdl *intf = &io_priv->intf; +u16 value = (u16)(addr &0x0000ffff );__le32 data; -usbctrl_vendorreq (pintfhdl, wvalue, &data,2 ,REALTEK_USB_VENQT_READ ); +usbctrl_vendorreq (intf, value, &data,2 ,REALTEK_USB_VENQT_READ );return (u16)(le32_to_cpu (data) &0xffff ); }u32 rtw_read32 (struct adapter *adapter,u32 addr) { -struct io_priv *pio_priv = &adapter->iopriv; -struct intf_hdl *pintfhdl = &pio_priv->intf; -u16 wvalue = (u16)(addr &0x0000ffff ); +struct io_priv *io_priv = &adapter->iopriv; +struct intf_hdl *intf = &io_priv->intf; +u16 value = (u16)(addr &0x0000ffff );__le32 data; -usbctrl_vendorreq (pintfhdl, wvalue, &data,4 ,REALTEK_USB_VENQT_READ ); +usbctrl_vendorreq (intf, value, &data,4 ,REALTEK_USB_VENQT_READ );return le32_to_cpu (data); }int rtw_write8 (struct adapter *adapter,u32 addr,u8 val) { -struct io_priv *pio_priv = &adapter->iopriv; -struct intf_hdl *pintfhdl = &pio_priv->intf; -u16 wvalue = (u16)(addr &0x0000ffff ); +struct io_priv *io_priv = &adapter->iopriv; +struct intf_hdl *intf = &io_priv->intf; +u16 value = (u16)(addr &0x0000ffff );int ret; - ret =usbctrl_vendorreq (pintfhdl, wvalue, &val,1 ,REALTEK_USB_VENQT_WRITE ); + ret =usbctrl_vendorreq (intf, value, &val,1 ,REALTEK_USB_VENQT_WRITE );return RTW_STATUS_CODE (ret); }int rtw_write16 (struct adapter *adapter,u32 addr,u16 val) { -struct io_priv *pio_priv = &adapter->iopriv; -struct intf_hdl *pintfhdl = &pio_priv->intf; -u16 wvalue = (u16)(addr &0x0000ffff ); +struct io_priv *io_priv = &adapter->iopriv; +struct intf_hdl *intf = &io_priv->intf; +u16 value = (u16)(addr &0x0000ffff );__le32 data =cpu_to_le32 (val &0x0000ffff );int ret; - ret =usbctrl_vendorreq (pintfhdl, wvalue, &data,2 ,REALTEK_USB_VENQT_WRITE ); + ret =usbctrl_vendorreq (intf, value, &data,2 ,REALTEK_USB_VENQT_WRITE );return RTW_STATUS_CODE (ret); }int rtw_write32 (struct adapter *adapter,u32 addr,u32 val) { -struct io_priv *pio_priv = &adapter->iopriv; -struct intf_hdl *pintfhdl = &pio_priv->intf; -u16 wvalue = (u16)(addr &0x0000ffff ); +struct io_priv *io_priv = &adapter->iopriv; +struct intf_hdl *intf = &io_priv->intf; +u16 value = (u16)(addr &0x0000ffff );__le32 data =cpu_to_le32 (val);int ret; - ret =usbctrl_vendorreq (pintfhdl, wvalue, &data,4 ,REALTEK_USB_VENQT_WRITE ); + ret =usbctrl_vendorreq (intf, value, &data,4 ,REALTEK_USB_VENQT_WRITE );return RTW_STATUS_CODE (ret); } -int rtw_writeN (struct adapter *adapter,u32 addr,u32 length,u8 *pdata) +int rtw_writeN (struct adapter *adapter,u32 addr,u32 length,u8 *data) { -struct io_priv *pio_priv = &adapter->iopriv; -struct intf_hdl *pintfhdl = &pio_priv->intf; -u16 wvalue = (u16)(addr &0x0000ffff ); +struct io_priv *io_priv = &adapter->iopriv; +struct intf_hdl *intf = &io_priv->intf; +u16 value = (u16)(addr &0x0000ffff );u8 buf[VENDOR_CMD_MAX_DATA_LEN ] = {0 };int ret;if (length >VENDOR_CMD_MAX_DATA_LEN )return _FAIL; -memcpy (buf, pdata, length); - ret =usbctrl_vendorreq (pintfhdl, wvalue, buf, (length &0xffff ),REALTEK_USB_VENQT_WRITE ); +memcpy (buf, data, length); + ret =usbctrl_vendorreq (intf, value, buf, (length &0xffff ),REALTEK_USB_VENQT_WRITE );return RTW_STATUS_CODE (ret); }
Signature · 1 line
2.33.0
PATCH v10 7/16 staging: r8188eu: remove casts from rtw_{read,write}*()
In reply to Fabio M. De FrancescoRemove unnecessary casts from rtw_read{8,16,32}() and from rtw_write{8,16,32,N}().
--- drivers/staging/r8188eu/hal/usb_ops_linux.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
drivers/staging/r8188eu/hal/usb_ops_linux.c +7 -7
@@ -96,7 +96,7 @@ u8 rtw_read8(struct adapter *adapter, u32 addr) {struct io_priv *io_priv = &adapter->iopriv;struct intf_hdl *intf = &io_priv->intf; -u16 value = (u16)(addr &0x0000ffff ); +u16 value = addr &0xffff ;u8 data;usbctrl_vendorreq (intf, value, &data,1 ,REALTEK_USB_VENQT_READ );
@@ -108,7 +108,7 @@ u16 rtw_read16(struct adapter *adapter, u32 addr) {struct io_priv *io_priv = &adapter->iopriv;struct intf_hdl *intf = &io_priv->intf; -u16 value = (u16)(addr &0x0000ffff ); +u16 value = addr &0xffff ;__le32 data;usbctrl_vendorreq (intf, value, &data,2 ,REALTEK_USB_VENQT_READ );
@@ -120,7 +120,7 @@ u32 rtw_read32(struct adapter *adapter, u32 addr) {struct io_priv *io_priv = &adapter->iopriv;struct intf_hdl *intf = &io_priv->intf; -u16 value = (u16)(addr &0x0000ffff ); +u16 value = addr &0xffff ;__le32 data;usbctrl_vendorreq (intf, value, &data,4 ,REALTEK_USB_VENQT_READ );
@@ -132,7 +132,7 @@ int rtw_write8(struct adapter *adapter, u32 addr, u8 val) {struct io_priv *io_priv = &adapter->iopriv;struct intf_hdl *intf = &io_priv->intf; -u16 value = (u16)(addr &0x0000ffff ); +u16 value = addr &0xffff ;int ret; ret =usbctrl_vendorreq (intf, value, &val,1 ,REALTEK_USB_VENQT_WRITE );
@@ -144,7 +144,7 @@ int rtw_write16(struct adapter *adapter, u32 addr, u16 val) {struct io_priv *io_priv = &adapter->iopriv;struct intf_hdl *intf = &io_priv->intf; -u16 value = (u16)(addr &0x0000ffff ); +u16 value = addr &0xffff ;__le32 data =cpu_to_le32 (val &0x0000ffff );int ret;
@@ -157,7 +157,7 @@ int rtw_write32(struct adapter *adapter, u32 addr, u32 val) {struct io_priv *io_priv = &adapter->iopriv;struct intf_hdl *intf = &io_priv->intf; -u16 value = (u16)(addr &0x0000ffff ); +u16 value = addr &0xffff ;__le32 data =cpu_to_le32 (val);int ret;
@@ -170,7 +170,7 @@ int rtw_writeN(struct adapter *adapter, u32 addr, u32 length, u8 *data) {struct io_priv *io_priv = &adapter->iopriv;struct intf_hdl *intf = &io_priv->intf; -u16 value = (u16)(addr &0x0000ffff ); +u16 value = addr &0xffff ;u8 buf[VENDOR_CMD_MAX_DATA_LEN ] = {0 };int ret;
Signature · 1 line
2.33.0
PATCH v10 8/16 staging: r8188eu: change the type of a variable in rtw_write16()
In reply to Fabio M. De FrancescoChange the type of "data" from __le32 to __le16 in rtw_write16(). The argument "val", which is u16, after being conditionally swapped to little endian, is assigned to "data"; therefore, __le16 is the most suitable type for "data". Remove the bitwise AND of "val" with 0xffff because it is redundant. Use cpu_to_le16() because "data" is __le16.
--- drivers/staging/r8188eu/hal/usb_ops_linux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/r8188eu/hal/usb_ops_linux.c +1 -1
@@ -145,7 +145,7 @@ int rtw_write16(struct adapter *adapter, u32 addr, u16 val)struct io_priv *io_priv = &adapter->iopriv;struct intf_hdl *intf = &io_priv->intf;u16 value = addr &0xffff ; -__le32 data =cpu_to_le32 (val &0x0000ffff ); +__le16 data =cpu_to_le16 (val);int ret; ret =usbctrl_vendorreq (intf, value, &data,2 ,REALTEK_USB_VENQT_WRITE );
Signature · 1 line
2.33.0
PATCH v10 9/16 staging: r8188eu: remove a buffer from rtw_writeN()
In reply to Fabio M. De FrancescoRemove the unnecessary buffer "u8 buf[VENDOR_CMD_MAX_DATA_LEN]" and pass directly "data" to usbctrl_vendorreq().
--- drivers/staging/r8188eu/hal/usb_ops_linux.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/staging/r8188eu/hal/usb_ops_linux.c +1 -3
@@ -171,14 +171,12 @@ int rtw_writeN(struct adapter *adapter, u32 addr, u32 length, u8 *data)struct io_priv *io_priv = &adapter->iopriv;struct intf_hdl *intf = &io_priv->intf;u16 value = addr &0xffff ; -u8 buf[VENDOR_CMD_MAX_DATA_LEN ] = {0 };int ret;if (length >VENDOR_CMD_MAX_DATA_LEN )return _FAIL; -memcpy (buf, data, length); - ret =usbctrl_vendorreq (intf, value, buf, (length &0xffff ),REALTEK_USB_VENQT_WRITE ); + ret =usbctrl_vendorreq (intf, value, data, (length &0xffff ),REALTEK_USB_VENQT_WRITE );return RTW_STATUS_CODE (ret); }
Signature · 1 line
2.33.0
PATCH v10 10/16 staging: r8188eu: remove a bitwise AND from rtw_writeN()
In reply to Fabio M. De FrancescoRemove an unnecessary bitwise AND because "length" can never be greater than 0xffff since VENDOR_CMD_MAX_DATA_LEN is defined as '254'.
--- drivers/staging/r8188eu/hal/usb_ops_linux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/staging/r8188eu/hal/usb_ops_linux.c +1 -1
@@ -176,7 +176,7 @@ int rtw_writeN(struct adapter *adapter, u32 addr, u32 length, u8 *data)if (length >VENDOR_CMD_MAX_DATA_LEN )return _FAIL; - ret =usbctrl_vendorreq (intf, value, data, (length &0xffff ),REALTEK_USB_VENQT_WRITE ); + ret =usbctrl_vendorreq (intf, value, data, length,REALTEK_USB_VENQT_WRITE );return RTW_STATUS_CODE (ret); }
Signature · 1 line
2.33.0
PATCH v10 11/16 staging: r8188eu: change the type of a variable in rtw_read16()
In reply to Fabio M. De FrancescoChange the type of "data" from __le32 to __le16. The size of the data that usbctrl_vendorreq() will read is two bytes in little endian order, so the most suitable type is __le16.
With the old code, since the two most significant bytes of data are not initialized, KMSan can likely detect the reading of uninitialized data, so this change can prevent the checker from complaining.
--- drivers/staging/r8188eu/hal/usb_ops_linux.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/staging/r8188eu/hal/usb_ops_linux.c +2 -2
@@ -109,11 +109,11 @@ u16 rtw_read16(struct adapter *adapter, u32 addr)struct io_priv *io_priv = &adapter->iopriv;struct intf_hdl *intf = &io_priv->intf;u16 value = addr &0xffff ; -__le32 data; +__le16 data;usbctrl_vendorreq (intf, value, &data,2 ,REALTEK_USB_VENQT_READ ); -return (u16)(le32_to_cpu (data) &0xffff ); +return le16_to_cpu (data); }u32 rtw_read32 (struct adapter *adapter,u32 addr)
Signature · 1 line
2.33.0
PATCH v10 12/16 staging: r8188eu: Remove a test from usbctrl_vendorreq()
In reply to Fabio M. De FrancescoRemove an unnecessary 'if' test from usbctrl_vendorreq() because "length" is never greater than MAX_VENDOR_REQ_CMD_SIZE.
--- drivers/staging/r8188eu/hal/usb_ops_linux.c | 6 ------ 1 file changed, 6 deletions(-)
drivers/staging/r8188eu/hal/usb_ops_linux.c +0 -6
@@ -23,12 +23,6 @@ static int usbctrl_vendorreq(struct intf_hdl *intf, u16 value, void *data, u16 l goto exit; } -if (len >MAX_VENDOR_REQ_CMD_SIZE ) { -DBG_88E ("[%s] Buffer len error ,vendor request failed\n" , __func__); - status = -EINVAL ; - goto exit; - } -mutex_lock (&dvobjpriv->usb_vendor_req_mutex);/* Acquire IO memory for vendorreq */
Signature · 1 line
2.33.0
PATCH v10 13/16 staging: r8188eu: call new usb_read() from rtw_read{8,16,32}()
In reply to Fabio M. De FrancescoCreate and call new usb_read() instead of usbctrl_vendorreq() from inside rtw_read{8,16,32}().
In old code, rtw_read{8,16,32}() called usbctrl_vendorreq() which in turn uses usb_control_msg() from within a "while" loop to build a control URB, send it off and wait for completion. usbctrl_vendorreq() was used for both receiving and sending messages, depending on the "requesttype" argument which was passed by callers.
Compared to usbctrl_vendorreq(), which managed both reads and writes from and to the USB endpoint, the new usb_read() manages only reads. For this purpose it uses the newer USB Core usb_control_msg_recv() API. The latter is preferred according both to a suggestion by Greg Kroah-Hartman and also to its actual design.
Two noteworthy features of usb_control_msg_recv() are that (1) the data pointer can be made to a reference on the stack because it does not have the restriction that usb_control_msg() has where the data pointer must be to dynamically allocated memory, and that (2) the whole message must be properly received from the device in order for this function to be successfuli (if a device returns less than the expected amount of data, then the function will fail).
usbctrl_vendorreq() uses a "while" loop that we considered unnecessary so that it is not in the new usb_read(). Furthermore, the latter has no redundant checking, less obvious comments, and it manages errors before success cases. All in all, usb_read() is simpler than usbctrl_vendorreq() and uses less lines of code.
--- drivers/staging/r8188eu/hal/usb_ops_linux.c | 59 +++++++++++++++++++-- 1 file changed, 56 insertions(+), 3 deletions(-)
drivers/staging/r8188eu/hal/usb_ops_linux.c +56 -3
@@ -86,6 +86,59 @@ static int usbctrl_vendorreq(struct intf_hdl *intf, u16 value, void *data, u16 lreturn status; } +static int usb_read (struct intf_hdl *intf,u16 value,void *data,u8 size) +{ +struct adapter *adapt = intf->padapter; +struct dvobj_priv *dvobjpriv =adapter_to_dvobj (adapt); +struct usb_device *udev = dvobjpriv->pusbdev; +int status; +u8 *io_buf;/* Pointer to I/O buffer */ + +mutex_lock (&dvobjpriv->usb_vendor_req_mutex); + +if (adapt->bSurpriseRemoved || adapt->pwrctrlpriv.pnp_bstop_trx) +return -EPERM ; + + io_buf = dvobjpriv->usb_vendor_req_buf; + + status =usb_control_msg_recv (udev,0 ,REALTEK_USB_VENQT_CMD_REQ , +REALTEK_USB_VENQT_READ , value, +REALTEK_USB_VENQT_CMD_IDX , io_buf, + size,RTW_USB_CONTROL_MSG_TIMEOUT , +GFP_KERNEL ); + +if (status == -ESHUTDOWN || + status == -ENODEV || + status == -ENOENT ) { +/* +* device or controller has been disabled due to +* some problem that could not be worked around, +* device or bus doesn’t exist, endpoint does not +* exist or is not enabled. +*/ + adapt->bSurpriseRemoved = true; + goto mutex_unlock; + } + +if (status <0 ) { +GET_HAL_DATA (adapt)->srestpriv.wifi_error_status = +USB_VEN_REQ_CMD_FAIL ; + +if (rtw_inc_and_chk_continual_urb_error (dvobjpriv)) + adapt->bSurpriseRemoved = true; + + goto mutex_unlock; + } + +rtw_reset_continual_urb_error (dvobjpriv); +memcpy (data, io_buf, size); + +mutex_unlock: +mutex_unlock (&dvobjpriv->usb_vendor_req_mutex); + +return status; +} +u8 rtw_read8 (struct adapter *adapter,u32 addr) {struct io_priv *io_priv = &adapter->iopriv;
@@ -93,7 +146,7 @@ u8 rtw_read8(struct adapter *adapter, u32 addr)u16 value = addr &0xffff ;u8 data; -usbctrl_vendorreq (intf, value, &data,1 ,REALTEK_USB_VENQT_READ ); +usb_read (intf, value, &data,1 );return data; }
@@ -105,7 +158,7 @@ u16 rtw_read16(struct adapter *adapter, u32 addr)u16 value = addr &0xffff ;__le16 data; -usbctrl_vendorreq (intf, value, &data,2 ,REALTEK_USB_VENQT_READ ); +usb_read (intf, value, &data,2 );return le16_to_cpu (data); }
@@ -117,7 +170,7 @@ u32 rtw_read32(struct adapter *adapter, u32 addr)u16 value = addr &0xffff ;__le32 data; -usbctrl_vendorreq (intf, value, &data,4 ,REALTEK_USB_VENQT_READ ); +usb_read (intf, value, &data,4 );return le32_to_cpu (data); }
Signature · 1 line
2.33.0
PATCH v10 14/16 staging: r8188eu: call new usb_write() from rtw_write{8,16,32,N}()
In reply to Fabio M. De FrancescoCreate and call new usb_write() instead of usbctrl_vendorreq() from inside rtw_write{8,16,32,N}().
In old code, rtw_write{8,16,32,N}() called usbctrl_vendorreq() which in turn uses usb_control_msg() from within a "while" loop to build a control URB, send it off and wait for completion. usbctrl_vendorreq() was used for both receiving and sending messages, depending on the "requesttype" argument which is passed by callers.
Compared to usbctrl_vendorreq(), which manages both reads and writes from and to the USB endpoint, the new usb_write() manages only writes. For this purpose it uses the newer USB Core usb_control_msg_send() API. The latter is preferred according both to suggestions by Greg Kroah-Hartman and also to its actual design.
A noteworthy feature of usb_control_msg_send() is that the data pointer can be made to a reference on the stack because it does not have the restriction that usb_control_msg() has where the data pointer must be to dynamically allocated memory.
usbctrl_vendorreq() used a "while" loop that we considered unnecessary so that it is not in the new usb_write(). Furthermore, the latter has no redundant checking, less obvious comments, no debug prints, and it manages errors before success case. All in all, usb_write() is simpler than usbctrl_vendorreq() and uses less lines of code.
--- drivers/staging/r8188eu/hal/usb_ops_linux.c | 108 ++++++++------------ 1 file changed, 43 insertions(+), 65 deletions(-)
drivers/staging/r8188eu/hal/usb_ops_linux.c +43 -65
@@ -8,85 +8,63 @@#include "../include/recv_osdep.h" #include "../include/rtl8188e_hal.h" -static int usbctrl_vendorreq (struct intf_hdl *intf,u16 value,void *data,u16 len,u8 requesttype) +static int usb_read (struct intf_hdl *intf,u16 value,void *data,u8 size) {struct adapter *adapt = intf->padapter;struct dvobj_priv *dvobjpriv =adapter_to_dvobj (adapt);struct usb_device *udev = dvobjpriv->pusbdev; -int vendorreq_times =0 ; -unsigned int pipe; -int status =0 ; -u8 *io_buf; +int status; +u8 *io_buf;/* Pointer to I/O buffer */ -if ((adapt->bSurpriseRemoved) || (adapt->pwrctrlpriv.pnp_bstop_trx)) { +mutex_lock (&dvobjpriv->usb_vendor_req_mutex); + +if (adapt->bSurpriseRemoved || adapt->pwrctrlpriv.pnp_bstop_trx) { status = -EPERM ; - goto exit; + goto mutex_unlock; } -mutex_lock (&dvobjpriv->usb_vendor_req_mutex); -/* Acquire IO memory for vendorreq */ io_buf = dvobjpriv->usb_vendor_req_buf; -if (requesttype ==REALTEK_USB_VENQT_READ ) - pipe =usb_rcvctrlpipe (udev,0 ); -else - pipe =usb_sndctrlpipe (udev,0 ); - -while (++vendorreq_times <=MAX_USBCTRL_VENDORREQ_TIMES ) { -if (requesttype ==REALTEK_USB_VENQT_READ ) -memset (io_buf,0 , len); -else -memcpy (io_buf, data, len); - - status =usb_control_msg (udev, pipe,REALTEK_USB_VENQT_CMD_REQ , - requesttype, value,REALTEK_USB_VENQT_CMD_IDX , - io_buf, len,RTW_USB_CONTROL_MSG_TIMEOUT ); + status =usb_control_msg_recv (udev,0 ,REALTEK_USB_VENQT_CMD_REQ , +REALTEK_USB_VENQT_READ , value, +REALTEK_USB_VENQT_CMD_IDX , io_buf, + size,RTW_USB_CONTROL_MSG_TIMEOUT , +GFP_KERNEL ); -if (status == len) { -/* success */ -rtw_reset_continual_urb_error (dvobjpriv); -if (requesttype ==REALTEK_USB_VENQT_READ ) -memcpy (data, io_buf, len); - }else { -/* error cases */ -DBG_88E ("reg 0x%x, usb %s %u fail, status:%d value=0x%x, vendorreq_times:%d\n" , - value, (requesttype ==REALTEK_USB_VENQT_READ ) ?"read" :"write" , - len, status, *(u32 *)data, vendorreq_times); - -if (status <0 ) { -if (status == -ESHUTDOWN || status == -ENODEV ) { - adapt->bSurpriseRemoved = true; - }else { -struct hal_data_8188e *haldata =GET_HAL_DATA (adapt); - haldata->srestpriv.wifi_error_status =USB_VEN_REQ_CMD_FAIL ; - } - }else { -/* status != len && status >= 0 */ -if (status >0 ) { -if (requesttype ==REALTEK_USB_VENQT_READ ) -memcpy (data, io_buf, len); - } - } +if (status == -ESHUTDOWN || + status == -ENODEV || + status == -ENOENT ) { +/* +* device or controller has been disabled due to +* some problem that could not be worked around, +* device or bus doesn’t exist, endpoint does not +* exist or is not enabled. +*/ + adapt->bSurpriseRemoved = true; + goto mutex_unlock; + } -if (rtw_inc_and_chk_continual_urb_error (dvobjpriv)) { - adapt->bSurpriseRemoved = true; -break ; - } +if (status <0 ) { +GET_HAL_DATA (adapt)->srestpriv.wifi_error_status = +USB_VEN_REQ_CMD_FAIL ; - } +if (rtw_inc_and_chk_continual_urb_error (dvobjpriv)) + adapt->bSurpriseRemoved = true; -/* firmware download is checksumed, don't retry */ -if ((value >=FW_8188E_START_ADDRESS && value <=FW_8188E_END_ADDRESS ) || status == len) -break ; + goto mutex_unlock; } +rtw_reset_continual_urb_error (dvobjpriv); +memcpy (data, io_buf, size); + +mutex_unlock:mutex_unlock (&dvobjpriv->usb_vendor_req_mutex); -exit: +return status; } -static int usb_read (struct intf_hdl *intf,u16 value,void *data,u8 size) +static int usb_write (struct intf_hdl *intf,u16 value,void *data,u8 size) {struct adapter *adapt = intf->padapter;struct dvobj_priv *dvobjpriv =adapter_to_dvobj (adapt);
@@ -101,8 +79,9 @@ static int usb_read(struct intf_hdl *intf, u16 value, void *data, u8 size) io_buf = dvobjpriv->usb_vendor_req_buf; - status =usb_control_msg_recv (udev,0 ,REALTEK_USB_VENQT_CMD_REQ , -REALTEK_USB_VENQT_READ , value, +memcpy (io_buf, data, size); + status =usb_control_msg_send (udev,0 ,REALTEK_USB_VENQT_CMD_REQ , +REALTEK_USB_VENQT_WRITE , value,REALTEK_USB_VENQT_CMD_IDX , io_buf, size,RTW_USB_CONTROL_MSG_TIMEOUT ,GFP_KERNEL );
@@ -131,7 +110,6 @@ static int usb_read(struct intf_hdl *intf, u16 value, void *data, u8 size) }rtw_reset_continual_urb_error (dvobjpriv); -memcpy (data, io_buf, size); mutex_unlock:mutex_unlock (&dvobjpriv->usb_vendor_req_mutex);
@@ -182,7 +160,7 @@ int rtw_write8(struct adapter *adapter, u32 addr, u8 val)u16 value = addr &0xffff ;int ret; - ret =usbctrl_vendorreq (intf, value, &val,1 ,REALTEK_USB_VENQT_WRITE ); + ret =usb_write (intf, value, &val,1 );return RTW_STATUS_CODE (ret); }
@@ -195,7 +173,7 @@ int rtw_write16(struct adapter *adapter, u32 addr, u16 val)__le16 data =cpu_to_le16 (val);int ret; - ret =usbctrl_vendorreq (intf, value, &data,2 ,REALTEK_USB_VENQT_WRITE ); + ret =usb_write (intf, value, &data,2 );return RTW_STATUS_CODE (ret); }
@@ -208,7 +186,7 @@ int rtw_write32(struct adapter *adapter, u32 addr, u32 val)__le32 data =cpu_to_le32 (val);int ret; - ret =usbctrl_vendorreq (intf, value, &data,4 ,REALTEK_USB_VENQT_WRITE ); + ret =usb_write (intf, value, &data,4 );return RTW_STATUS_CODE (ret); }
@@ -223,7 +201,7 @@ int rtw_writeN(struct adapter *adapter, u32 addr, u32 length, u8 *data)if (length >VENDOR_CMD_MAX_DATA_LEN )return _FAIL; - ret =usbctrl_vendorreq (intf, value, data, length,REALTEK_USB_VENQT_WRITE ); + ret =usb_write (intf, value, data, length);return RTW_STATUS_CODE (ret); }
Signature · 1 line
2.33.0
PATCH v10 15/16 staging: r8188eu: remove shared buffer for USB requests
In reply to Fabio M. De FrancescoFrom: Pavel Skripkin <[email protected]>
Remove the shared buffer for USB requests because it is not necessary and use a local on stack variable since the new Core USB API does not have the constraints of usb_control_msg().
--- drivers/staging/r8188eu/hal/usb_ops_linux.c | 15 ++++++--------- drivers/staging/r8188eu/include/drv_types.h | 3 --- drivers/staging/r8188eu/os_dep/usb_intf.c | 14 +------------- 3 files changed, 7 insertions(+), 25 deletions(-)
drivers/staging/r8188eu/hal/usb_ops_linux.c +6 -9
@@ -14,7 +14,7 @@ static int usb_read(struct intf_hdl *intf, u16 value, void *data, u8 size)struct dvobj_priv *dvobjpriv =adapter_to_dvobj (adapt);struct usb_device *udev = dvobjpriv->pusbdev;int status; -u8 *io_buf;/* Pointer to I/O buffer */ +u8 io_buf[4 ];mutex_lock (&dvobjpriv->usb_vendor_req_mutex);
@@ -23,9 +23,6 @@ static int usb_read(struct intf_hdl *intf, u16 value, void *data, u8 size) goto mutex_unlock; } -/* Acquire IO memory for vendorreq */ - io_buf = dvobjpriv->usb_vendor_req_buf; - status = usb_control_msg_recv(udev, 0, REALTEK_USB_VENQT_CMD_REQ, REALTEK_USB_VENQT_READ, value, REALTEK_USB_VENQT_CMD_IDX, io_buf,
@@ -70,14 +67,14 @@ static int usb_write(struct intf_hdl *intf, u16 value, void *data, u8 size)struct dvobj_priv *dvobjpriv =adapter_to_dvobj (adapt);struct usb_device *udev = dvobjpriv->pusbdev;int status; -u8 *io_buf;/* Pointer to I/O buffer */ +u8 io_buf[VENDOR_CMD_MAX_DATA_LEN ];mutex_lock (&dvobjpriv->usb_vendor_req_mutex); -if (adapt->bSurpriseRemoved || adapt->pwrctrlpriv.pnp_bstop_trx) -return -EPERM ; - - io_buf = dvobjpriv->usb_vendor_req_buf; +if (adapt->bSurpriseRemoved || adapt->pwrctrlpriv.pnp_bstop_trx) { + status = -EPERM ; + goto mutex_unlock; + }memcpy (io_buf, data, size); status = usb_control_msg_send(udev, 0, REALTEK_USB_VENQT_CMD_REQ,
drivers/staging/r8188eu/include/drv_types.h +0 -3
@@ -168,9 +168,6 @@ struct dvobj_priv {struct semaphore usb_suspend_sema;struct mutex usb_vendor_req_mutex; -u8 *usb_alloc_vendor_req_buf; -u8 *usb_vendor_req_buf; -struct usb_interface *pusbintf;struct usb_device *pusbdev;
drivers/staging/r8188eu/os_dep/usb_intf.c +1 -13
@@ -75,24 +75,12 @@ static struct rtw_usb_drv *usb_drv = &rtl8188e_usb_drv;static u8 rtw_init_intf_priv (struct dvobj_priv *dvobj) { -u8 rst = _SUCCESS; -mutex_init (&dvobj->usb_vendor_req_mutex); - - dvobj->usb_alloc_vendor_req_buf =kzalloc (MAX_USB_IO_CTL_SIZE ,GFP_KERNEL ); -if (!dvobj->usb_alloc_vendor_req_buf) { -DBG_88E ("alloc usb_vendor_req_buf failed... /n" ); - rst = _FAIL; - goto exit; - } - dvobj->usb_vendor_req_buf = (u8 *)N_BYTE_ALIGMENT ((size_t )(dvobj->usb_alloc_vendor_req_buf),ALIGNMENT_UNIT ); -exit: -return rst; +return _SUCCESS; }static void rtw_deinit_intf_priv (struct dvobj_priv *dvobj) { -kfree (dvobj->usb_alloc_vendor_req_buf);mutex_destroy (&dvobj->usb_vendor_req_mutex); }
Signature · 1 line
2.33.0
PATCH v10 16/16 staging: r8188eu: remove mutex 'usb_vendor_req_mutex'
In reply to Fabio M. De FrancescoFrom: Pavel Skripkin <[email protected]>
Remove mutex 'usb_vendor_req_mutex'.
It was used to protect a shared buffer for USB requests and, since that buffer is removed in previous patch, this mutex is now useless.
Furthermore, because it was used to serialize the calls to the Core USB API, we thoroughly tested the enabling of concurrent firing of USB requests without the mutex and found no problems of any kind in common use cases.
--- drivers/staging/r8188eu/hal/usb_ops_linux.c | 30 ++++++--------------- drivers/staging/r8188eu/os_dep/usb_intf.c | 24 ----------------- 2 files changed, 8 insertions(+), 46 deletions(-)
drivers/staging/r8188eu/hal/usb_ops_linux.c +8 -22
@@ -16,12 +16,8 @@ static int usb_read(struct intf_hdl *intf, u16 value, void *data, u8 size)int status;u8 io_buf[4 ]; -mutex_lock (&dvobjpriv->usb_vendor_req_mutex); - -if (adapt->bSurpriseRemoved || adapt->pwrctrlpriv.pnp_bstop_trx) { - status = -EPERM ; - goto mutex_unlock; - } +if (adapt->bSurpriseRemoved || adapt->pwrctrlpriv.pnp_bstop_trx) +return -EPERM ; status = usb_control_msg_recv(udev, 0, REALTEK_USB_VENQT_CMD_REQ, REALTEK_USB_VENQT_READ, value,
@@ -39,7 +35,7 @@ static int usb_read(struct intf_hdl *intf, u16 value, void *data, u8 size)* exist or is not enabled. */ adapt->bSurpriseRemoved = true; - goto mutex_unlock; +return status; }if (status <0 ) {
@@ -49,15 +45,12 @@ static int usb_read(struct intf_hdl *intf, u16 value, void *data, u8 size)if (rtw_inc_and_chk_continual_urb_error (dvobjpriv)) adapt->bSurpriseRemoved = true; - goto mutex_unlock; +return status; }rtw_reset_continual_urb_error (dvobjpriv);memcpy (data, io_buf, size); -mutex_unlock: -mutex_unlock (&dvobjpriv->usb_vendor_req_mutex); -return status; }
@@ -69,12 +62,8 @@ static int usb_write(struct intf_hdl *intf, u16 value, void *data, u8 size)int status;u8 io_buf[VENDOR_CMD_MAX_DATA_LEN ]; -mutex_lock (&dvobjpriv->usb_vendor_req_mutex); - -if (adapt->bSurpriseRemoved || adapt->pwrctrlpriv.pnp_bstop_trx) { - status = -EPERM ; - goto mutex_unlock; - } +if (adapt->bSurpriseRemoved || adapt->pwrctrlpriv.pnp_bstop_trx) +return -EPERM ;memcpy (io_buf, data, size); status = usb_control_msg_send(udev, 0, REALTEK_USB_VENQT_CMD_REQ,
@@ -93,7 +82,7 @@ static int usb_write(struct intf_hdl *intf, u16 value, void *data, u8 size)* exist or is not enabled. */ adapt->bSurpriseRemoved = true; - goto mutex_unlock; +return status; }if (status <0 ) {
@@ -103,14 +92,11 @@ static int usb_write(struct intf_hdl *intf, u16 value, void *data, u8 size)if (rtw_inc_and_chk_continual_urb_error (dvobjpriv)) adapt->bSurpriseRemoved = true; - goto mutex_unlock; +return status; }rtw_reset_continual_urb_error (dvobjpriv); -mutex_unlock: -mutex_unlock (&dvobjpriv->usb_vendor_req_mutex); -return status; }
drivers/staging/r8188eu/os_dep/usb_intf.c +0 -24
@@ -73,21 +73,9 @@ static struct rtw_usb_drv rtl8188e_usb_drv = {static struct rtw_usb_drv *usb_drv = &rtl8188e_usb_drv; -static u8 rtw_init_intf_priv (struct dvobj_priv *dvobj) -{ -mutex_init (&dvobj->usb_vendor_req_mutex); -return _SUCCESS; -} - -static void rtw_deinit_intf_priv (struct dvobj_priv *dvobj) -{ -mutex_destroy (&dvobj->usb_vendor_req_mutex); -} -static struct dvobj_priv *usb_dvobj_init (struct usb_interface *usb_intf) {int i; -int status = _FAIL;struct dvobj_priv *pdvobjpriv;struct usb_host_config *phost_conf;struct usb_config_descriptor *pconf_desc;
@@ -146,23 +134,12 @@ static struct dvobj_priv *usb_dvobj_init(struct usb_interface *usb_intf)DBG_88E ("NON USB_SPEED_HIGH\n" ); } -if (rtw_init_intf_priv (pdvobjpriv) == _FAIL) - goto free_dvobj; -/* 3 misc */ sema_init (&pdvobjpriv->usb_suspend_sema,0 );rtw_reset_continual_urb_error (pdvobjpriv);usb_get_dev (pusbd); - status = _SUCCESS; - -free_dvobj: -if (status != _SUCCESS && pdvobjpriv) { -usb_set_intfdata (usb_intf,NULL ); -kfree (pdvobjpriv); - pdvobjpriv =NULL ; - } exit:return pdvobjpriv; }
@@ -188,7 +165,6 @@ static void usb_dvobj_deinit(struct usb_interface *usb_intf)usb_reset_device (interface_to_usbdev (usb_intf)); } } -rtw_deinit_intf_priv (dvobj);kfree (dvobj); }
Signature · 1 line
2.33.0
Quoted 9 lines · CEST Fabio M. De Francesco
--- Preface ---
This is v10 of "shorten and simplify calls chain". The 14 (v7) + 2 (v8) patches have already been applied to staging-testing, so we have been requested to reset the numbering of the remaining patches to 01/16, while discarding from v9 the above-mentioned 16 patches (otherwise we would have submitted a series containing 32 patches, that is 1 patch less than v8 because it has been dropped by us in what we considered it unnecessary - it was about fixing a misspelled word in a comment).
Hello all,
Please disregard this weird cover. I don't know how I've been able to make the mess you see in the subject. The good one has been sent soon after this. And please, let me know if it is necessary to resend in order to have the cover letter as the first email of the thread.
Thanks,
Fabio
Greg Kroah-Hartman
maintainerQuoted 11 lines · Fabio M. De Francesco
Quoted 9 lines · CEST Fabio M. De Francesco
--- Preface ---
This is v10 of "shorten and simplify calls chain". The 14 (v7) + 2 (v8) patches have already been applied to staging-testing, so we have been requested to reset the numbering of the remaining patches to 01/16, while discarding from v9 the above-mentioned 16 patches (otherwise we would have submitted a series containing 32 patches, that is 1 patch less than v8 because it has been dropped by us in what we considered it unnecessary - it was about fixing a misspelled word in a comment).
Quoted 6 lines
Hello all,
Please disregard this weird cover. I don't know how I've been able to make the mess you see in the subject. The good one has been sent soon after this. And please, let me know if it is necessary to resend in order to have the cover letter as the first email of the thread.
Nah, I can figure it out, looks good, let's queue it up and see what breaks :)
thanks,
greg k-h
Quoted 2 lines · CEST Greg Kroah-Hartman
Quoted 1 line · Fabio M. De Francesco
On Friday, September 24, 2021 2:26:49 PM CEST Fabio M. De Francesco
Quoted 8 lines · wrote:
Quoted 5 lines
Quoted 4 lines
--- Preface ---
This is v10 of "shorten and simplify calls chain". [...]
[...]
Nah, I can figure it out, looks good, let's queue it up and see what breaks :)
"[and] see what breaks :)". Interesting...
This is the second or third time you have written me these words (I cannot speak for Pavel). I guess I'll have to work on it :)
All kidding aside, we seriously appreciate that you have decided to accept the patches.
Regards,
Fabio
Quoted 4 lines
thanks,
greg k-h