aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Brownell <david-b@pacbell.net>2008-05-07 17:24:10 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2008-05-14 13:00:28 -0400
commit2c2d28a015f0dd36c5d1a06e16923e3142574066 (patch)
tree02e64a91ddfb09f899d135a50b4f7003d60a7f3a
parent9079e91b5b5a84836e65cdc9128d2602e3beaef2 (diff)
USB: serial gadget: remove needless data structure
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>
-rw-r--r--drivers/usb/gadget/serial.c85
1 files changed, 13 insertions, 72 deletions
diff --git a/drivers/usb/gadget/serial.c b/drivers/usb/gadget/serial.c
index 00da3f6620a3..b0c32c73aeb6 100644
--- a/drivers/usb/gadget/serial.c
+++ b/drivers/usb/gadget/serial.c
@@ -121,12 +121,6 @@ struct gs_buf {
121 char *buf_put; 121 char *buf_put;
122}; 122};
123 123
124/* list of requests */
125struct gs_req_entry {
126 struct list_head re_entry;
127 struct usb_request *re_req;
128};
129
130/* the port structure holds info for each port, one for each minor number */ 124/* the port structure holds info for each port, one for each minor number */
131struct gs_port { 125struct gs_port {
132 struct gs_dev *port_dev; /* pointer to device struct */ 126 struct gs_dev *port_dev; /* pointer to device struct */
@@ -185,10 +179,6 @@ static struct usb_request *gs_alloc_req(struct usb_ep *ep, unsigned int len,
185 gfp_t kmalloc_flags); 179 gfp_t kmalloc_flags);
186static void gs_free_req(struct usb_ep *ep, struct usb_request *req); 180static void gs_free_req(struct usb_ep *ep, struct usb_request *req);
187 181
188static struct gs_req_entry *gs_alloc_req_entry(struct usb_ep *ep, unsigned len,
189 gfp_t kmalloc_flags);
190static void gs_free_req_entry(struct usb_ep *ep, struct gs_req_entry *req);
191
192static int gs_alloc_ports(struct gs_dev *dev, gfp_t kmalloc_flags); 182static int gs_alloc_ports(struct gs_dev *dev, gfp_t kmalloc_flags);
193static void gs_free_ports(struct gs_dev *dev); 183static void gs_free_ports(struct gs_dev *dev);
194 184
@@ -966,7 +956,6 @@ static int gs_send(struct gs_dev *dev)
966 unsigned long flags; 956 unsigned long flags;
967 struct usb_ep *ep; 957 struct usb_ep *ep;
968 struct usb_request *req; 958 struct usb_request *req;
969 struct gs_req_entry *req_entry;
970 959
971 if (dev == NULL) { 960 if (dev == NULL) {
972 pr_err("gs_send: NULL device pointer\n"); 961 pr_err("gs_send: NULL device pointer\n");
@@ -979,10 +968,8 @@ static int gs_send(struct gs_dev *dev)
979 968
980 while(!list_empty(&dev->dev_req_list)) { 969 while(!list_empty(&dev->dev_req_list)) {
981 970
982 req_entry = list_entry(dev->dev_req_list.next, 971 req = list_entry(dev->dev_req_list.next,
983 struct gs_req_entry, re_entry); 972 struct usb_request, list);
984
985 req = req_entry->re_req;
986 973
987 len = gs_send_packet(dev, req->buf, ep->maxpacket); 974 len = gs_send_packet(dev, req->buf, ep->maxpacket);
988 975
@@ -992,7 +979,7 @@ static int gs_send(struct gs_dev *dev)
992 *((unsigned char *)req->buf), 979 *((unsigned char *)req->buf),
993 *((unsigned char *)req->buf+1), 980 *((unsigned char *)req->buf+1),
994 *((unsigned char *)req->buf+2)); 981 *((unsigned char *)req->buf+2));
995 list_del(&req_entry->re_entry); 982 list_del(&req->list);
996 req->length = len; 983 req->length = len;
997 spin_unlock_irqrestore(&dev->dev_lock, flags); 984 spin_unlock_irqrestore(&dev->dev_lock, flags);
998 if ((ret=usb_ep_queue(ep, req, GFP_ATOMIC))) { 985 if ((ret=usb_ep_queue(ep, req, GFP_ATOMIC))) {
@@ -1175,7 +1162,6 @@ requeue:
1175static void gs_write_complete(struct usb_ep *ep, struct usb_request *req) 1162static void gs_write_complete(struct usb_ep *ep, struct usb_request *req)
1176{ 1163{
1177 struct gs_dev *dev = ep->driver_data; 1164 struct gs_dev *dev = ep->driver_data;
1178 struct gs_req_entry *gs_req = req->context;
1179 1165
1180 if (dev == NULL) { 1166 if (dev == NULL) {
1181 pr_err("gs_write_complete: NULL device pointer\n"); 1167 pr_err("gs_write_complete: NULL device pointer\n");
@@ -1186,13 +1172,8 @@ static void gs_write_complete(struct usb_ep *ep, struct usb_request *req)
1186 case 0: 1172 case 0:
1187 /* normal completion */ 1173 /* normal completion */
1188requeue: 1174requeue:
1189 if (gs_req == NULL) {
1190 pr_err("gs_write_complete: NULL request pointer\n");
1191 return;
1192 }
1193
1194 spin_lock(&dev->dev_lock); 1175 spin_lock(&dev->dev_lock);
1195 list_add(&gs_req->re_entry, &dev->dev_req_list); 1176 list_add(&req->list, &dev->dev_req_list);
1196 spin_unlock(&dev->dev_lock); 1177 spin_unlock(&dev->dev_lock);
1197 1178
1198 gs_send(dev); 1179 gs_send(dev);
@@ -1731,7 +1712,6 @@ static int gs_set_config(struct gs_dev *dev, unsigned config)
1731 struct usb_ep *ep; 1712 struct usb_ep *ep;
1732 struct usb_endpoint_descriptor *ep_desc; 1713 struct usb_endpoint_descriptor *ep_desc;
1733 struct usb_request *req; 1714 struct usb_request *req;
1734 struct gs_req_entry *req_entry;
1735 1715
1736 if (dev == NULL) { 1716 if (dev == NULL) {
1737 pr_err("gs_set_config: NULL device pointer\n"); 1717 pr_err("gs_set_config: NULL device pointer\n");
@@ -1843,9 +1823,10 @@ static int gs_set_config(struct gs_dev *dev, unsigned config)
1843 /* allocate write requests, and put on free list */ 1823 /* allocate write requests, and put on free list */
1844 ep = dev->dev_in_ep; 1824 ep = dev->dev_in_ep;
1845 for (i=0; i<write_q_size; i++) { 1825 for (i=0; i<write_q_size; i++) {
1846 if ((req_entry=gs_alloc_req_entry(ep, ep->maxpacket, GFP_ATOMIC))) { 1826 req = gs_alloc_req(ep, ep->maxpacket, GFP_ATOMIC);
1847 req_entry->re_req->complete = gs_write_complete; 1827 if (req) {
1848 list_add(&req_entry->re_entry, &dev->dev_req_list); 1828 req->complete = gs_write_complete;
1829 list_add(&req->list, &dev->dev_req_list);
1849 } else { 1830 } else {
1850 pr_err("gs_set_config: cannot allocate " 1831 pr_err("gs_set_config: cannot allocate "
1851 "write requests\n"); 1832 "write requests\n");
@@ -1883,7 +1864,7 @@ exit_reset_config:
1883 */ 1864 */
1884static void gs_reset_config(struct gs_dev *dev) 1865static void gs_reset_config(struct gs_dev *dev)
1885{ 1866{
1886 struct gs_req_entry *req_entry; 1867 struct usb_request *req;
1887 1868
1888 if (dev == NULL) { 1869 if (dev == NULL) {
1889 pr_err("gs_reset_config: NULL device pointer\n"); 1870 pr_err("gs_reset_config: NULL device pointer\n");
@@ -1897,10 +1878,10 @@ static void gs_reset_config(struct gs_dev *dev)
1897 1878
1898 /* free write requests on the free list */ 1879 /* free write requests on the free list */
1899 while(!list_empty(&dev->dev_req_list)) { 1880 while(!list_empty(&dev->dev_req_list)) {
1900 req_entry = list_entry(dev->dev_req_list.next, 1881 req = list_entry(dev->dev_req_list.next,
1901 struct gs_req_entry, re_entry); 1882 struct usb_request, list);
1902 list_del(&req_entry->re_entry); 1883 list_del(&req->list);
1903 gs_free_req_entry(dev->dev_in_ep, req_entry); 1884 gs_free_req(dev->dev_in_ep, req);
1904 } 1885 }
1905 1886
1906 /* disable endpoints, forcing completion of pending i/o; */ 1887 /* disable endpoints, forcing completion of pending i/o; */
@@ -2010,46 +1991,6 @@ static void gs_free_req(struct usb_ep *ep, struct usb_request *req)
2010} 1991}
2011 1992
2012/* 1993/*
2013 * gs_alloc_req_entry
2014 *
2015 * Allocates a request and its buffer, using the given
2016 * endpoint, buffer len, and kmalloc flags.
2017 */
2018static struct gs_req_entry *
2019gs_alloc_req_entry(struct usb_ep *ep, unsigned len, gfp_t kmalloc_flags)
2020{
2021 struct gs_req_entry *req;
2022
2023 req = kmalloc(sizeof(struct gs_req_entry), kmalloc_flags);
2024 if (req == NULL)
2025 return NULL;
2026
2027 req->re_req = gs_alloc_req(ep, len, kmalloc_flags);
2028 if (req->re_req == NULL) {
2029 kfree(req);
2030 return NULL;
2031 }
2032
2033 req->re_req->context = req;
2034
2035 return req;
2036}
2037
2038/*
2039 * gs_free_req_entry
2040 *
2041 * Frees a request and its buffer.
2042 */
2043static void gs_free_req_entry(struct usb_ep *ep, struct gs_req_entry *req)
2044{
2045 if (ep != NULL && req != NULL) {
2046 if (req->re_req != NULL)
2047 gs_free_req(ep, req->re_req);
2048 kfree(req);
2049 }
2050}
2051
2052/*
2053 * gs_alloc_ports 1994 * gs_alloc_ports
2054 * 1995 *
2055 * Allocate all ports and set the gs_dev struct to point to them. 1996 * Allocate all ports and set the gs_dev struct to point to them.