aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGreg Kroah-Hartman <gregkh@linuxfoundation.org>2022-10-21 08:33:30 +0200
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2024-03-26 17:00:11 +0100
commit0243ef83005fc837ac0b127a949e4dfd2f80622b (patch)
treea6f265055face47fdb545eeb531c134306e740f2
parent4cece764965020c22cff7665b18a012006359095 (diff)
downloadusb-gadget_char.tar.gz
USB: gadget: dummy_hcd: switch char * to u8 *gadget_char
The function handle_control_request() casts the urb buffer to a char *, and then treats it like a unsigned char buffer when assigning data to it. On some architectures, "char" is really signed, so let's just properly set this pointer to a u8 to take away any potential problems as that's what is really wanted here. Document that we are only using the lower 8 bits for the devstatus variable (only 7 are currently used), as the cast from 16 to 8 is not obvious. Cc: Felipe Balbi <balbi@kernel.org> Cc: Jakob Koschel <jakobkoschel@gmail.com> Cc: Randy Dunlap <rdunlap@infradead.org> Cc: Ira Weiny <ira.weiny@intel.com> Cc: Alan Stern <stern@rowland.harvard.edu> Reported-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r--drivers/usb/gadget/udc/dummy_hcd.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/drivers/usb/gadget/udc/dummy_hcd.c b/drivers/usb/gadget/udc/dummy_hcd.c
index 0953e1b5c03007..1139fc8c03f0c5 100644
--- a/drivers/usb/gadget/udc/dummy_hcd.c
+++ b/drivers/usb/gadget/udc/dummy_hcd.c
@@ -1739,13 +1739,13 @@ static int handle_control_request(struct dummy_hcd *dum_hcd, struct urb *urb,
if (setup->bRequestType == Dev_InRequest
|| setup->bRequestType == Intf_InRequest
|| setup->bRequestType == Ep_InRequest) {
- char *buf;
+ u8 *buf;
/*
- * device: remote wakeup, selfpowered
+ * device: remote wakeup, selfpowered, LTM, U1, or U2
* interface: nothing
* endpoint: halt
*/
- buf = (char *)urb->transfer_buffer;
+ buf = urb->transfer_buffer;
if (urb->transfer_buffer_length > 0) {
if (setup->bRequestType == Ep_InRequest) {
ep2 = find_endpoint(dum, w_index);
@@ -1754,11 +1754,12 @@ static int handle_control_request(struct dummy_hcd *dum_hcd, struct urb *urb,
break;
}
buf[0] = ep2->halted;
- } else if (setup->bRequestType ==
- Dev_InRequest) {
+ } else if (setup->bRequestType == Dev_InRequest) {
+ /* Only take the lower 8 bits */
buf[0] = (u8)dum->devstatus;
- } else
+ } else {
buf[0] = 0;
+ }
}
if (urb->transfer_buffer_length > 1)
buf[1] = 0;