diff mbox series

[v3,08/12] usb: misc: ldusb: update to use usb_control_msg_send()

Message ID 20210126183403.911653-9-anant.thazhemadam@gmail.com (mailing list archive)
State Superseded
Headers show
Series drivers: usb: misc: update to use usb_control_msg_{send|recv}() API | expand

Commit Message

Anant Thazhemadam Jan. 26, 2021, 6:33 p.m. UTC
The newer usb_control_msg_{send|recv}() API are an improvement on the
existing usb_control_msg() as it ensures that a short read/write is treated
as an error, data can be used off the stack, and raw usb pipes need not be
created in the calling functions.
For this reason, the instance of usb_control_msg_send() has been replaced
with usb_control_msg_send() appropriately.

Signed-off-by: Anant Thazhemadam <anant.thazhemadam@gmail.com>
---
 drivers/usb/misc/ldusb.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

Comments

Johan Hovold Jan. 27, 2021, 3:06 p.m. UTC | #1
On Wed, Jan 27, 2021 at 12:03:59AM +0530, Anant Thazhemadam wrote:
> The newer usb_control_msg_{send|recv}() API are an improvement on the
> existing usb_control_msg() as it ensures that a short read/write is treated
> as an error, data can be used off the stack, and raw usb pipes need not be
> created in the calling functions.
> For this reason, the instance of usb_control_msg_send() has been replaced
> with usb_control_msg_send() appropriately.
> 
> Signed-off-by: Anant Thazhemadam <anant.thazhemadam@gmail.com>
> ---
>  drivers/usb/misc/ldusb.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/usb/misc/ldusb.c b/drivers/usb/misc/ldusb.c
> index 670e4d91e9ca..259ead4edecb 100644
> --- a/drivers/usb/misc/ldusb.c
> +++ b/drivers/usb/misc/ldusb.c
> @@ -573,15 +573,13 @@ static ssize_t ld_usb_write(struct file *file, const char __user *buffer,
>  	}
>  
>  	if (dev->interrupt_out_endpoint == NULL) {
> -		/* try HID_REQ_SET_REPORT=9 on control_endpoint instead of interrupt_out_endpoint */
> -		retval = usb_control_msg(interface_to_usbdev(dev->intf),
> -					 usb_sndctrlpipe(interface_to_usbdev(dev->intf), 0),
> -					 9,
> +		retval = usb_control_msg_send(interface_to_usbdev(dev->intf),
> +					 0, 9,
>  					 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
>  					 1 << 8, 0,
>  					 dev->interrupt_out_buffer,
>  					 bytes_to_write,
> -					 USB_CTRL_SET_TIMEOUT);
> +					 USB_CTRL_SET_TIMEOUT, GFP_KERNEL);
>  		if (retval < 0)
>  			dev_err(&dev->intf->dev,
>  				"Couldn't submit HID_REQ_SET_REPORT %d\n",

This would also only introduce a redundant allocation and memcpy() as
the buffer is already DMA-able and used for that purpose in other places
as well.

I suggest dropping this one too.

Johan
diff mbox series

Patch

diff --git a/drivers/usb/misc/ldusb.c b/drivers/usb/misc/ldusb.c
index 670e4d91e9ca..259ead4edecb 100644
--- a/drivers/usb/misc/ldusb.c
+++ b/drivers/usb/misc/ldusb.c
@@ -573,15 +573,13 @@  static ssize_t ld_usb_write(struct file *file, const char __user *buffer,
 	}
 
 	if (dev->interrupt_out_endpoint == NULL) {
-		/* try HID_REQ_SET_REPORT=9 on control_endpoint instead of interrupt_out_endpoint */
-		retval = usb_control_msg(interface_to_usbdev(dev->intf),
-					 usb_sndctrlpipe(interface_to_usbdev(dev->intf), 0),
-					 9,
+		retval = usb_control_msg_send(interface_to_usbdev(dev->intf),
+					 0, 9,
 					 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
 					 1 << 8, 0,
 					 dev->interrupt_out_buffer,
 					 bytes_to_write,
-					 USB_CTRL_SET_TIMEOUT);
+					 USB_CTRL_SET_TIMEOUT, GFP_KERNEL);
 		if (retval < 0)
 			dev_err(&dev->intf->dev,
 				"Couldn't submit HID_REQ_SET_REPORT %d\n",