Skip to contentSkip to conversation

staging: r8188eu: Use usb_control_msg_recv/send() in usbctrl_vendorreq()

RFC PATCH In review Fabio M. De Francesco 3 participants 8 messages Aug 22, 2021 – Aug 24, 2021 Staging

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 staging: r8188eu: Use usb_control_msg_recv/send() in usbctrl_vendorreq()

Replace usb_control_msg() with the new usb_control_msg_recv() and usb_control_msg_send() API of USB Core.

This patch is an RFC for different reasons:

1) I'm not sure if it is needed: while Greg Kroah-Hartman suggested to use the new API in a message to a thread that was about a series of patches submitted by Pavel Skripkin (who decided to not use it), I cannot explain if and why the driver would benefit from this patch.
2) I have doubts about the sematic of the API I use here, so I'd like to know whether or not I'm using them properly.
3) At the moment I cannot test the driver because I don't have my device with me.
4) This patch could probably lead to a slight change in some lines of Pavel's series (for sure in usb_read*()).

I'd like to hear from the Maintainers and other interested people if this patch is worth to be considered and, in this case, if there are suggestions for the purpose to improve it.

---
 drivers/staging/r8188eu/hal/usb_ops_linux.c | 19 ++++++++++---------
 1 file changed, 10 insertions(+), 9 deletions(-)
drivers/staging/r8188eu/hal/usb_ops_linux.c +10 -9
index 6a0a24acf292..9e290c1cc449 100644
@@ -15,7 +15,7 @@ static int usbctrl_vendorreq(struct intf_hdl *pintfhdl, u16 value, void *pdata,
 	struct adapter	*adapt = pintfhdl->padapter;
 	struct dvobj_priv  *dvobjpriv = adapter_to_dvobj(adapt);
 	struct usb_device *udev = dvobjpriv->pusbdev;
-	unsigned int pipe;
+	u8 pipe;
 	int status = 0;
 	u8 reqtype;
 	u8 *pIo_buf;
@@ -47,19 +47,20 @@ static int usbctrl_vendorreq(struct intf_hdl *pintfhdl, u16 value, void *pdata,
 		memset(pIo_buf, 0, len);
 
 		if (requesttype == 0x01) {
-			pipe = usb_rcvctrlpipe(udev, 0);/* read_in */
 			reqtype =  REALTEK_USB_VENQT_READ;
+			status = usb_control_msg_recv(udev, pipe, REALTEK_USB_VENQT_CMD_REQ,
+						      reqtype, value, REALTEK_USB_VENQT_CMD_IDX,
+						      pIo_buf, len, RTW_USB_CONTROL_MSG_TIMEOUT,
+						      GFP_KERNEL);
 		} else {
-			pipe = usb_sndctrlpipe(udev, 0);/* write_out */
 			reqtype =  REALTEK_USB_VENQT_WRITE;
-			memcpy(pIo_buf, pdata, len);
+			status = usb_control_msg_send(udev, pipe, REALTEK_USB_VENQT_CMD_REQ,
+						      reqtype, value, REALTEK_USB_VENQT_CMD_IDX,
+						      pIo_buf, len, RTW_USB_CONTROL_MSG_TIMEOUT,
+						      GFP_KERNEL);
 		}
 
-		status = usb_control_msg(udev, pipe, REALTEK_USB_VENQT_CMD_REQ,
-					 reqtype, value, REALTEK_USB_VENQT_CMD_IDX,
-					 pIo_buf, len, RTW_USB_CONTROL_MSG_TIMEOUT);
-
-		if (status == len) {   /*  Success this control transfer. */
+		if (!status) {   /*  Success this control transfer. */
 			rtw_reset_continual_urb_error(dvobjpriv);
 			if (requesttype == 0x01)
 				memcpy(pdata, pIo_buf,  len);
Signature · 1 line
2.32.0
#1 lore raw
Quoted 31 lines · Fabio M. De Francesco

Replace usb_control_msg() with the new usb_control_msg_recv() and usb_control_msg_send() API of USB Core.

This patch is an RFC for different reasons:

1) I'm not sure if it is needed: while Greg Kroah-Hartman suggested to use the new API in a message to a thread that was about a series of patches submitted by Pavel Skripkin (who decided to not use it), I cannot explain if and why the driver would benefit from this patch.
2) I have doubts about the sematic of the API I use here, so I'd like to know whether or not I'm using them properly.
3) At the moment I cannot test the driver because I don't have my device with me.
4) This patch could probably lead to a slight change in some lines of Pavel's series (for sure in usb_read*()).

I'd like to hear from the Maintainers and other interested people if this patch is worth to be considered and, in this case, if there are suggestions for the purpose to improve it.

---
  drivers/staging/r8188eu/hal/usb_ops_linux.c | 19 ++++++++++---------
  1 file changed, 10 insertions(+), 9 deletions(-)
drivers/staging/r8188eu/hal/usb_ops_linux.c +0 -0
index 6a0a24acf292..9e290c1cc449 100644

drivers/staging/r8188eu/hal/usb_ops_linux.c static int usbctrl_vendorreq(struct intf_hdl *pintfhdl, u16 value, void *pdata, · line 20

Quoted 7 lines
drivers/staging/r8188eu/hal/usb_ops_linux.c +1 -1
@@ -15,7 +15,7 @@ static int usbctrl_vendorreq(struct intf_hdl *pintfhdl, u16 value, void *pdata,
  	struct adapter	*adapt = pintfhdl->padapter;
  	struct dvobj_priv  *dvobjpriv = adapter_to_dvobj(adapt);
  	struct usb_device *udev = dvobjpriv->pusbdev;
-	unsigned int pipe;
+	u8 pipe;
  	int status = 0;
  	u8 reqtype;

I think, we can pass REALTEK_USB_VENQT_{READ,WRITE} directly as requesttype argument and get rid of u8 reqtype. + we can define these macros:

#define
usbctrl_vendor_read(...) usbctrl_vendorreq(...,REALTEK_USB_VENQT_READ)

#define
usbctrl_vendor_write() usbctrl_vendorreq(...,REALTEK_USB_VENQT_WRITE)

This will make code more nice, IMO :)

(Sorry for this formatting, my email client disabled "paste without formatting" option)

Quoted 5 lines
drivers/staging/r8188eu/hal/usb_ops_linux.c +0 -0
  	u8 *pIo_buf;
@@ -47,19 +47,20 @@ static int usbctrl_vendorreq(struct intf_hdl *pintfhdl, u16 value, void *pdata,
  		memset(pIo_buf, 0, len);
 
  		if (requesttype == 0x01) {

drivers/staging/r8188eu/hal/usb_ops_linux.c static int usbctrl_vendorreq(struct intf_hdl *pintfhdl, u16 value, void *pdata, · line 55

Quoted 10 lines
drivers/staging/r8188eu/hal/usb_ops_linux.c +4 -3
-			pipe = usb_rcvctrlpipe(udev, 0);/* read_in */
  			reqtype =  REALTEK_USB_VENQT_READ;
+			status = usb_control_msg_recv(udev, pipe, REALTEK_USB_VENQT_CMD_REQ,
+						      reqtype, value, REALTEK_USB_VENQT_CMD_IDX,
+						      pIo_buf, len, RTW_USB_CONTROL_MSG_TIMEOUT,
+						      GFP_KERNEL);
  		} else {
-			pipe = usb_sndctrlpipe(udev, 0);/* write_out */
  			reqtype =  REALTEK_USB_VENQT_WRITE;
-			memcpy(pIo_buf, pdata, len);

I guess, this memcpy is needed, since we want to send data from pdata

Quoted 6 lines
drivers/staging/r8188eu/hal/usb_ops_linux.c +4 -0
+			status = usb_control_msg_send(udev, pipe, REALTEK_USB_VENQT_CMD_REQ,
+						      reqtype, value, REALTEK_USB_VENQT_CMD_IDX,
+						      pIo_buf, len, RTW_USB_CONTROL_MSG_TIMEOUT,
+						      GFP_KERNEL);
  		}

drivers/staging/r8188eu/hal/usb_ops_linux.c static int usbctrl_vendorreq(struct intf_hdl *pintfhdl, u16 value, void *pdata, · line 66

Quoted 10 lines
drivers/staging/r8188eu/hal/usb_ops_linux.c +1 -5
 
-		status = usb_control_msg(udev, pipe, REALTEK_USB_VENQT_CMD_REQ,
-					 reqtype, value, REALTEK_USB_VENQT_CMD_IDX,
-					 pIo_buf, len, RTW_USB_CONTROL_MSG_TIMEOUT);
-
-		if (status == len) {   /*  Success this control transfer. */
+		if (!status) {   /*  Success this control transfer. */
  			rtw_reset_continual_urb_error(dvobjpriv);
  			if (requesttype == 0x01)
  				memcpy(pdata, pIo_buf,  len);

With regards,
Pavel Skripkin

#2 lore raw
Quoted 55 lines · Pavel Skripkin
Quoted 31 lines · Fabio M. De Francesco

Replace usb_control_msg() with the new usb_control_msg_recv() and usb_control_msg_send() API of USB Core.

This patch is an RFC for different reasons:

1) I'm not sure if it is needed: while Greg Kroah-Hartman suggested to use the new API in a message to a thread that was about a series of patches submitted by Pavel Skripkin (who decided to not use it), I cannot explain if and why the driver would benefit from this patch.
2) I have doubts about the sematic of the API I use here, so I'd like to know whether or not I'm using them properly.
3) At the moment I cannot test the driver because I don't have my device with me.
4) This patch could probably lead to a slight change in some lines of Pavel's series (for sure in usb_read*()).

I'd like to hear from the Maintainers and other interested people if this patch is worth to be considered and, in this case, if there are suggestions for the purpose to improve it.

---
  drivers/staging/r8188eu/hal/usb_ops_linux.c | 19 ++++++++++---------
  1 file changed, 10 insertions(+), 9 deletions(-)
drivers/staging/r8188eu/hal/usb_ops_linux.c +0 -0
index 6a0a24acf292..9e290c1cc449 100644

drivers/staging/r8188eu/hal/usb_ops_linux.c static int usbctrl_vendorreq(struct intf_hdl *pintfhdl, u16 value, void *pdata, · line 20

Quoted 7 lines
drivers/staging/r8188eu/hal/usb_ops_linux.c +1 -1
@@ -15,7 +15,7 @@ static int usbctrl_vendorreq(struct intf_hdl *pintfhdl, u16 value, void *pdata,
  	struct adapter	*adapt = pintfhdl->padapter;
  	struct dvobj_priv  *dvobjpriv = adapter_to_dvobj(adapt);
  	struct usb_device *udev = dvobjpriv->pusbdev;
-	unsigned int pipe;
+	u8 pipe;
  	int status = 0;
  	u8 reqtype;

I think, we can pass REALTEK_USB_VENQT_{READ,WRITE} directly as requesttype argument and get rid of u8 reqtype. + we can define these macros:

#define
usbctrl_vendor_read(...) usbctrl_vendorreq(...,REALTEK_USB_VENQT_READ)

#define
usbctrl_vendor_write() usbctrl_vendorreq(...,REALTEK_USB_VENQT_WRITE)

This will make code more nice, IMO :)

Quoted 7 lines

(Sorry for this formatting, my email client disabled "paste without formatting" option)

drivers/staging/r8188eu/hal/usb_ops_linux.c static int usbctrl_vendorreq(struct intf_hdl *pintfhdl, u16 value, void *pdata, · line 48

Quoted 4 lines
drivers/staging/r8188eu/hal/usb_ops_linux.c +0 -0
  	u8 *pIo_buf;
@@ -47,19 +47,20 @@ static int usbctrl_vendorreq(struct intf_hdl *pintfhdl, u16 value, void *pdata,
  		memset(pIo_buf, 0, len);
 
		^^^^^^^^^^^^^^^^^^^^^^^

And this memset becomes useless, since usb_control_msg_recv cannot receive only part of the message

Quoted 21 lines

drivers/staging/r8188eu/hal/usb_ops_linux.c static int usbctrl_vendorreq(struct intf_hdl *pintfhdl, u16 value, void *pdata, · line 55

Quoted 11 lines
drivers/staging/r8188eu/hal/usb_ops_linux.c +4 -3
  		if (requesttype == 0x01) {
-			pipe = usb_rcvctrlpipe(udev, 0);/* read_in */
  			reqtype =  REALTEK_USB_VENQT_READ;
+			status = usb_control_msg_recv(udev, pipe, REALTEK_USB_VENQT_CMD_REQ,
+						      reqtype, value, REALTEK_USB_VENQT_CMD_IDX,
+						      pIo_buf, len, RTW_USB_CONTROL_MSG_TIMEOUT,
+						      GFP_KERNEL);
  		} else {
-			pipe = usb_sndctrlpipe(udev, 0);/* write_out */
  			reqtype =  REALTEK_USB_VENQT_WRITE;
-			memcpy(pIo_buf, pdata, len);

I guess, this memcpy is needed, since we want to send data from pdata

Quoted 6 lines
drivers/staging/r8188eu/hal/usb_ops_linux.c +4 -0
+			status = usb_control_msg_send(udev, pipe, REALTEK_USB_VENQT_CMD_REQ,
+						      reqtype, value, REALTEK_USB_VENQT_CMD_IDX,
+						      pIo_buf, len, RTW_USB_CONTROL_MSG_TIMEOUT,
+						      GFP_KERNEL);
  		}
 
Quoted 11 lines

drivers/staging/r8188eu/hal/usb_ops_linux.c static int usbctrl_vendorreq(struct intf_hdl *pintfhdl, u16 value, void *pdata, · line 66

Quoted 10 lines
drivers/staging/r8188eu/hal/usb_ops_linux.c +1 -5
-		status = usb_control_msg(udev, pipe, REALTEK_USB_VENQT_CMD_REQ,
-					 reqtype, value, REALTEK_USB_VENQT_CMD_IDX,
-					 pIo_buf, len, RTW_USB_CONTROL_MSG_TIMEOUT);
-
-		if (status == len) {   /*  Success this control transfer. */
+		if (!status) {   /*  Success this control transfer. */
  			rtw_reset_continual_urb_error(dvobjpriv);
  			if (requesttype == 0x01)
  				memcpy(pdata, pIo_buf,  len);

With regards,
Pavel Skripkin

#3 lore raw
Quoted 6 lines · CEST Pavel Skripkin
Quoted 5 lines · Pavel Skripkin
Quoted 4 lines · Fabio M. De Francesco

Replace usb_control_msg() with the new usb_control_msg_recv() and usb_control_msg_send() API of USB Core.
[...]

Quoted 8 lines
Quoted 3 lines

drivers/staging/r8188eu/hal/usb_ops_linux.c static int usbctrl_vendorreq(struct intf_hdl *pintfhdl, u16 value, void *pdata, · line 48

Quoted 3 lines
drivers/staging/r8188eu/hal/usb_ops_linux.c +0 -0
@@ -47,19 +47,20 @@ static int usbctrl_vendorreq(struct intf_hdl *pintfhdl, u16 value, void *pdata,
  		memset(pIo_buf, 0, len);
 
		^^^^^^^^^^^^^^^^^^^^^^^

And this memset becomes useless, since usb_control_msg_recv cannot receive only part of the message

I didn't notice it at all. Obviously, I'll remove it.

Thanks,

Fabio

Quoted 4 lines

With regards,
Pavel Skripkin

#4 lore raw
In reply to Pavel Skripkin
Quoted 48 lines · CEST Pavel Skripkin
Quoted 31 lines · Fabio M. De Francesco

Replace usb_control_msg() with the new usb_control_msg_recv() and usb_control_msg_send() API of USB Core.

This patch is an RFC for different reasons:

1) I'm not sure if it is needed: while Greg Kroah-Hartman suggested to use the new API in a message to a thread that was about a series of patches submitted by Pavel Skripkin (who decided to not use it), I cannot explain if and why the driver would benefit from this patch.
2) I have doubts about the semantic of the API I use here, so I'd like to know whether or not I'm using them properly.
3) At the moment I cannot test the driver because I don't have my device with me.
4) This patch could probably lead to a slight change in some lines of Pavel's series (for sure in usb_read*()).

I'd like to hear from the Maintainers and other interested people if this patch is worth to be considered and, in this case, if there are suggestions for the purpose to improve it.

---
  drivers/staging/r8188eu/hal/usb_ops_linux.c | 19 ++++++++++---------
  1 file changed, 10 insertions(+), 9 deletions(-)
drivers/staging/r8188eu/hal/usb_ops_linux.c +0 -0
index 6a0a24acf292..9e290c1cc449 100644

drivers/staging/r8188eu/hal/usb_ops_linux.c static int usbctrl_vendorreq(struct intf_hdl *pintfhdl, u16 value, void *pdata, · line 20

Quoted 7 lines
drivers/staging/r8188eu/hal/usb_ops_linux.c +1 -1
@@ -15,7 +15,7 @@ static int usbctrl_vendorreq(struct intf_hdl *pintfhdl, u16 value, void *pdata,
  	struct adapter	*adapt = pintfhdl->padapter;
  	struct dvobj_priv  *dvobjpriv = adapter_to_dvobj(adapt);
  	struct usb_device *udev = dvobjpriv->pusbdev;
-	unsigned int pipe;
+	u8 pipe;
  	int status = 0;
  	u8 reqtype;

I think, we can pass REALTEK_USB_VENQT_{READ,WRITE} directly as requesttype argument and get rid of u8 reqtype. + we can define these macros:

#define
usbctrl_vendor_read(...) usbctrl_vendorreq(...,REALTEK_USB_VENQT_READ)

Quoted 5 lines

#define
usbctrl_vendor_write() usbctrl_vendorreq(...,REALTEK_USB_VENQT_WRITE)

This will make code more nice, IMO :)

Dear Pavel,

I agree in full: nicer and cleaner :)

I'll do that, but please notice that I will also need to change the code of the three usb_read*() for calling usbctrl_vendor_read(). Furthermore, "else res = 0;" becomes unnecessary. Please take these changes into account when you'll send them again as "regular" patches.

Quoted 2 lines

(Sorry for this formatting, my email client disabled "paste without formatting" option)

Actually I don't see any oddities in the format of your message :)

Quoted 4 lines
Quoted 4 lines
drivers/staging/r8188eu/hal/usb_ops_linux.c +0 -0
  	u8 *pIo_buf;
@@ -47,19 +47,20 @@ static int usbctrl_vendorreq(struct intf_hdl *pintfhdl, u16 value, void *pdata,
  		memset(pIo_buf, 0, len);
 
Quoted 13 lines

drivers/staging/r8188eu/hal/usb_ops_linux.c static int usbctrl_vendorreq(struct intf_hdl *pintfhdl, u16 value, void *pdata, · line 55

Quoted 11 lines
drivers/staging/r8188eu/hal/usb_ops_linux.c +4 -3
  		if (requesttype == 0x01) {
-			pipe = usb_rcvctrlpipe(udev, 0);/* read_in */
  			reqtype =  REALTEK_USB_VENQT_READ;
+			status = usb_control_msg_recv(udev, pipe, REALTEK_USB_VENQT_CMD_REQ,
+						      reqtype, value, REALTEK_USB_VENQT_CMD_IDX,
+						      pIo_buf, len, RTW_USB_CONTROL_MSG_TIMEOUT,
+						      GFP_KERNEL);
  		} else {
-			pipe = usb_sndctrlpipe(udev, 0);/* write_out */
  			reqtype =  REALTEK_USB_VENQT_WRITE;
-			memcpy(pIo_buf, pdata, len);

I guess, this memcpy is needed, since we want to send data from pdata

Oh, dear! How could I have missed that? Two alternatives: either because of working during bedtime, or I'm definitely losing my mind... :(

Quoted 7 lines
Quoted 7 lines
drivers/staging/r8188eu/hal/usb_ops_linux.c +4 -0
+			status = usb_control_msg_send(udev, pipe, REALTEK_USB_VENQT_CMD_REQ,
+						      reqtype, value, REALTEK_USB_VENQT_CMD_IDX,
+						      pIo_buf, len, RTW_USB_CONTROL_MSG_TIMEOUT,
+						      GFP_KERNEL);
  		}
 
Quoted 14 lines

drivers/staging/r8188eu/hal/usb_ops_linux.c static int usbctrl_vendorreq(struct intf_hdl *pintfhdl, u16 value, void *pdata, · line 66

Quoted 10 lines
drivers/staging/r8188eu/hal/usb_ops_linux.c +1 -5
-		status = usb_control_msg(udev, pipe, REALTEK_USB_VENQT_CMD_REQ,
-					 reqtype, value, REALTEK_USB_VENQT_CMD_IDX,
-					 pIo_buf, len, RTW_USB_CONTROL_MSG_TIMEOUT);
-
-		if (status == len) {   /*  Success this control transfer. */
+		if (!status) {   /*  Success this control transfer. */
  			rtw_reset_continual_urb_error(dvobjpriv);
  			if (requesttype == 0x01)
  				memcpy(pdata, pIo_buf,  len);

With regards,
Pavel Skripkin

Thanks for you review, I really appreciate it.

Regards,

Fabio

P.S.: As I wrote, I have not my ASUS N10 Nano with me and I won't have the opportunity to test this as well as any other patch until the end of August. I hope to not break anything. If somebody has time to test the final patch that I'm going to submit, I'd really appreciate it.

#5 lore raw
Quoted 53 lines · Fabio M. De Francesco
Quoted 46 lines · CEST Pavel Skripkin
Quoted 31 lines · Fabio M. De Francesco

Replace usb_control_msg() with the new usb_control_msg_recv() and usb_control_msg_send() API of USB Core.

This patch is an RFC for different reasons:

1) I'm not sure if it is needed: while Greg Kroah-Hartman suggested to use the new API in a message to a thread that was about a series of patches submitted by Pavel Skripkin (who decided to not use it), I cannot explain if and why the driver would benefit from this patch.
2) I have doubts about the semantic of the API I use here, so I'd like to know whether or not I'm using them properly.
3) At the moment I cannot test the driver because I don't have my device with me.
4) This patch could probably lead to a slight change in some lines of Pavel's series (for sure in usb_read*()).

I'd like to hear from the Maintainers and other interested people if this patch is worth to be considered and, in this case, if there are suggestions for the purpose to improve it.

---
  drivers/staging/r8188eu/hal/usb_ops_linux.c | 19 ++++++++++---------
  1 file changed, 10 insertions(+), 9 deletions(-)
drivers/staging/r8188eu/hal/usb_ops_linux.c +0 -0
index 6a0a24acf292..9e290c1cc449 100644

drivers/staging/r8188eu/hal/usb_ops_linux.c static int usbctrl_vendorreq(struct intf_hdl *pintfhdl, u16 value, void *pdata, · line 20

Quoted 7 lines
drivers/staging/r8188eu/hal/usb_ops_linux.c +1 -1
@@ -15,7 +15,7 @@ static int usbctrl_vendorreq(struct intf_hdl *pintfhdl, u16 value, void *pdata,
  	struct adapter	*adapt = pintfhdl->padapter;
  	struct dvobj_priv  *dvobjpriv = adapter_to_dvobj(adapt);
  	struct usb_device *udev = dvobjpriv->pusbdev;
-	unsigned int pipe;
+	u8 pipe;
  	int status = 0;
  	u8 reqtype;

I think, we can pass REALTEK_USB_VENQT_{READ,WRITE} directly as requesttype argument and get rid of u8 reqtype. + we can define these macros:

#define
usbctrl_vendor_read(...) usbctrl_vendorreq(...,REALTEK_USB_VENQT_READ)

Quoted 5 lines

#define
usbctrl_vendor_write() usbctrl_vendorreq(...,REALTEK_USB_VENQT_WRITE)

This will make code more nice, IMO :)

Quoted 9 lines

Dear Pavel,

I agree in full: nicer and cleaner :)

I'll do that, but please notice that I will also need to change the code of the three usb_read*() for calling usbctrl_vendor_read(). Furthermore, "else res = 0;" becomes unnecessary. Please take these changes into account when you'll send them again as "regular" patches.

It depends on which patch will go in first.

There are a lot of upcoming clean ups, so I am waiting for merging my series with random clean ups :) A lot of fun...

I biggest hope is that my series will go in before camel-case clean ups, because rewriting this for the 3rd time will kill my mind...

With regards,
Pavel Skripkin

#6 lore raw
Quoted 16 lines · CEST Pavel Skripkin
Quoted 15 lines · Fabio M. De Francesco

[...]

Quoted 11 lines

I think, we can pass REALTEK_USB_VENQT_{READ,WRITE} directly as requesttype argument and get rid of u8 reqtype. + we can define these macros:

#define
usbctrl_vendor_read(...) usbctrl_vendorreq(...,REALTEK_USB_VENQT_READ)

#define
usbctrl_vendor_write() usbctrl_vendorreq(...,REALTEK_USB_VENQT_WRITE)

This will make code more nice, IMO :)

Quoted 8 lines
Quoted 8 lines

Dear Pavel,

I agree in full: nicer and cleaner :)

I'll do that, but please notice that I will also need to change the code of the three usb_read*() for calling usbctrl_vendor_read(). Furthermore, "else res = 0;" becomes unnecessary. Please take these changes into account when you'll send them again as "regular" patches.

I have reconsidered the tip above and, while I appreciate your suggestion, I think it's not so necessary to use the macros only to get rid of "u8 reqtype". I finally got rid of that variable by passing the request types explicitly to usb_control_msg_recv/send().

Quoted 4 lines

It depends on which patch will go in first.

There are a lot of upcoming clean ups, so I am waiting for merging my series with random clean ups :) A lot of fun...

A lot of fun... Sure? :)

Quoted 2 lines

I biggest hope is that my series will go in before camel-case clean ups, because rewriting this for the 3rd time will kill my mind...

In this case, I wouldn't want to be in your place :)

Quoted 3 lines

With regards,
Pavel Skripkin

Thanks again very much for your review,

Fabio

#7 lore raw
In reply to Fabio M. De Francesco
Quoted 115 lines · Fabio M. De Francesco
Quoted 48 lines · CEST Pavel Skripkin
Quoted 31 lines · Fabio M. De Francesco

Replace usb_control_msg() with the new usb_control_msg_recv() and usb_control_msg_send() API of USB Core.

This patch is an RFC for different reasons:

1) I'm not sure if it is needed: while Greg Kroah-Hartman suggested to use the new API in a message to a thread that was about a series of patches submitted by Pavel Skripkin (who decided to not use it), I cannot explain if and why the driver would benefit from this patch.
2) I have doubts about the semantic of the API I use here, so I'd like to know whether or not I'm using them properly.
3) At the moment I cannot test the driver because I don't have my device with me.
4) This patch could probably lead to a slight change in some lines of Pavel's series (for sure in usb_read*()).

I'd like to hear from the Maintainers and other interested people if this patch is worth to be considered and, in this case, if there are suggestions for the purpose to improve it.

---
  drivers/staging/r8188eu/hal/usb_ops_linux.c | 19 ++++++++++---------
  1 file changed, 10 insertions(+), 9 deletions(-)
drivers/staging/r8188eu/hal/usb_ops_linux.c +0 -0
index 6a0a24acf292..9e290c1cc449 100644

drivers/staging/r8188eu/hal/usb_ops_linux.c static int usbctrl_vendorreq(struct intf_hdl *pintfhdl, u16 value, void *pdata, · line 20

Quoted 7 lines
drivers/staging/r8188eu/hal/usb_ops_linux.c +1 -1
@@ -15,7 +15,7 @@ static int usbctrl_vendorreq(struct intf_hdl *pintfhdl, u16 value, void *pdata,
    struct adapter  *adapt = pintfhdl->padapter;
    struct dvobj_priv  *dvobjpriv = adapter_to_dvobj(adapt);
    struct usb_device *udev = dvobjpriv->pusbdev;
-   unsigned int pipe;
+   u8 pipe;
    int status = 0;
    u8 reqtype;

I think, we can pass REALTEK_USB_VENQT_{READ,WRITE} directly as requesttype argument and get rid of u8 reqtype. + we can define these macros:

#define
usbctrl_vendor_read(...) usbctrl_vendorreq(...,REALTEK_USB_VENQT_READ)

Quoted 5 lines

#define
usbctrl_vendor_write() usbctrl_vendorreq(...,REALTEK_USB_VENQT_WRITE)

This will make code more nice, IMO :)

Dear Pavel,

I agree in full: nicer and cleaner :)

I'll do that, but please notice that I will also need to change the code of the three usb_read*() for calling usbctrl_vendor_read(). Furthermore, "else res = 0;" becomes unnecessary. Please take these changes into account when you'll send them again as "regular" patches.

Quoted 2 lines

(Sorry for this formatting, my email client disabled "paste without formatting" option)

Actually I don't see any oddities in the format of your message :)

Quoted 4 lines
Quoted 4 lines
drivers/staging/r8188eu/hal/usb_ops_linux.c +0 -0
    u8 *pIo_buf;
@@ -47,19 +47,20 @@ static int usbctrl_vendorreq(struct intf_hdl *pintfhdl, u16 value, void *pdata,
            memset(pIo_buf, 0, len);
 
Quoted 13 lines

drivers/staging/r8188eu/hal/usb_ops_linux.c static int usbctrl_vendorreq(struct intf_hdl *pintfhdl, u16 value, void *pdata, · line 55

Quoted 11 lines
drivers/staging/r8188eu/hal/usb_ops_linux.c +4 -3
            if (requesttype == 0x01) {
-                   pipe = usb_rcvctrlpipe(udev, 0);/* read_in */
                    reqtype =  REALTEK_USB_VENQT_READ;
+                   status = usb_control_msg_recv(udev, pipe, REALTEK_USB_VENQT_CMD_REQ,
+                                                 reqtype, value, REALTEK_USB_VENQT_CMD_IDX,
+                                                 pIo_buf, len, RTW_USB_CONTROL_MSG_TIMEOUT,
+                                                 GFP_KERNEL);
            } else {
-                   pipe = usb_sndctrlpipe(udev, 0);/* write_out */
                    reqtype =  REALTEK_USB_VENQT_WRITE;
-                   memcpy(pIo_buf, pdata, len);

I guess, this memcpy is needed, since we want to send data from pdata

Oh, dear! How could I have missed that? Two alternatives: either because of working during bedtime, or I'm definitely losing my mind... :(

Quoted 19 lines
Quoted 7 lines
drivers/staging/r8188eu/hal/usb_ops_linux.c +4 -0
+                   status = usb_control_msg_send(udev, pipe, REALTEK_USB_VENQT_CMD_REQ,
+                                                 reqtype, value, REALTEK_USB_VENQT_CMD_IDX,
+                                                 pIo_buf, len, RTW_USB_CONTROL_MSG_TIMEOUT,
+                                                 GFP_KERNEL);
            }

drivers/staging/r8188eu/hal/usb_ops_linux.c static int usbctrl_vendorreq(struct intf_hdl *pintfhdl, u16 value, void *pdata, · line 66

Quoted 10 lines
drivers/staging/r8188eu/hal/usb_ops_linux.c +1 -5
 
-           status = usb_control_msg(udev, pipe, REALTEK_USB_VENQT_CMD_REQ,
-                                    reqtype, value, REALTEK_USB_VENQT_CMD_IDX,
-                                    pIo_buf, len, RTW_USB_CONTROL_MSG_TIMEOUT);
-
-           if (status == len) {   /*  Success this control transfer. */
+           if (!status) {   /*  Success this control transfer. */
                    rtw_reset_continual_urb_error(dvobjpriv);
                    if (requesttype == 0x01)
                            memcpy(pdata, pIo_buf,  len);
Quoted 2 lines

With regards,
Pavel Skripkin

Thanks for you review, I really appreciate it.

Quoted 9 lines

Regards,

Fabio

P.S.: As I wrote, I have not my ASUS N10 Nano with me and I won't have the opportunity to test this as well as any other patch until the end of August. I hope to not break anything. If somebody has time to test the final patch that I'm going to submit, I'd really appreciate it.

Dear Fabio,

Code is looking good - happy to test the final patch here by all means.

Regards,
Phil