Skip to content

Commit

Permalink
USB: serial gadget: remove needless data structure
Browse files Browse the repository at this point in the history
This removes a needless data structure from the serial gadget code;
it's a small code shrink, and a larger data shrink.

Since "struct usb_request" already has a "struct list_head" reserved
for use by gadget drivers, the serial gadget code doesn't need to
allocate wrapper structs to hold that list ... it can (and should!)
just use the list_head provided for that exact use.

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Cc: Al Borchers <alborchers@steinerpoint.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
David Brownell authored and Greg Kroah-Hartman committed May 14, 2008
1 parent 9079e91 commit 2c2d28a
Showing 1 changed file with 13 additions and 72 deletions.
85 changes: 13 additions & 72 deletions drivers/usb/gadget/serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,6 @@ struct gs_buf {
char *buf_put;
};

/* list of requests */
struct gs_req_entry {
struct list_head re_entry;
struct usb_request *re_req;
};

/* the port structure holds info for each port, one for each minor number */
struct gs_port {
struct gs_dev *port_dev; /* pointer to device struct */
Expand Down Expand Up @@ -185,10 +179,6 @@ static struct usb_request *gs_alloc_req(struct usb_ep *ep, unsigned int len,
gfp_t kmalloc_flags);
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,
gfp_t kmalloc_flags);
static void gs_free_req_entry(struct usb_ep *ep, struct gs_req_entry *req);

static int gs_alloc_ports(struct gs_dev *dev, gfp_t kmalloc_flags);
static void gs_free_ports(struct gs_dev *dev);

Expand Down Expand Up @@ -966,7 +956,6 @@ static int gs_send(struct gs_dev *dev)
unsigned long flags;
struct usb_ep *ep;
struct usb_request *req;
struct gs_req_entry *req_entry;

if (dev == NULL) {
pr_err("gs_send: NULL device pointer\n");
Expand All @@ -979,10 +968,8 @@ static int gs_send(struct gs_dev *dev)

while(!list_empty(&dev->dev_req_list)) {

req_entry = list_entry(dev->dev_req_list.next,
struct gs_req_entry, re_entry);

req = req_entry->re_req;
req = list_entry(dev->dev_req_list.next,
struct usb_request, list);

len = gs_send_packet(dev, req->buf, ep->maxpacket);

Expand All @@ -992,7 +979,7 @@ static int gs_send(struct gs_dev *dev)
*((unsigned char *)req->buf),
*((unsigned char *)req->buf+1),
*((unsigned char *)req->buf+2));
list_del(&req_entry->re_entry);
list_del(&req->list);
req->length = len;
spin_unlock_irqrestore(&dev->dev_lock, flags);
if ((ret=usb_ep_queue(ep, req, GFP_ATOMIC))) {
Expand Down Expand Up @@ -1175,7 +1162,6 @@ static void gs_read_complete(struct usb_ep *ep, struct usb_request *req)
static void gs_write_complete(struct usb_ep *ep, struct usb_request *req)
{
struct gs_dev *dev = ep->driver_data;
struct gs_req_entry *gs_req = req->context;

if (dev == NULL) {
pr_err("gs_write_complete: NULL device pointer\n");
Expand All @@ -1186,13 +1172,8 @@ static void gs_write_complete(struct usb_ep *ep, struct usb_request *req)
case 0:
/* normal completion */
requeue:
if (gs_req == NULL) {
pr_err("gs_write_complete: NULL request pointer\n");
return;
}

spin_lock(&dev->dev_lock);
list_add(&gs_req->re_entry, &dev->dev_req_list);
list_add(&req->list, &dev->dev_req_list);
spin_unlock(&dev->dev_lock);

gs_send(dev);
Expand Down Expand Up @@ -1731,7 +1712,6 @@ static int gs_set_config(struct gs_dev *dev, unsigned config)
struct usb_ep *ep;
struct usb_endpoint_descriptor *ep_desc;
struct usb_request *req;
struct gs_req_entry *req_entry;

if (dev == NULL) {
pr_err("gs_set_config: NULL device pointer\n");
Expand Down Expand Up @@ -1843,9 +1823,10 @@ static int gs_set_config(struct gs_dev *dev, unsigned config)
/* allocate write requests, and put on free list */
ep = dev->dev_in_ep;
for (i=0; i<write_q_size; i++) {
if ((req_entry=gs_alloc_req_entry(ep, ep->maxpacket, GFP_ATOMIC))) {
req_entry->re_req->complete = gs_write_complete;
list_add(&req_entry->re_entry, &dev->dev_req_list);
req = gs_alloc_req(ep, ep->maxpacket, GFP_ATOMIC);
if (req) {
req->complete = gs_write_complete;
list_add(&req->list, &dev->dev_req_list);
} else {
pr_err("gs_set_config: cannot allocate "
"write requests\n");
Expand Down Expand Up @@ -1883,7 +1864,7 @@ static int gs_set_config(struct gs_dev *dev, unsigned config)
*/
static void gs_reset_config(struct gs_dev *dev)
{
struct gs_req_entry *req_entry;
struct usb_request *req;

if (dev == NULL) {
pr_err("gs_reset_config: NULL device pointer\n");
Expand All @@ -1897,10 +1878,10 @@ static void gs_reset_config(struct gs_dev *dev)

/* free write requests on the free list */
while(!list_empty(&dev->dev_req_list)) {
req_entry = list_entry(dev->dev_req_list.next,
struct gs_req_entry, re_entry);
list_del(&req_entry->re_entry);
gs_free_req_entry(dev->dev_in_ep, req_entry);
req = list_entry(dev->dev_req_list.next,
struct usb_request, list);
list_del(&req->list);
gs_free_req(dev->dev_in_ep, req);
}

/* disable endpoints, forcing completion of pending i/o; */
Expand Down Expand Up @@ -2009,46 +1990,6 @@ static void gs_free_req(struct usb_ep *ep, struct usb_request *req)
}
}

/*
* gs_alloc_req_entry
*
* Allocates a request and its buffer, using the given
* endpoint, buffer len, and kmalloc flags.
*/
static struct gs_req_entry *
gs_alloc_req_entry(struct usb_ep *ep, unsigned len, gfp_t kmalloc_flags)
{
struct gs_req_entry *req;

req = kmalloc(sizeof(struct gs_req_entry), kmalloc_flags);
if (req == NULL)
return NULL;

req->re_req = gs_alloc_req(ep, len, kmalloc_flags);
if (req->re_req == NULL) {
kfree(req);
return NULL;
}

req->re_req->context = req;

return req;
}

/*
* gs_free_req_entry
*
* Frees a request and its buffer.
*/
static void gs_free_req_entry(struct usb_ep *ep, struct gs_req_entry *req)
{
if (ep != NULL && req != NULL) {
if (req->re_req != NULL)
gs_free_req(ep, req->re_req);
kfree(req);
}
}

/*
* gs_alloc_ports
*
Expand Down

0 comments on commit 2c2d28a

Please sign in to comment.