From cd6cb41e0fa16377d2ede6300f95eb5b1b5719c8 Mon Sep 17 00:00:00 2001 From: Martin Kaiser Date: Sat, 21 Aug 2021 18:48:59 +0200 Subject: [PATCH] set pipe only once Set the pipe for reading or writing in usbctrl_vendorreq only once. There's no need to set it again for every retry. This patch is an adaptation of commit 889ed8b5e374 ("staging: rtl8188eu: set pipe only once") for the new r8188eu driver. Link: https://lore.kernel.org/r/20210821164859.4351-10-martin@kaiser.cx --- os_dep/linux/usb_ops_linux.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/os_dep/linux/usb_ops_linux.c b/os_dep/linux/usb_ops_linux.c index b05978c..28ebd55 100644 --- a/os_dep/linux/usb_ops_linux.c +++ b/os_dep/linux/usb_ops_linux.c @@ -94,14 +94,17 @@ int usbctrl_vendorreq(struct intf_hdl *pintfhdl, u16 value, u16 index, void *pda goto release_mutex; } - while (++vendorreq_times <= MAX_USBCTRL_VENDORREQ_TIMES) { - memset(pIo_buf, 0, len); + if (requesttype == VENDOR_READ) + pipe = usb_rcvctrlpipe(udev, 0);/* read_in */ + else + pipe = usb_sndctrlpipe(udev, 0);/* write_out */ - if (requesttype == 0x01) { - pipe = usb_rcvctrlpipe(udev, 0);/* read_in */ + while (++vendorreq_times <= MAX_USBCTRL_VENDORREQ_TIMES) { + + if (requesttype == VENDOR_READ) { + memset(pIo_buf, 0, len); reqtype = REALTEK_USB_VENQT_READ; } else { - pipe = usb_sndctrlpipe(udev, 0);/* write_out */ reqtype = REALTEK_USB_VENQT_WRITE; _rtw_memcpy(pIo_buf, pdata, len); } @@ -110,13 +113,13 @@ int usbctrl_vendorreq(struct intf_hdl *pintfhdl, u16 value, u16 index, void *pda if (status == len) { /* Success this control transfer. */ rtw_reset_continual_io_error(pdvobjpriv); - if (requesttype == 0x01) { + if (requesttype == VENDOR_READ) { /* For Control read transfer, we have to copy the read data from pIo_buf to pdata. */ _rtw_memcpy(pdata, pIo_buf, len); } } else { /* error cases */ RTW_INFO("reg 0x%x, usb %s %u fail, status:%d value=0x%x, vendorreq_times:%d\n" - , value, (requesttype == 0x01) ? "read" : "write" , len, status, *(u32 *)pdata, vendorreq_times); + , value, (requesttype == VENDOR_READ) ? "read" : "write" , len, status, *(u32 *)pdata, vendorreq_times); if (status < 0) { if (status == (-ESHUTDOWN) || status == -ENODEV)