All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] USB: gadget: dummy_hcd: switch char * to u8 *
@ 2024-03-26 16:03 Greg Kroah-Hartman
  2024-03-26 16:16 ` Linus Torvalds
  2024-03-26 16:26 ` Alan Stern
  0 siblings, 2 replies; 11+ messages in thread
From: Greg Kroah-Hartman @ 2024-03-26 16:03 UTC (permalink / raw)
  To: linux-usb
  Cc: Greg Kroah-Hartman, Felipe Balbi, Jakob Koschel, Randy Dunlap,
	Ira Weiny, Alan Stern, Linus Torvalds

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>
---
 drivers/usb/gadget/udc/dummy_hcd.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/gadget/udc/dummy_hcd.c b/drivers/usb/gadget/udc/dummy_hcd.c
index 0953e1b5c030..1139fc8c03f0 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;
-- 
2.44.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread
* [PATCH] USB: gadget: dummy_hcd: switch char * to u8 *
@ 2022-10-21  6:44 Greg Kroah-Hartman
  2022-10-21 17:30 ` Linus Torvalds
  0 siblings, 1 reply; 11+ messages in thread
From: Greg Kroah-Hartman @ 2022-10-21  6:44 UTC (permalink / raw)
  To: linux-usb
  Cc: linux-kernel, Greg Kroah-Hartman, Felipe Balbi, Jakob Koschel,
	Randy Dunlap, Ira Weiny, Linus Torvalds

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.

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>
Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/usb/gadget/udc/dummy_hcd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/udc/dummy_hcd.c b/drivers/usb/gadget/udc/dummy_hcd.c
index 899ac9f9c279..774781968e55 100644
--- a/drivers/usb/gadget/udc/dummy_hcd.c
+++ b/drivers/usb/gadget/udc/dummy_hcd.c
@@ -1740,13 +1740,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
 			 * 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);
-- 
2.38.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2024-03-26 16:29 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-26 16:03 [PATCH] USB: gadget: dummy_hcd: switch char * to u8 * Greg Kroah-Hartman
2024-03-26 16:16 ` Linus Torvalds
2024-03-26 16:29   ` Greg Kroah-Hartman
2024-03-26 16:26 ` Alan Stern
  -- strict thread matches above, loose matches on Subject: below --
2022-10-21  6:44 Greg Kroah-Hartman
2022-10-21 17:30 ` Linus Torvalds
2022-10-21 22:02   ` David Laight
2022-10-23 15:53   ` Greg Kroah-Hartman
2022-10-23 16:04     ` Greg Kroah-Hartman
2022-10-23 16:46       ` Linus Torvalds
2022-10-23 16:46     ` Alan Stern

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.