usb: Modify existing gadget drivers to use config_ep_by_speed() instead of ep_choose.
Subsystems (2)
PATCH v5 4/5 usb: Modify existing gadget drivers to use config_ep_by_speed() instead of ep_choose.
Remove obsolete functions:
1. ep_choose()
2. usb_find_endpoint()
Signed-off-by Tatyana Brokhman <[email protected]>
--- drivers/usb/gadget/config.c | 25 ------------------ drivers/usb/gadget/f_acm.c | 47 ++++++++++------------------------ drivers/usb/gadget/f_ecm.c | 45 ++++++++++----------------------- drivers/usb/gadget/f_eem.c | 32 ++++++----------------- drivers/usb/gadget/f_hid.c | 19 ++++--------- drivers/usb/gadget/f_loopback.c | 11 +++++--- drivers/usb/gadget/f_mass_storage.c | 34 +++++++++--------------- drivers/usb/gadget/f_obex.c | 32 ++++++----------------- drivers/usb/gadget/f_phonet.c | 12 ++++---- drivers/usb/gadget/f_rndis.c | 45 +++++++++----------------------- drivers/usb/gadget/f_serial.c | 32 ++++++------------------ drivers/usb/gadget/f_sourcesink.c | 8 ++++- drivers/usb/gadget/f_subset.c | 29 ++++----------------- include/linux/usb/composite.h | 15 ----------- include/linux/usb/gadget.h | 6 ---- 15 files changed, 111 insertions(+), 281 deletions(-)
drivers/usb/gadget/config.c +0 -25
@@ -165,28 +165,3 @@ usb_copy_descriptors(struct usb_descriptor_header **src)return ret; } -/** -* usb_find_endpoint - find a copy of an endpoint descriptor -* @src: original vector of descriptors -* @copy: copy of @src -* @match: endpoint descriptor found in @src -* -* This returns the copy of the @match descriptor made for @copy. Its -* intended use is to help remembering the endpoint descriptor to use -* when enabling a given endpoint. -*/ -struct usb_endpoint_descriptor * -usb_find_endpoint ( -struct usb_descriptor_header **src, -struct usb_descriptor_header **copy, -struct usb_endpoint_descriptor *match -) -{ -while (*src) { -if (*src == (void *) match) -return (void *)*copy; - src++; - copy++; - } -return NULL ; -}
drivers/usb/gadget/f_acm.c +14 -33
89 lines not on this page · raw message
drivers/usb/gadget/f_ecm.c +14 -31
83 lines not on this page · raw message
drivers/usb/gadget/f_eem.c +9 -23
@@ -35,17 +35,9 @@* Ethernet link. */ -struct eem_ep_descs { -struct usb_endpoint_descriptor *in; -struct usb_endpoint_descriptor *out; -}; -struct f_eem {struct gether port;u8 ctrl_id; - -struct eem_ep_descs fs; -struct eem_ep_descs hs; };static inline struct f_eem *func_to_eem (struct usb_function *f)
@@ -176,12 +168,16 @@ static int eem_set_alt(struct usb_function *f, unsigned intf, unsigned alt)gether_disconnect (&eem->port); } -if (!eem->port.in_ep->desc) { +if (!eem->port.in_ep->desc || !eem->port.out_ep->desc) {DBG (cdev,"init eem\n" ); - eem->port.in_ep->desc =ep_choose (cdev->gadget, - eem->hs.in, eem->fs.in); - eem->port.out_ep->desc =ep_choose (cdev->gadget, - eem->hs.out, eem->fs.out); +if (config_ep_by_speed (cdev->gadget, f, + eem->port.in_ep) || +config_ep_by_speed (cdev->gadget, f, + eem->port.out_ep)) { + eem->port.in_ep->desc =NULL ; + eem->port.out_ep->desc =NULL ; + goto fail; + } }/* zlps should not occur because zero-length EEM packets
@@ -253,11 +249,6 @@ eem_bind(struct usb_configuration *c, struct usb_function *f)if (!f->descriptors) goto fail; - eem->fs.in =usb_find_endpoint (eem_fs_function, - f->descriptors, &eem_fs_in_desc); - eem->fs.out =usb_find_endpoint (eem_fs_function, - f->descriptors, &eem_fs_out_desc); -/* support all relevant hardware speeds... we expect that when * hardware is dual speed, all bulk-capable endpoints work at * both speeds
@@ -272,11 +263,6 @@ eem_bind(struct usb_configuration *c, struct usb_function *f) f->hs_descriptors =usb_copy_descriptors (eem_hs_function);if (!f->hs_descriptors) goto fail; - - eem->hs.in =usb_find_endpoint (eem_hs_function, - f->hs_descriptors, &eem_hs_in_desc); - eem->hs.out =usb_find_endpoint (eem_hs_function, - f->hs_descriptors, &eem_hs_out_desc); } DBG(cdev, "CDC Ethernet (EEM): %s speed IN/%s OUT/%s\n",
drivers/usb/gadget/f_hid.c +6 -13
@@ -59,8 +59,6 @@ struct f_hidg {struct cdev cdev;struct usb_function func;struct usb_ep *in_ep; -struct usb_endpoint_descriptor *fs_in_ep_desc; -struct usb_endpoint_descriptor *hs_in_ep_desc; };static inline struct f_hidg *func_to_hidg (struct usb_function *f)
@@ -425,8 +423,12 @@ static int hidg_set_alt(struct usb_function *f, unsigned intf, unsigned alt)if (hidg->in_ep->driver_data !=NULL )usb_ep_disable (hidg->in_ep); - hidg->in_ep->desc =ep_choose (f->config->cdev->gadget, - hidg->hs_in_ep_desc, hidg->fs_in_ep_desc); + status =config_ep_by_speed (f->config->cdev->gadget, f, + hidg->in_ep); +if (status) { +ERROR (cdev,"config_ep_by_speed FAILED!\n" ); + goto fail; + } status =usb_ep_enable (hidg->in_ep);if (status <0 ) {ERROR (cdev,"Enable endpoint FAILED!\n" );
@@ -497,21 +499,12 @@ static int __init hidg_bind(struct usb_configuration *c, struct usb_function *f)if (!f->descriptors) goto fail; - hidg->fs_in_ep_desc =usb_find_endpoint (hidg_fs_descriptors, - f->descriptors, - &hidg_fs_in_ep_desc); -if (gadget_is_dualspeed (c->cdev->gadget)) { hidg_hs_in_ep_desc.bEndpointAddress = hidg_fs_in_ep_desc.bEndpointAddress; f->hs_descriptors =usb_copy_descriptors (hidg_hs_descriptors);if (!f->hs_descriptors) goto fail; - hidg->hs_in_ep_desc =usb_find_endpoint (hidg_hs_descriptors, - f->hs_descriptors, - &hidg_hs_in_ep_desc); - }else { - hidg->hs_in_ep_desc =NULL ; }mutex_init (&hidg->lock);
drivers/usb/gadget/f_loopback.c +7 -4
@@ -256,8 +256,9 @@ enable_loopback(struct usb_composite_dev *cdev, struct f_loopback *loop)/* one endpoint writes data back IN to the host */ ep = loop->in_ep; - ep->desc =ep_choose (cdev->gadget, - &hs_loop_source_desc, &fs_loop_source_desc); + result =config_ep_by_speed (cdev->gadget, &(loop->function), ep); +if (result) +return result; result =usb_ep_enable (ep);if (result <0 )return result;
@@ -265,8 +266,10 @@ enable_loopback(struct usb_composite_dev *cdev, struct f_loopback *loop)/* one endpoint just reads OUT packets */ ep = loop->out_ep; - ep->desc =ep_choose (cdev->gadget, - &hs_loop_sink_desc, &fs_loop_sink_desc); + result =config_ep_by_speed (cdev->gadget, &(loop->function), ep); +if (result) + goto fail0; + result =usb_ep_enable (ep);if (result <0 ) { fail0:
drivers/usb/gadget/f_mass_storage.c +13 -21
@@ -2349,19 +2349,6 @@ static int get_next_command(struct fsg_common *common)/*-------------------------------------------------------------------------*/ -static int enable_endpoint (struct fsg_common *common,struct usb_ep *ep, -const struct usb_endpoint_descriptor *d) -{ -int rc; - - ep->driver_data = common; - ep->desc = (struct usb_endpoint_descriptor *)d; - rc =usb_ep_enable (ep); -if (rc) -ERROR (common,"can't enable %s, result %d\n" , ep->name, rc); -return rc; -} -static int alloc_request (struct fsg_common *common,struct usb_ep *ep,struct usb_request **preq) {
@@ -2375,7 +2362,6 @@ static int alloc_request(struct fsg_common *common, struct usb_ep *ep,/* Reset interface setting and re-init endpoint state (toggle etc). */ static int do_set_interface (struct fsg_common *common,struct fsg_dev *new_fsg) { -const struct usb_endpoint_descriptor *d;struct fsg_dev *fsg;int i, rc =0 ;
@@ -2422,20 +2408,26 @@ reset: fsg = common->fsg;/* Enable the endpoints */ - d =fsg_ep_desc (common->gadget, - &fsg_fs_bulk_in_desc, &fsg_hs_bulk_in_desc); - rc =enable_endpoint (common, fsg->bulk_in, d); + rc =config_ep_by_speed (common->gadget, &(fsg->function), fsg->bulk_in); +if (rc) + goto reset; + rc =usb_ep_enable (fsg->bulk_in);if (rc) goto reset; + fsg->bulk_in->driver_data = common; fsg->bulk_in_enabled =1 ; - d =fsg_ep_desc (common->gadget, - &fsg_fs_bulk_out_desc, &fsg_hs_bulk_out_desc); - rc =enable_endpoint (common, fsg->bulk_out, d); + rc =config_ep_by_speed (common->gadget, &(fsg->function), + fsg->bulk_out); +if (rc) + goto reset; + rc =usb_ep_enable (fsg->bulk_out);if (rc) goto reset; + fsg->bulk_out->driver_data = common; fsg->bulk_out_enabled =1 ; - common->bulk_out_maxpacket =le16_to_cpu (d->wMaxPacketSize); + common->bulk_out_maxpacket = +le16_to_cpu (fsg->bulk_out->desc->wMaxPacketSize);clear_bit (IGNORE_BULK_OUT , &fsg->atomic_bitflags);/* Allocate the requests */
drivers/usb/gadget/f_obex.c +9 -23
@@ -39,20 +39,12 @@* ready to handle the commands. */ -struct obex_ep_descs { -struct usb_endpoint_descriptor *obex_in; -struct usb_endpoint_descriptor *obex_out; -}; -struct f_obex {struct gserial port;u8 ctrl_id;u8 data_id;u8 port_num;u8 can_activate; - -struct obex_ep_descs fs; -struct obex_ep_descs hs; };static inline struct f_obex *func_to_obex (struct usb_function *f)
@@ -227,12 +219,16 @@ static int obex_set_alt(struct usb_function *f, unsigned intf, unsigned alt)gserial_disconnect (&obex->port); } -if (!obex->port.in->desc) { +if (!obex->port.in->desc || !obex->port.out->desc) {DBG (cdev,"init obex ttyGS%d\n" , obex->port_num); - obex->port.in->desc =ep_choose (cdev->gadget, - obex->hs.obex_in, obex->fs.obex_in); - obex->port.out->desc =ep_choose (cdev->gadget, - obex->hs.obex_out, obex->fs.obex_out); +if (config_ep_by_speed (cdev->gadget, f, + obex->port.in) || +config_ep_by_speed (cdev->gadget, f, + obex->port.out)) { + obex->port.out->desc =NULL ; + obex->port.in->desc =NULL ; + goto fail; + } }if (alt ==1 ) {
@@ -346,11 +342,6 @@ obex_bind(struct usb_configuration *c, struct usb_function *f)/* copy descriptors, and track endpoint copies */ f->descriptors =usb_copy_descriptors (fs_function); - obex->fs.obex_in =usb_find_endpoint (fs_function, - f->descriptors, &obex_fs_ep_in_desc); - obex->fs.obex_out =usb_find_endpoint (fs_function, - f->descriptors, &obex_fs_ep_out_desc); -/* support all relevant hardware speeds... we expect that when * hardware is dual speed, all bulk-capable endpoints work at * both speeds
@@ -364,11 +355,6 @@ obex_bind(struct usb_configuration *c, struct usb_function *f)/* copy descriptors, and track endpoint copies */ f->hs_descriptors =usb_copy_descriptors (hs_function); - - obex->hs.obex_in =usb_find_endpoint (hs_function, - f->hs_descriptors, &obex_hs_ep_in_desc); - obex->hs.obex_out =usb_find_endpoint (hs_function, - f->hs_descriptors, &obex_hs_ep_out_desc); }/* Avoid letting this gadget enumerate until the userspace
drivers/usb/gadget/f_phonet.c +6 -6
@@ -424,12 +424,12 @@ static int pn_set_alt(struct usb_function *f, unsigned intf, unsigned alt)if (alt ==1 ) {int i; - fp->out_ep->desc =ep_choose (gadget, - &pn_hs_sink_desc, - &pn_fs_sink_desc); - fp->in_ep->desc =ep_choose (gadget, - &pn_hs_source_desc, - &pn_fs_source_desc); +if (config_ep_by_speed (gadget, f, fp->in_ep) || +config_ep_by_speed (gadget, f, fp->out_ep)) { + fp->in_ep->desc =NULL ; + fp->out_ep->desc =NULL ; +return -EINVAL ; + }usb_ep_enable (fp->out_ep);usb_ep_enable (fp->in_ep);
drivers/usb/gadget/f_rndis.c +13 -32
83 lines not on this page · raw message
drivers/usb/gadget/f_serial.c +8 -24
@@ -27,18 +27,10 @@* if you can arrange appropriate host side drivers. */ -struct gser_descs { -struct usb_endpoint_descriptor *in; -struct usb_endpoint_descriptor *out; -}; -struct f_gser {struct gserial port;u8 data_id;u8 port_num; - -struct gser_descs fs; -struct gser_descs hs; };static inline struct f_gser *func_to_gser (struct usb_function *f)
@@ -136,12 +128,15 @@ static int gser_set_alt(struct usb_function *f, unsigned intf, unsigned alt)if (gser->port.in->driver_data) {DBG (cdev,"reset generic ttyGS%d\n" , gser->port_num);gserial_disconnect (&gser->port); - }else { + } +if (!gser->port.in->desc || !gser->port.out->desc) {DBG (cdev,"activate generic ttyGS%d\n" , gser->port_num); - gser->port.in->desc =ep_choose (cdev->gadget, - gser->hs.in, gser->fs.in); - gser->port.out->desc =ep_choose (cdev->gadget, - gser->hs.out, gser->fs.out); +if (!config_ep_by_speed (cdev->gadget, f, gser->port.in) || + !config_ep_by_speed (cdev->gadget, f, gser->port.out)) { + gser->port.in->desc =NULL ; + gser->port.out->desc =NULL ; +return -EINVAL ; + } }gserial_connect (&gser->port, gser->port_num);return 0 ;
@@ -193,12 +188,6 @@ gser_bind(struct usb_configuration *c, struct usb_function *f)/* copy descriptors, and track endpoint copies */ f->descriptors =usb_copy_descriptors (gser_fs_function); - gser->fs.in =usb_find_endpoint (gser_fs_function, - f->descriptors, &gser_fs_in_desc); - gser->fs.out =usb_find_endpoint (gser_fs_function, - f->descriptors, &gser_fs_out_desc); - -/* support all relevant hardware speeds... we expect that when * hardware is dual speed, all bulk-capable endpoints work at * both speeds
@@ -211,11 +200,6 @@ gser_bind(struct usb_configuration *c, struct usb_function *f)/* copy descriptors, and track endpoint copies */ f->hs_descriptors =usb_copy_descriptors (gser_hs_function); - - gser->hs.in =usb_find_endpoint (gser_hs_function, - f->hs_descriptors, &gser_hs_in_desc); - gser->hs.out =usb_find_endpoint (gser_hs_function, - f->hs_descriptors, &gser_hs_out_desc); } DBG(cdev, "generic ttyGS%d: %s speed IN/%s OUT/%s\n",
drivers/usb/gadget/f_sourcesink.c +6 -2
@@ -347,7 +347,9 @@ enable_source_sink(struct usb_composite_dev *cdev, struct f_sourcesink *ss)/* one endpoint writes (sources) zeroes IN (to the host) */ ep = ss->in_ep; - ep->desc =ep_choose (cdev->gadget, &hs_source_desc, &fs_source_desc); + result =config_ep_by_speed (cdev->gadget, &(ss->function), ep); +if (result) +return result; result =usb_ep_enable (ep);if (result <0 )return result;
@@ -364,7 +366,9 @@ fail:/* one endpoint reads (sinks) anything OUT (from the host) */ ep = ss->out_ep; - ep->desc =ep_choose (cdev->gadget, &hs_sink_desc, &fs_sink_desc); + result =config_ep_by_speed (cdev->gadget, &(ss->function), ep); +if (result) + goto fail; result =usb_ep_enable (ep);if (result <0 ) goto fail;
drivers/usb/gadget/f_subset.c +6 -23
@@ -57,18 +57,10 @@* caring about specific product and vendor IDs. */ -struct geth_descs { -struct usb_endpoint_descriptor *in; -struct usb_endpoint_descriptor *out; -}; -struct f_gether {struct gether port;char ethaddr[14 ]; - -struct geth_descs fs; -struct geth_descs hs; };static inline struct f_gether *func_to_geth (struct usb_function *f)
@@ -243,10 +235,12 @@ static int geth_set_alt(struct usb_function *f, unsigned intf, unsigned alt) }DBG (cdev,"init + activate cdc subset\n" ); - geth->port.in_ep->desc =ep_choose (cdev->gadget, - geth->hs.in, geth->fs.in); - geth->port.out_ep->desc =ep_choose (cdev->gadget, - geth->hs.out, geth->fs.out); +if (config_ep_by_speed (cdev->gadget, f, geth->port.in_ep) || +config_ep_by_speed (cdev->gadget, f, geth->port.out_ep)) { + geth->port.in_ep->desc =NULL ; + geth->port.out_ep->desc =NULL ; +return -EINVAL ; + } net =gether_connect (&geth->port);return IS_ERR (net) ?PTR_ERR (net) :0 ;
@@ -297,12 +291,6 @@ geth_bind(struct usb_configuration *c, struct usb_function *f)/* copy descriptors, and track endpoint copies */ f->descriptors =usb_copy_descriptors (fs_eth_function); - geth->fs.in =usb_find_endpoint (fs_eth_function, - f->descriptors, &fs_subset_in_desc); - geth->fs.out =usb_find_endpoint (fs_eth_function, - f->descriptors, &fs_subset_out_desc); - -/* support all relevant hardware speeds... we expect that when * hardware is dual speed, all bulk-capable endpoints work at * both speeds
@@ -315,11 +303,6 @@ geth_bind(struct usb_configuration *c, struct usb_function *f)/* copy descriptors, and track endpoint copies */ f->hs_descriptors =usb_copy_descriptors (hs_eth_function); - - geth->hs.in =usb_find_endpoint (hs_eth_function, - f->hs_descriptors, &hs_subset_in_desc); - geth->hs.out =usb_find_endpoint (hs_eth_function, - f->hs_descriptors, &hs_subset_out_desc); }/* NOTE: all that is done without knowing or caring about
include/linux/usb/composite.h +0 -15
@@ -158,21 +158,6 @@ int usb_interface_id(struct usb_configuration *, struct usb_function *);int config_ep_by_speed (struct usb_gadget *g,struct usb_function *f,struct usb_ep *_ep); -/** -* ep_choose - select descriptor endpoint at current device speed -* @g: gadget, connected and running at some speed -* @hs: descriptor to use for high speed operation -* @fs: descriptor to use for full or low speed operation -*/ -static inline struct usb_endpoint_descriptor * -ep_choose (struct usb_gadget *g,struct usb_endpoint_descriptor *hs, -struct usb_endpoint_descriptor *fs) -{ -if (gadget_is_dualspeed (g) && g->speed ==USB_SPEED_HIGH ) -return hs; -return fs; -} -#define MAX_CONFIG_INTERFACES 16/* arbitrary; max 255 */ /**
include/linux/usb/gadget.h +0 -6
@@ -871,12 +871,6 @@ int usb_gadget_config_buf(const struct usb_config_descriptor *config,struct usb_descriptor_header **usb_copy_descriptors (struct usb_descriptor_header **); -/* return copy of endpoint descriptor given original descriptor set */ -struct usb_endpoint_descriptor *usb_find_endpoint ( -struct usb_descriptor_header **src, -struct usb_descriptor_header **copy, -struct usb_endpoint_descriptor *match); -/** * usb_free_descriptors - free descriptors returned by usb_copy_descriptors() * @v: vector of descriptors
Signature · 5 lines
1.6.3.3 -- Sent by an employee of the Qualcomm Innovation Center, Inc. The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.