aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb
diff options
context:
space:
mode:
authorDavid Brownell <david-b@pacbell.net>2005-05-07 16:05:13 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2005-06-27 17:43:53 -0400
commit1bbc169621cbe502b9143a27eb12802a0f1d43a0 (patch)
treea8fc4a429d890ea02ef1084ec3ffb2a9b9ef9c61 /drivers/usb
parent028b271b687714f9fc7a1e89bb79f1fbeef154ee (diff)
[PATCH] USB: gadget driver updates (SETUP api change)
This updates most of the gadget framework to expect SETUP packets use USB byteorder (matching the annotation in <linux/usb_ch9.h> and usage in the host side stack): - definition in <linux/usb_gadget.h> - gadget drivers: Ethernet/RNDIS, serial/ACM, file_storage, gadgetfs. - dummy_hcd It also includes some other similar changes as suggested by "sparse", which was used to detect byteorder bugs. Signed-off-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb')
-rw-r--r--drivers/usb/gadget/dummy_hcd.c3
-rw-r--r--drivers/usb/gadget/ether.c6
-rw-r--r--drivers/usb/gadget/file_storage.c19
-rw-r--r--drivers/usb/gadget/inode.c12
-rw-r--r--drivers/usb/gadget/serial.c36
-rw-r--r--drivers/usb/gadget/zero.c6
6 files changed, 40 insertions, 42 deletions
diff --git a/drivers/usb/gadget/dummy_hcd.c b/drivers/usb/gadget/dummy_hcd.c
index 73d2f24050ab..f9540adf2a4f 100644
--- a/drivers/usb/gadget/dummy_hcd.c
+++ b/drivers/usb/gadget/dummy_hcd.c
@@ -1267,9 +1267,6 @@ restart:
1267 struct dummy_ep *ep2; 1267 struct dummy_ep *ep2;
1268 1268
1269 setup = *(struct usb_ctrlrequest*) urb->setup_packet; 1269 setup = *(struct usb_ctrlrequest*) urb->setup_packet;
1270 le16_to_cpus (&setup.wIndex);
1271 le16_to_cpus (&setup.wValue);
1272 le16_to_cpus (&setup.wLength);
1273 if (setup.wLength != urb->transfer_buffer_length) { 1270 if (setup.wLength != urb->transfer_buffer_length) {
1274 maybe_set_status (urb, -EOVERFLOW); 1271 maybe_set_status (urb, -EOVERFLOW);
1275 goto return_urb; 1272 goto return_urb;
diff --git a/drivers/usb/gadget/ether.c b/drivers/usb/gadget/ether.c
index 3830a0a0fd50..9f8413e3c10a 100644
--- a/drivers/usb/gadget/ether.c
+++ b/drivers/usb/gadget/ether.c
@@ -1277,9 +1277,9 @@ eth_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
1277 struct eth_dev *dev = get_gadget_data (gadget); 1277 struct eth_dev *dev = get_gadget_data (gadget);
1278 struct usb_request *req = dev->req; 1278 struct usb_request *req = dev->req;
1279 int value = -EOPNOTSUPP; 1279 int value = -EOPNOTSUPP;
1280 u16 wIndex = (__force u16) ctrl->wIndex; 1280 u16 wIndex = le16_to_cpu(ctrl->wIndex);
1281 u16 wValue = (__force u16) ctrl->wValue; 1281 u16 wValue = le16_to_cpu(ctrl->wValue);
1282 u16 wLength = (__force u16) ctrl->wLength; 1282 u16 wLength = le16_to_cpu(ctrl->wLength);
1283 1283
1284 /* descriptors just go into the pre-allocated ep0 buffer, 1284 /* descriptors just go into the pre-allocated ep0 buffer,
1285 * while config change events may enable network traffic. 1285 * while config change events may enable network traffic.
diff --git a/drivers/usb/gadget/file_storage.c b/drivers/usb/gadget/file_storage.c
index f5ce45c4b2a3..4f57085619b4 100644
--- a/drivers/usb/gadget/file_storage.c
+++ b/drivers/usb/gadget/file_storage.c
@@ -819,7 +819,7 @@ static void inline put_be32(u8 *buf, u32 val)
819 buf[0] = val >> 24; 819 buf[0] = val >> 24;
820 buf[1] = val >> 16; 820 buf[1] = val >> 16;
821 buf[2] = val >> 8; 821 buf[2] = val >> 8;
822 buf[3] = val; 822 buf[3] = val & 0xff;
823} 823}
824 824
825 825
@@ -1277,8 +1277,8 @@ static int class_setup_req(struct fsg_dev *fsg,
1277{ 1277{
1278 struct usb_request *req = fsg->ep0req; 1278 struct usb_request *req = fsg->ep0req;
1279 int value = -EOPNOTSUPP; 1279 int value = -EOPNOTSUPP;
1280 u16 w_index = ctrl->wIndex; 1280 u16 w_index = le16_to_cpu(ctrl->wIndex);
1281 u16 w_length = ctrl->wLength; 1281 u16 w_length = le16_to_cpu(ctrl->wLength);
1282 1282
1283 if (!fsg->config) 1283 if (!fsg->config)
1284 return value; 1284 return value;
@@ -1345,7 +1345,7 @@ static int class_setup_req(struct fsg_dev *fsg,
1345 "unknown class-specific control req " 1345 "unknown class-specific control req "
1346 "%02x.%02x v%04x i%04x l%u\n", 1346 "%02x.%02x v%04x i%04x l%u\n",
1347 ctrl->bRequestType, ctrl->bRequest, 1347 ctrl->bRequestType, ctrl->bRequest,
1348 ctrl->wValue, w_index, w_length); 1348 le16_to_cpu(ctrl->wValue), w_index, w_length);
1349 return value; 1349 return value;
1350} 1350}
1351 1351
@@ -1359,8 +1359,8 @@ static int standard_setup_req(struct fsg_dev *fsg,
1359{ 1359{
1360 struct usb_request *req = fsg->ep0req; 1360 struct usb_request *req = fsg->ep0req;
1361 int value = -EOPNOTSUPP; 1361 int value = -EOPNOTSUPP;
1362 u16 w_index = ctrl->wIndex; 1362 u16 w_index = le16_to_cpu(ctrl->wIndex);
1363 u16 w_value = ctrl->wValue; 1363 u16 w_value = le16_to_cpu(ctrl->wValue);
1364 1364
1365 /* Usually this just stores reply data in the pre-allocated ep0 buffer, 1365 /* Usually this just stores reply data in the pre-allocated ep0 buffer,
1366 * but config change events will also reconfigure hardware. */ 1366 * but config change events will also reconfigure hardware. */
@@ -1469,7 +1469,7 @@ static int standard_setup_req(struct fsg_dev *fsg,
1469 VDBG(fsg, 1469 VDBG(fsg,
1470 "unknown control req %02x.%02x v%04x i%04x l%u\n", 1470 "unknown control req %02x.%02x v%04x i%04x l%u\n",
1471 ctrl->bRequestType, ctrl->bRequest, 1471 ctrl->bRequestType, ctrl->bRequest,
1472 w_value, w_index, ctrl->wLength); 1472 w_value, w_index, le16_to_cpu(ctrl->wLength));
1473 } 1473 }
1474 1474
1475 return value; 1475 return value;
@@ -1481,7 +1481,7 @@ static int fsg_setup(struct usb_gadget *gadget,
1481{ 1481{
1482 struct fsg_dev *fsg = get_gadget_data(gadget); 1482 struct fsg_dev *fsg = get_gadget_data(gadget);
1483 int rc; 1483 int rc;
1484 int w_length = ctrl->wLength; 1484 int w_length = le16_to_cpu(ctrl->wLength);
1485 1485
1486 ++fsg->ep0_req_tag; // Record arrival of a new request 1486 ++fsg->ep0_req_tag; // Record arrival of a new request
1487 fsg->ep0req->context = NULL; 1487 fsg->ep0req->context = NULL;
@@ -1497,8 +1497,7 @@ static int fsg_setup(struct usb_gadget *gadget,
1497 if (rc >= 0 && rc != DELAYED_STATUS) { 1497 if (rc >= 0 && rc != DELAYED_STATUS) {
1498 rc = min(rc, w_length); 1498 rc = min(rc, w_length);
1499 fsg->ep0req->length = rc; 1499 fsg->ep0req->length = rc;
1500 fsg->ep0req->zero = (rc < w_length && 1500 fsg->ep0req->zero = rc < w_length;
1501 (rc % gadget->ep0->maxpacket) == 0);
1502 fsg->ep0req_name = (ctrl->bRequestType & USB_DIR_IN ? 1501 fsg->ep0req_name = (ctrl->bRequestType & USB_DIR_IN ?
1503 "ep0-in" : "ep0-out"); 1502 "ep0-in" : "ep0-out");
1504 rc = ep0_queue(fsg); 1503 rc = ep0_queue(fsg);
diff --git a/drivers/usb/gadget/inode.c b/drivers/usb/gadget/inode.c
index 1e5e6ddef787..020815397a49 100644
--- a/drivers/usb/gadget/inode.c
+++ b/drivers/usb/gadget/inode.c
@@ -417,8 +417,8 @@ ep_read (struct file *fd, char __user *buf, size_t len, loff_t *ptr)
417 goto free1; 417 goto free1;
418 418
419 value = ep_io (data, kbuf, len); 419 value = ep_io (data, kbuf, len);
420 VDEBUG (data->dev, "%s read %d OUT, status %d\n", 420 VDEBUG (data->dev, "%s read %zu OUT, status %d\n",
421 data->name, len, value); 421 data->name, len, (int) value);
422 if (value >= 0 && copy_to_user (buf, kbuf, value)) 422 if (value >= 0 && copy_to_user (buf, kbuf, value))
423 value = -EFAULT; 423 value = -EFAULT;
424 424
@@ -465,8 +465,8 @@ ep_write (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
465 } 465 }
466 466
467 value = ep_io (data, kbuf, len); 467 value = ep_io (data, kbuf, len);
468 VDEBUG (data->dev, "%s write %d IN, status %d\n", 468 VDEBUG (data->dev, "%s write %zu IN, status %d\n",
469 data->name, len, value); 469 data->name, len, (int) value);
470free1: 470free1:
471 up (&data->lock); 471 up (&data->lock);
472 kfree (kbuf); 472 kfree (kbuf);
@@ -1318,8 +1318,8 @@ gadgetfs_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
1318 struct usb_request *req = dev->req; 1318 struct usb_request *req = dev->req;
1319 int value = -EOPNOTSUPP; 1319 int value = -EOPNOTSUPP;
1320 struct usb_gadgetfs_event *event; 1320 struct usb_gadgetfs_event *event;
1321 u16 w_value = ctrl->wValue; 1321 u16 w_value = le16_to_cpu(ctrl->wValue);
1322 u16 w_length = ctrl->wLength; 1322 u16 w_length = le16_to_cpu(ctrl->wLength);
1323 1323
1324 spin_lock (&dev->lock); 1324 spin_lock (&dev->lock);
1325 dev->setup_abort = 0; 1325 dev->setup_abort = 0;
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
index 4d591c764e38..9e4f1c6935a5 100644
--- a/drivers/usb/gadget/serial.c
+++ b/drivers/usb/gadget/serial.c
@@ -300,18 +300,18 @@ static int gs_build_config_buf(u8 *buf, enum usb_device_speed speed,
300 u8 type, unsigned int index, int is_otg); 300 u8 type, unsigned int index, int is_otg);
301 301
302static struct usb_request *gs_alloc_req(struct usb_ep *ep, unsigned int len, 302static struct usb_request *gs_alloc_req(struct usb_ep *ep, unsigned int len,
303 int kmalloc_flags); 303 unsigned kmalloc_flags);
304static void gs_free_req(struct usb_ep *ep, struct usb_request *req); 304static void gs_free_req(struct usb_ep *ep, struct usb_request *req);
305 305
306static struct gs_req_entry *gs_alloc_req_entry(struct usb_ep *ep, unsigned len, 306static struct gs_req_entry *gs_alloc_req_entry(struct usb_ep *ep, unsigned len,
307 int kmalloc_flags); 307 unsigned kmalloc_flags);
308static void gs_free_req_entry(struct usb_ep *ep, struct gs_req_entry *req); 308static void gs_free_req_entry(struct usb_ep *ep, struct gs_req_entry *req);
309 309
310static int gs_alloc_ports(struct gs_dev *dev, int kmalloc_flags); 310static int gs_alloc_ports(struct gs_dev *dev, unsigned kmalloc_flags);
311static void gs_free_ports(struct gs_dev *dev); 311static void gs_free_ports(struct gs_dev *dev);
312 312
313/* circular buffer */ 313/* circular buffer */
314static struct gs_buf *gs_buf_alloc(unsigned int size, int kmalloc_flags); 314static struct gs_buf *gs_buf_alloc(unsigned int size, unsigned kmalloc_flags);
315static void gs_buf_free(struct gs_buf *gb); 315static void gs_buf_free(struct gs_buf *gb);
316static void gs_buf_clear(struct gs_buf *gb); 316static void gs_buf_clear(struct gs_buf *gb);
317static unsigned int gs_buf_data_avail(struct gs_buf *gb); 317static unsigned int gs_buf_data_avail(struct gs_buf *gb);
@@ -1607,9 +1607,9 @@ static int gs_setup(struct usb_gadget *gadget,
1607 int ret = -EOPNOTSUPP; 1607 int ret = -EOPNOTSUPP;
1608 struct gs_dev *dev = get_gadget_data(gadget); 1608 struct gs_dev *dev = get_gadget_data(gadget);
1609 struct usb_request *req = dev->dev_ctrl_req; 1609 struct usb_request *req = dev->dev_ctrl_req;
1610 u16 wIndex = ctrl->wIndex; 1610 u16 wIndex = le16_to_cpu(ctrl->wIndex);
1611 u16 wValue = ctrl->wValue; 1611 u16 wValue = le16_to_cpu(ctrl->wValue);
1612 u16 wLength = ctrl->wLength; 1612 u16 wLength = le16_to_cpu(ctrl->wLength);
1613 1613
1614 switch (ctrl->bRequestType & USB_TYPE_MASK) { 1614 switch (ctrl->bRequestType & USB_TYPE_MASK) {
1615 case USB_TYPE_STANDARD: 1615 case USB_TYPE_STANDARD:
@@ -1651,9 +1651,9 @@ static int gs_setup_standard(struct usb_gadget *gadget,
1651 int ret = -EOPNOTSUPP; 1651 int ret = -EOPNOTSUPP;
1652 struct gs_dev *dev = get_gadget_data(gadget); 1652 struct gs_dev *dev = get_gadget_data(gadget);
1653 struct usb_request *req = dev->dev_ctrl_req; 1653 struct usb_request *req = dev->dev_ctrl_req;
1654 u16 wIndex = ctrl->wIndex; 1654 u16 wIndex = le16_to_cpu(ctrl->wIndex);
1655 u16 wValue = ctrl->wValue; 1655 u16 wValue = le16_to_cpu(ctrl->wValue);
1656 u16 wLength = ctrl->wLength; 1656 u16 wLength = le16_to_cpu(ctrl->wLength);
1657 1657
1658 switch (ctrl->bRequest) { 1658 switch (ctrl->bRequest) {
1659 case USB_REQ_GET_DESCRIPTOR: 1659 case USB_REQ_GET_DESCRIPTOR:
@@ -1782,9 +1782,9 @@ static int gs_setup_class(struct usb_gadget *gadget,
1782 struct gs_dev *dev = get_gadget_data(gadget); 1782 struct gs_dev *dev = get_gadget_data(gadget);
1783 struct gs_port *port = dev->dev_port[0]; /* ACM only has one port */ 1783 struct gs_port *port = dev->dev_port[0]; /* ACM only has one port */
1784 struct usb_request *req = dev->dev_ctrl_req; 1784 struct usb_request *req = dev->dev_ctrl_req;
1785 u16 wIndex = ctrl->wIndex; 1785 u16 wIndex = le16_to_cpu(ctrl->wIndex);
1786 u16 wValue = ctrl->wValue; 1786 u16 wValue = le16_to_cpu(ctrl->wValue);
1787 u16 wLength = ctrl->wLength; 1787 u16 wLength = le16_to_cpu(ctrl->wLength);
1788 1788
1789 switch (ctrl->bRequest) { 1789 switch (ctrl->bRequest) {
1790 case USB_CDC_REQ_SET_LINE_CODING: 1790 case USB_CDC_REQ_SET_LINE_CODING:
@@ -2119,7 +2119,8 @@ static int gs_build_config_buf(u8 *buf, enum usb_device_speed speed,
2119 * Allocate a usb_request and its buffer. Returns a pointer to the 2119 * Allocate a usb_request and its buffer. Returns a pointer to the
2120 * usb_request or NULL if there is an error. 2120 * usb_request or NULL if there is an error.
2121 */ 2121 */
2122static struct usb_request *gs_alloc_req(struct usb_ep *ep, unsigned int len, int kmalloc_flags) 2122static struct usb_request *
2123gs_alloc_req(struct usb_ep *ep, unsigned int len, unsigned kmalloc_flags)
2123{ 2124{
2124 struct usb_request *req; 2125 struct usb_request *req;
2125 2126
@@ -2159,7 +2160,8 @@ static void gs_free_req(struct usb_ep *ep, struct usb_request *req)
2159 * Allocates a request and its buffer, using the given 2160 * Allocates a request and its buffer, using the given
2160 * endpoint, buffer len, and kmalloc flags. 2161 * endpoint, buffer len, and kmalloc flags.
2161 */ 2162 */
2162static struct gs_req_entry *gs_alloc_req_entry(struct usb_ep *ep, unsigned len, int kmalloc_flags) 2163static struct gs_req_entry *
2164gs_alloc_req_entry(struct usb_ep *ep, unsigned len, unsigned kmalloc_flags)
2163{ 2165{
2164 struct gs_req_entry *req; 2166 struct gs_req_entry *req;
2165 2167
@@ -2200,7 +2202,7 @@ static void gs_free_req_entry(struct usb_ep *ep, struct gs_req_entry *req)
2200 * 2202 *
2201 * The device lock is normally held when calling this function. 2203 * The device lock is normally held when calling this function.
2202 */ 2204 */
2203static int gs_alloc_ports(struct gs_dev *dev, int kmalloc_flags) 2205static int gs_alloc_ports(struct gs_dev *dev, unsigned kmalloc_flags)
2204{ 2206{
2205 int i; 2207 int i;
2206 struct gs_port *port; 2208 struct gs_port *port;
@@ -2282,7 +2284,7 @@ static void gs_free_ports(struct gs_dev *dev)
2282 * 2284 *
2283 * Allocate a circular buffer and all associated memory. 2285 * Allocate a circular buffer and all associated memory.
2284 */ 2286 */
2285static struct gs_buf *gs_buf_alloc(unsigned int size, int kmalloc_flags) 2287static struct gs_buf *gs_buf_alloc(unsigned int size, unsigned kmalloc_flags)
2286{ 2288{
2287 struct gs_buf *gb; 2289 struct gs_buf *gb;
2288 2290
diff --git a/drivers/usb/gadget/zero.c b/drivers/usb/gadget/zero.c
index 6e49432071a1..a6e035e24479 100644
--- a/drivers/usb/gadget/zero.c
+++ b/drivers/usb/gadget/zero.c
@@ -919,9 +919,9 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
919 struct zero_dev *dev = get_gadget_data (gadget); 919 struct zero_dev *dev = get_gadget_data (gadget);
920 struct usb_request *req = dev->req; 920 struct usb_request *req = dev->req;
921 int value = -EOPNOTSUPP; 921 int value = -EOPNOTSUPP;
922 u16 w_index = ctrl->wIndex; 922 u16 w_index = le16_to_cpu(ctrl->wIndex);
923 u16 w_value = ctrl->wValue; 923 u16 w_value = le16_to_cpu(ctrl->wValue);
924 u16 w_length = ctrl->wLength; 924 u16 w_length = le16_to_cpu(ctrl->wLength);
925 925
926 /* usually this stores reply data in the pre-allocated ep0 buffer, 926 /* usually this stores reply data in the pre-allocated ep0 buffer,
927 * but config change events will reconfigure hardware. 927 * but config change events will reconfigure hardware.