Commit 1bbc1696 authored by David Brownell's avatar David Brownell Committed by Greg Kroah-Hartman

[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: default avatarDavid Brownell <dbrownell@users.sourceforge.net>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 028b271b
...@@ -1267,9 +1267,6 @@ static void dummy_timer (unsigned long _dum) ...@@ -1267,9 +1267,6 @@ static void dummy_timer (unsigned long _dum)
struct dummy_ep *ep2; struct dummy_ep *ep2;
setup = *(struct usb_ctrlrequest*) urb->setup_packet; setup = *(struct usb_ctrlrequest*) urb->setup_packet;
le16_to_cpus (&setup.wIndex);
le16_to_cpus (&setup.wValue);
le16_to_cpus (&setup.wLength);
if (setup.wLength != urb->transfer_buffer_length) { if (setup.wLength != urb->transfer_buffer_length) {
maybe_set_status (urb, -EOVERFLOW); maybe_set_status (urb, -EOVERFLOW);
goto return_urb; goto return_urb;
......
...@@ -1277,9 +1277,9 @@ eth_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) ...@@ -1277,9 +1277,9 @@ eth_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
struct eth_dev *dev = get_gadget_data (gadget); struct eth_dev *dev = get_gadget_data (gadget);
struct usb_request *req = dev->req; struct usb_request *req = dev->req;
int value = -EOPNOTSUPP; int value = -EOPNOTSUPP;
u16 wIndex = (__force u16) ctrl->wIndex; u16 wIndex = le16_to_cpu(ctrl->wIndex);
u16 wValue = (__force u16) ctrl->wValue; u16 wValue = le16_to_cpu(ctrl->wValue);
u16 wLength = (__force u16) ctrl->wLength; u16 wLength = le16_to_cpu(ctrl->wLength);
/* descriptors just go into the pre-allocated ep0 buffer, /* descriptors just go into the pre-allocated ep0 buffer,
* while config change events may enable network traffic. * while config change events may enable network traffic.
......
...@@ -819,7 +819,7 @@ static void inline put_be32(u8 *buf, u32 val) ...@@ -819,7 +819,7 @@ static void inline put_be32(u8 *buf, u32 val)
buf[0] = val >> 24; buf[0] = val >> 24;
buf[1] = val >> 16; buf[1] = val >> 16;
buf[2] = val >> 8; buf[2] = val >> 8;
buf[3] = val; buf[3] = val & 0xff;
} }
...@@ -1277,8 +1277,8 @@ static int class_setup_req(struct fsg_dev *fsg, ...@@ -1277,8 +1277,8 @@ static int class_setup_req(struct fsg_dev *fsg,
{ {
struct usb_request *req = fsg->ep0req; struct usb_request *req = fsg->ep0req;
int value = -EOPNOTSUPP; int value = -EOPNOTSUPP;
u16 w_index = ctrl->wIndex; u16 w_index = le16_to_cpu(ctrl->wIndex);
u16 w_length = ctrl->wLength; u16 w_length = le16_to_cpu(ctrl->wLength);
if (!fsg->config) if (!fsg->config)
return value; return value;
...@@ -1345,7 +1345,7 @@ static int class_setup_req(struct fsg_dev *fsg, ...@@ -1345,7 +1345,7 @@ static int class_setup_req(struct fsg_dev *fsg,
"unknown class-specific control req " "unknown class-specific control req "
"%02x.%02x v%04x i%04x l%u\n", "%02x.%02x v%04x i%04x l%u\n",
ctrl->bRequestType, ctrl->bRequest, ctrl->bRequestType, ctrl->bRequest,
ctrl->wValue, w_index, w_length); le16_to_cpu(ctrl->wValue), w_index, w_length);
return value; return value;
} }
...@@ -1359,8 +1359,8 @@ static int standard_setup_req(struct fsg_dev *fsg, ...@@ -1359,8 +1359,8 @@ static int standard_setup_req(struct fsg_dev *fsg,
{ {
struct usb_request *req = fsg->ep0req; struct usb_request *req = fsg->ep0req;
int value = -EOPNOTSUPP; int value = -EOPNOTSUPP;
u16 w_index = ctrl->wIndex; u16 w_index = le16_to_cpu(ctrl->wIndex);
u16 w_value = ctrl->wValue; u16 w_value = le16_to_cpu(ctrl->wValue);
/* Usually this just stores reply data in the pre-allocated ep0 buffer, /* Usually this just stores reply data in the pre-allocated ep0 buffer,
* but config change events will also reconfigure hardware. */ * but config change events will also reconfigure hardware. */
...@@ -1469,7 +1469,7 @@ static int standard_setup_req(struct fsg_dev *fsg, ...@@ -1469,7 +1469,7 @@ static int standard_setup_req(struct fsg_dev *fsg,
VDBG(fsg, VDBG(fsg,
"unknown control req %02x.%02x v%04x i%04x l%u\n", "unknown control req %02x.%02x v%04x i%04x l%u\n",
ctrl->bRequestType, ctrl->bRequest, ctrl->bRequestType, ctrl->bRequest,
w_value, w_index, ctrl->wLength); w_value, w_index, le16_to_cpu(ctrl->wLength));
} }
return value; return value;
...@@ -1481,7 +1481,7 @@ static int fsg_setup(struct usb_gadget *gadget, ...@@ -1481,7 +1481,7 @@ static int fsg_setup(struct usb_gadget *gadget,
{ {
struct fsg_dev *fsg = get_gadget_data(gadget); struct fsg_dev *fsg = get_gadget_data(gadget);
int rc; int rc;
int w_length = ctrl->wLength; int w_length = le16_to_cpu(ctrl->wLength);
++fsg->ep0_req_tag; // Record arrival of a new request ++fsg->ep0_req_tag; // Record arrival of a new request
fsg->ep0req->context = NULL; fsg->ep0req->context = NULL;
...@@ -1497,8 +1497,7 @@ static int fsg_setup(struct usb_gadget *gadget, ...@@ -1497,8 +1497,7 @@ static int fsg_setup(struct usb_gadget *gadget,
if (rc >= 0 && rc != DELAYED_STATUS) { if (rc >= 0 && rc != DELAYED_STATUS) {
rc = min(rc, w_length); rc = min(rc, w_length);
fsg->ep0req->length = rc; fsg->ep0req->length = rc;
fsg->ep0req->zero = (rc < w_length && fsg->ep0req->zero = rc < w_length;
(rc % gadget->ep0->maxpacket) == 0);
fsg->ep0req_name = (ctrl->bRequestType & USB_DIR_IN ? fsg->ep0req_name = (ctrl->bRequestType & USB_DIR_IN ?
"ep0-in" : "ep0-out"); "ep0-in" : "ep0-out");
rc = ep0_queue(fsg); rc = ep0_queue(fsg);
......
...@@ -417,8 +417,8 @@ ep_read (struct file *fd, char __user *buf, size_t len, loff_t *ptr) ...@@ -417,8 +417,8 @@ ep_read (struct file *fd, char __user *buf, size_t len, loff_t *ptr)
goto free1; goto free1;
value = ep_io (data, kbuf, len); value = ep_io (data, kbuf, len);
VDEBUG (data->dev, "%s read %d OUT, status %d\n", VDEBUG (data->dev, "%s read %zu OUT, status %d\n",
data->name, len, value); data->name, len, (int) value);
if (value >= 0 && copy_to_user (buf, kbuf, value)) if (value >= 0 && copy_to_user (buf, kbuf, value))
value = -EFAULT; value = -EFAULT;
...@@ -465,8 +465,8 @@ ep_write (struct file *fd, const char __user *buf, size_t len, loff_t *ptr) ...@@ -465,8 +465,8 @@ ep_write (struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
} }
value = ep_io (data, kbuf, len); value = ep_io (data, kbuf, len);
VDEBUG (data->dev, "%s write %d IN, status %d\n", VDEBUG (data->dev, "%s write %zu IN, status %d\n",
data->name, len, value); data->name, len, (int) value);
free1: free1:
up (&data->lock); up (&data->lock);
kfree (kbuf); kfree (kbuf);
...@@ -1318,8 +1318,8 @@ gadgetfs_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) ...@@ -1318,8 +1318,8 @@ gadgetfs_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
struct usb_request *req = dev->req; struct usb_request *req = dev->req;
int value = -EOPNOTSUPP; int value = -EOPNOTSUPP;
struct usb_gadgetfs_event *event; struct usb_gadgetfs_event *event;
u16 w_value = ctrl->wValue; u16 w_value = le16_to_cpu(ctrl->wValue);
u16 w_length = ctrl->wLength; u16 w_length = le16_to_cpu(ctrl->wLength);
spin_lock (&dev->lock); spin_lock (&dev->lock);
dev->setup_abort = 0; dev->setup_abort = 0;
......
...@@ -300,18 +300,18 @@ static int gs_build_config_buf(u8 *buf, enum usb_device_speed speed, ...@@ -300,18 +300,18 @@ static int gs_build_config_buf(u8 *buf, enum usb_device_speed speed,
u8 type, unsigned int index, int is_otg); u8 type, unsigned int index, int is_otg);
static struct usb_request *gs_alloc_req(struct usb_ep *ep, unsigned int len, static struct usb_request *gs_alloc_req(struct usb_ep *ep, unsigned int len,
int kmalloc_flags); unsigned kmalloc_flags);
static void gs_free_req(struct usb_ep *ep, struct usb_request *req); static void gs_free_req(struct usb_ep *ep, struct usb_request *req);
static struct gs_req_entry *gs_alloc_req_entry(struct usb_ep *ep, unsigned len, static struct gs_req_entry *gs_alloc_req_entry(struct usb_ep *ep, unsigned len,
int kmalloc_flags); unsigned kmalloc_flags);
static void gs_free_req_entry(struct usb_ep *ep, struct gs_req_entry *req); static void gs_free_req_entry(struct usb_ep *ep, struct gs_req_entry *req);
static int gs_alloc_ports(struct gs_dev *dev, int kmalloc_flags); static int gs_alloc_ports(struct gs_dev *dev, unsigned kmalloc_flags);
static void gs_free_ports(struct gs_dev *dev); static void gs_free_ports(struct gs_dev *dev);
/* circular buffer */ /* circular buffer */
static struct gs_buf *gs_buf_alloc(unsigned int size, int kmalloc_flags); static struct gs_buf *gs_buf_alloc(unsigned int size, unsigned kmalloc_flags);
static void gs_buf_free(struct gs_buf *gb); static void gs_buf_free(struct gs_buf *gb);
static void gs_buf_clear(struct gs_buf *gb); static void gs_buf_clear(struct gs_buf *gb);
static unsigned int gs_buf_data_avail(struct gs_buf *gb); static unsigned int gs_buf_data_avail(struct gs_buf *gb);
...@@ -1607,9 +1607,9 @@ static int gs_setup(struct usb_gadget *gadget, ...@@ -1607,9 +1607,9 @@ static int gs_setup(struct usb_gadget *gadget,
int ret = -EOPNOTSUPP; int ret = -EOPNOTSUPP;
struct gs_dev *dev = get_gadget_data(gadget); struct gs_dev *dev = get_gadget_data(gadget);
struct usb_request *req = dev->dev_ctrl_req; struct usb_request *req = dev->dev_ctrl_req;
u16 wIndex = ctrl->wIndex; u16 wIndex = le16_to_cpu(ctrl->wIndex);
u16 wValue = ctrl->wValue; u16 wValue = le16_to_cpu(ctrl->wValue);
u16 wLength = ctrl->wLength; u16 wLength = le16_to_cpu(ctrl->wLength);
switch (ctrl->bRequestType & USB_TYPE_MASK) { switch (ctrl->bRequestType & USB_TYPE_MASK) {
case USB_TYPE_STANDARD: case USB_TYPE_STANDARD:
...@@ -1651,9 +1651,9 @@ static int gs_setup_standard(struct usb_gadget *gadget, ...@@ -1651,9 +1651,9 @@ static int gs_setup_standard(struct usb_gadget *gadget,
int ret = -EOPNOTSUPP; int ret = -EOPNOTSUPP;
struct gs_dev *dev = get_gadget_data(gadget); struct gs_dev *dev = get_gadget_data(gadget);
struct usb_request *req = dev->dev_ctrl_req; struct usb_request *req = dev->dev_ctrl_req;
u16 wIndex = ctrl->wIndex; u16 wIndex = le16_to_cpu(ctrl->wIndex);
u16 wValue = ctrl->wValue; u16 wValue = le16_to_cpu(ctrl->wValue);
u16 wLength = ctrl->wLength; u16 wLength = le16_to_cpu(ctrl->wLength);
switch (ctrl->bRequest) { switch (ctrl->bRequest) {
case USB_REQ_GET_DESCRIPTOR: case USB_REQ_GET_DESCRIPTOR:
...@@ -1782,9 +1782,9 @@ static int gs_setup_class(struct usb_gadget *gadget, ...@@ -1782,9 +1782,9 @@ static int gs_setup_class(struct usb_gadget *gadget,
struct gs_dev *dev = get_gadget_data(gadget); struct gs_dev *dev = get_gadget_data(gadget);
struct gs_port *port = dev->dev_port[0]; /* ACM only has one port */ struct gs_port *port = dev->dev_port[0]; /* ACM only has one port */
struct usb_request *req = dev->dev_ctrl_req; struct usb_request *req = dev->dev_ctrl_req;
u16 wIndex = ctrl->wIndex; u16 wIndex = le16_to_cpu(ctrl->wIndex);
u16 wValue = ctrl->wValue; u16 wValue = le16_to_cpu(ctrl->wValue);
u16 wLength = ctrl->wLength; u16 wLength = le16_to_cpu(ctrl->wLength);
switch (ctrl->bRequest) { switch (ctrl->bRequest) {
case USB_CDC_REQ_SET_LINE_CODING: 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,7 +2119,8 @@ static int gs_build_config_buf(u8 *buf, enum usb_device_speed speed,
* Allocate a usb_request and its buffer. Returns a pointer to the * Allocate a usb_request and its buffer. Returns a pointer to the
* usb_request or NULL if there is an error. * usb_request or NULL if there is an error.
*/ */
static struct usb_request *gs_alloc_req(struct usb_ep *ep, unsigned int len, int kmalloc_flags) static struct usb_request *
gs_alloc_req(struct usb_ep *ep, unsigned int len, unsigned kmalloc_flags)
{ {
struct usb_request *req; struct usb_request *req;
...@@ -2159,7 +2160,8 @@ static void gs_free_req(struct usb_ep *ep, struct usb_request *req) ...@@ -2159,7 +2160,8 @@ static void gs_free_req(struct usb_ep *ep, struct usb_request *req)
* Allocates a request and its buffer, using the given * Allocates a request and its buffer, using the given
* endpoint, buffer len, and kmalloc flags. * endpoint, buffer len, and kmalloc flags.
*/ */
static struct gs_req_entry *gs_alloc_req_entry(struct usb_ep *ep, unsigned len, int kmalloc_flags) static struct gs_req_entry *
gs_alloc_req_entry(struct usb_ep *ep, unsigned len, unsigned kmalloc_flags)
{ {
struct gs_req_entry *req; struct gs_req_entry *req;
...@@ -2200,7 +2202,7 @@ static void gs_free_req_entry(struct usb_ep *ep, struct gs_req_entry *req) ...@@ -2200,7 +2202,7 @@ static void gs_free_req_entry(struct usb_ep *ep, struct gs_req_entry *req)
* *
* The device lock is normally held when calling this function. * The device lock is normally held when calling this function.
*/ */
static int gs_alloc_ports(struct gs_dev *dev, int kmalloc_flags) static int gs_alloc_ports(struct gs_dev *dev, unsigned kmalloc_flags)
{ {
int i; int i;
struct gs_port *port; struct gs_port *port;
...@@ -2282,7 +2284,7 @@ static void gs_free_ports(struct gs_dev *dev) ...@@ -2282,7 +2284,7 @@ static void gs_free_ports(struct gs_dev *dev)
* *
* Allocate a circular buffer and all associated memory. * Allocate a circular buffer and all associated memory.
*/ */
static struct gs_buf *gs_buf_alloc(unsigned int size, int kmalloc_flags) static struct gs_buf *gs_buf_alloc(unsigned int size, unsigned kmalloc_flags)
{ {
struct gs_buf *gb; struct gs_buf *gb;
......
...@@ -919,9 +919,9 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl) ...@@ -919,9 +919,9 @@ zero_setup (struct usb_gadget *gadget, const struct usb_ctrlrequest *ctrl)
struct zero_dev *dev = get_gadget_data (gadget); struct zero_dev *dev = get_gadget_data (gadget);
struct usb_request *req = dev->req; struct usb_request *req = dev->req;
int value = -EOPNOTSUPP; int value = -EOPNOTSUPP;
u16 w_index = ctrl->wIndex; u16 w_index = le16_to_cpu(ctrl->wIndex);
u16 w_value = ctrl->wValue; u16 w_value = le16_to_cpu(ctrl->wValue);
u16 w_length = ctrl->wLength; u16 w_length = le16_to_cpu(ctrl->wLength);
/* usually this stores reply data in the pre-allocated ep0 buffer, /* usually this stores reply data in the pre-allocated ep0 buffer,
* but config change events will reconfigure hardware. * but config change events will reconfigure hardware.
......
...@@ -711,7 +711,7 @@ usb_gadget_disconnect (struct usb_gadget *gadget) ...@@ -711,7 +711,7 @@ usb_gadget_disconnect (struct usb_gadget *gadget)
* the hardware level driver. Most calls must be handled by * the hardware level driver. Most calls must be handled by
* the gadget driver, including descriptor and configuration * the gadget driver, including descriptor and configuration
* management. The 16 bit members of the setup data are in * management. The 16 bit members of the setup data are in
* cpu order. Called in_interrupt; this may not sleep. Driver * USB byte order. Called in_interrupt; this may not sleep. Driver
* queues a response to ep0, or returns negative to stall. * queues a response to ep0, or returns negative to stall.
* @disconnect: Invoked after all transfers have been stopped, * @disconnect: Invoked after all transfers have been stopped,
* when the host is disconnected. May be called in_interrupt; this * when the host is disconnected. May be called in_interrupt; this
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment