USB: UDC: Fix memory leaks by expanding the API
Subsystems (4)
v4 cover USB: UDC: Fix memory leaks by expanding the API
This series expands the UDC API to fix some long-standing memory leaks in the net2280 and net2272 drivers. And with expanding APIs, it could manage cdns3 and dwc3 gadget device memory better without the hacks at UDC core.
Changes for v4:
- Add Greg and Alan's reviewed-by.
Changes for v3:
- Rebase the latest usb/next, and fix one build error for dwc3 [Patch 5/6]
Alan Stern (3):
USB: UDC: Expand device model API interface
USB: UDC: net2280: Fix memory leaks
USB: UDC: net2272: Fix memory leaks
Peter Chen (3):
usb: cdns3: gadget: fix possible memory leak
usb: dwc3: allocate gadget structure dynamically
Revert "usb: udc: allow adding and removing the same gadget device"
drivers/usb/cdns3/gadget.c | 20 ++++-- drivers/usb/dwc3/core.h | 2 +- drivers/usb/dwc3/ep0.c | 26 ++++---- drivers/usb/dwc3/gadget.c | 108 ++++++++++++++++++------------- drivers/usb/dwc3/gadget.h | 2 +- drivers/usb/gadget/udc/core.c | 79 +++++++++++++++++----- drivers/usb/gadget/udc/net2272.c | 23 ++++--- drivers/usb/gadget/udc/net2272.h | 1 + drivers/usb/gadget/udc/net2280.c | 11 ++-- drivers/usb/gadget/udc/net2280.h | 1 + include/linux/usb/gadget.h | 27 ++++++-- 11 files changed, 199 insertions(+), 101 deletions(-)
Signature · 1 line
2.17.1
PATCH v4 1/6 USB: UDC: Expand device model API interface
From: Alan Stern <[email protected]>
The routines used by the UDC core to interface with the kernel's device model, namely usb_add_gadget_udc(), usb_add_gadget_udc_release(), and usb_del_gadget_udc(), provide access to only a subset of the device model's full API. They include functionality equivalent to device_register() and device_unregister() for gadgets, but they omit device_initialize(), device_add(), device_del(), get_device(), and put_device().
This patch expands the UDC API by adding usb_initialize_gadget(), usb_add_gadget(), usb_del_gadget(), usb_get_gadget(), and usb_put_gadget() to fill in the gap. It rewrites the existing routines to call the new ones.
--- drivers/usb/gadget/udc/core.c | 78 ++++++++++++++++++++++++++++------- include/linux/usb/gadget.h | 27 +++++++++--- 2 files changed, 84 insertions(+), 21 deletions(-)
drivers/usb/gadget/udc/core.c +63 -15
@@ -1164,21 +1164,18 @@ static int check_pending_gadget_drivers(struct usb_udc *udc) }/** -* usb_add_gadget_udc_release - adds a new gadget to the udc class driver list +* usb_initialize_gadget - initialize a gadget and its embedded struct device * @parent: the parent device to this udc. Usually the controller driver's * device. -* @gadget: the gadget to be added to the list. +* @gadget: the gadget to be initialized. * @release: a gadget release function. * * Returns zero on success, negative errno otherwise. * Calls the gadget release function in the latter case. */ -int usb_add_gadget_udc_release (struct device *parent,struct usb_gadget *gadget, +void usb_initialize_gadget (struct device *parent,struct usb_gadget *gadget,void (*release)(struct device *dev)) { -struct usb_udc *udc; -int ret = -ENOMEM ; -dev_set_name (&gadget->dev,"gadget" );INIT_WORK (&gadget->work, usb_gadget_state_work); gadget->dev.parent = parent;
@@ -1189,17 +1186,32 @@ int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget, gadget->dev.release = usb_udc_nop_release;device_initialize (&gadget->dev); +} +EXPORT_SYMBOL_GPL (usb_initialize_gadget); + +/** +* usb_add_gadget - adds a new gadget to the udc class driver list +* @gadget: the gadget to be added to the list. +* +* Returns zero on success, negative errno otherwise. +* Does not do a final usb_put_gadget() if an error occurs. +*/ +int usb_add_gadget (struct usb_gadget *gadget) +{ +struct usb_udc *udc; +int ret = -ENOMEM ; udc =kzalloc (sizeof (*udc),GFP_KERNEL );if (!udc) - goto err_put_gadget; + goto error;device_initialize (&udc->dev); udc->dev.release = usb_udc_release; udc->dev.class = udc_class; udc->dev.groups = usb_udc_attr_groups; - udc->dev.parent = parent; - ret =dev_set_name (&udc->dev,"%s" ,kobject_name (&parent->kobj)); + udc->dev.parent = gadget->dev.parent; + ret =dev_set_name (&udc->dev,"%s" , +kobject_name (&gadget->dev.parent->kobj));if (ret) goto err_put_udc;
@@ -1242,8 +1254,30 @@ int usb_add_gadget_udc_release(struct device *parent, struct usb_gadget *gadget, err_put_udc:put_device (&udc->dev); - err_put_gadget: -put_device (&gadget->dev); + error: +return ret; +} +EXPORT_SYMBOL_GPL (usb_add_gadget); + +/** +* usb_add_gadget_udc_release - adds a new gadget to the udc class driver list +* @parent: the parent device to this udc. Usually the controller driver's +* device. +* @gadget: the gadget to be added to the list. +* @release: a gadget release function. +* +* Returns zero on success, negative errno otherwise. +* Calls the gadget release function in the latter case. +*/ +int usb_add_gadget_udc_release (struct device *parent,struct usb_gadget *gadget, +void (*release)(struct device *dev)) +{ +int ret; + +usb_initialize_gadget (parent, gadget, release); + ret =usb_add_gadget (gadget); +if (ret) +usb_put_gadget (gadget);return ret; }EXPORT_SYMBOL_GPL (usb_add_gadget_udc_release);
@@ -1311,13 +1345,14 @@ static void usb_gadget_remove_driver(struct usb_udc *udc) }/** -* usb_del_gadget_udc - deletes @udc from udc_list +* usb_del_gadget - deletes @udc from udc_list * @gadget: the gadget to be removed. * -* This, will call usb_gadget_unregister_driver() if +* This will call usb_gadget_unregister_driver() if * the @udc is still busy. +* It will not do a final usb_put_gadget(). */ -void usb_del_gadget_udc (struct usb_gadget *gadget) +void usb_del_gadget (struct usb_gadget *gadget) {struct usb_udc *udc = gadget->udc;
@@ -1340,7 +1375,20 @@ void usb_del_gadget_udc(struct usb_gadget *gadget)kobject_uevent (&udc->dev.kobj,KOBJ_REMOVE );flush_work (&gadget->work);device_unregister (&udc->dev); -device_unregister (&gadget->dev); +device_del (&gadget->dev); +} +EXPORT_SYMBOL_GPL (usb_del_gadget); + +/** +* usb_del_gadget_udc - deletes @udc from udc_list +* @gadget: the gadget to be removed. +* +* Calls usb_del_gadget() and does a final usb_put_gadget(). +*/ +void usb_del_gadget_udc (struct usb_gadget *gadget) +{ +usb_del_gadget (gadget); +usb_put_gadget (gadget);memset (&gadget->dev,0x00 ,sizeof (gadget->dev)); }EXPORT_SYMBOL_GPL (usb_del_gadget_udc);
include/linux/usb/gadget.h +21 -6
@@ -436,6 +436,7 @@ struct usb_gadget { };#define work_to_gadget (w) (container_of((w), struct usb_gadget, work)) +/* Interface to the device model */ static inline void set_gadget_data (struct usb_gadget *gadget,void *data) {dev_set_drvdata (&gadget->dev, data); }static inline void *get_gadget_data (struct usb_gadget *gadget)
@@ -444,6 +445,26 @@ static inline struct usb_gadget *dev_to_usb_gadget(struct device *dev) { return container_of(dev, struct usb_gadget, dev); } +static inline struct usb_gadget *usb_get_gadget (struct usb_gadget *gadget) +{ +get_device (&gadget->dev); +return gadget; +} +static inline void usb_put_gadget (struct usb_gadget *gadget) +{ +put_device (&gadget->dev); +} +extern void usb_initialize_gadget (struct device *parent, +struct usb_gadget *gadget,void (*release)(struct device *dev)); +extern int usb_add_gadget (struct usb_gadget *gadget); +extern void usb_del_gadget (struct usb_gadget *gadget); + +/* Legacy device-model interface */ +extern int usb_add_gadget_udc_release (struct device *parent, +struct usb_gadget *gadget,void (*release)(struct device *dev)); +extern int usb_add_gadget_udc (struct device *parent,struct usb_gadget *gadget); +extern void usb_del_gadget_udc (struct usb_gadget *gadget); +extern char *usb_get_gadget_udc_name (void );/* iterates the non-control endpoints; 'tmp' is a struct usb_ep pointer */ #define gadget_for_each_ep (tmp, gadget) \
@@ -735,12 +756,6 @@ int usb_gadget_probe_driver(struct usb_gadget_driver *driver);*/ int usb_gadget_unregister_driver (struct usb_gadget_driver *driver); -extern int usb_add_gadget_udc_release (struct device *parent, -struct usb_gadget *gadget,void (*release)(struct device *dev)); -extern int usb_add_gadget_udc (struct device *parent,struct usb_gadget *gadget); -extern void usb_del_gadget_udc (struct usb_gadget *gadget); -extern char *usb_get_gadget_udc_name (void ); -/*-------------------------------------------------------------------------*/ /* utility to simplify dealing with string descriptors */
Signature · 1 line
2.17.1
PATCH v4 2/6 USB: UDC: net2280: Fix memory leaks
In reply to Peter ChenFrom: Alan Stern <[email protected]>
As Anton and Evgeny have noted, the net2280 UDC driver has a problem with leaking memory along some of its failure pathways. It also has another problem, not previously noted, in that some of the failure pathways will call usb_del_gadget_udc() without first calling usb_add_gadget_udc_release(). And it leaks memory by calling kfree() when it should call put_device().
Previous attempts to fix the problems have failed because of lack of support in the UDC core for separately initializing and adding gadgets, or for separately deleting and freeing gadgets. The previous patch in this series adds the necessary support, making it possible to fix the outstanding problems properly.
This patch adds an "added" flag to the net2280 structure to indicate whether or not the gadget has been registered (and thus whether or not to call usb_del_gadget()), and it fixes the deallocation issues by calling usb_put_gadget() at the appropriate point.
A similar memory leak issue, apparently never before recognized, stems from the fact that the driver never initializes the drvdata field in the gadget's embedded struct device! Evidently this wasn't noticed because the pointer is only ever used as an argument to kfree(), which doesn't mind getting called with a NULL pointer. In fact, the drvdata for gadget device will be written by usb_composite_dev structure if any gadget class is loaded, so it needs to use usb_gadget structure to get net2280 private data.
--- drivers/usb/gadget/udc/net2280.c | 11 +++++++---- drivers/usb/gadget/udc/net2280.h | 1 + 2 files changed, 8 insertions(+), 4 deletions(-)
drivers/usb/gadget/udc/net2280.c +7 -4
@@ -3561,7 +3561,7 @@ static irqreturn_t net2280_irq(int irq, void *_dev)static void gadget_release (struct device *_dev) { -struct net2280 *dev =dev_get_drvdata (_dev); + struct net2280 *dev = container_of(_dev, struct net2280, gadget.dev);kfree (dev); }
@@ -3572,7 +3572,8 @@ static void net2280_remove(struct pci_dev *pdev) {struct net2280 *dev =pci_get_drvdata (pdev); -usb_del_gadget_udc (&dev->gadget); +if (dev->added) +usb_del_gadget (&dev->gadget);BUG_ON (dev->driver);
@@ -3603,6 +3604,7 @@ static void net2280_remove(struct pci_dev *pdev)device_remove_file (&pdev->dev, &dev_attr_registers);ep_info (dev,"unbind\n" ); +usb_put_gadget (&dev->gadget); }/* wrap this driver around the specified device, but
@@ -3624,6 +3626,7 @@ static int net2280_probe(struct pci_dev *pdev, const struct pci_device_id *id) }pci_set_drvdata (pdev, dev); +usb_initialize_gadget (&pdev->dev, &dev->gadget, gadget_release);spin_lock_init (&dev->lock); dev->quirks = id->driver_data; dev->pdev = pdev;
@@ -3774,10 +3777,10 @@ static int net2280_probe(struct pci_dev *pdev, const struct pci_device_id *id)if (retval) goto done; - retval =usb_add_gadget_udc_release (&pdev->dev, &dev->gadget, - gadget_release); + retval =usb_add_gadget (&dev->gadget);if (retval) goto done; + dev->added =1 ;return 0 ; done:
drivers/usb/gadget/udc/net2280.h +1 -0
@@ -156,6 +156,7 @@ struct net2280 { softconnect : 1, got_irq : 1, region:1, + added:1, u1_enable:1, u2_enable:1, ltm_enable:1,
Signature · 1 line
2.17.1
PATCH v4 3/6 USB: UDC: net2272: Fix memory leaks
In reply to Peter ChenFrom: Alan Stern <[email protected]>
Like net2280 (on which it was based), the net2272 UDC driver has a problem with leaking memory along some of its failure pathways. It also has another problem, not previously noted, in that some of the failure pathways will call usb_del_gadget_udc() without first calling usb_add_gadget_udc_release(). And it leaks memory by calling kfree() when it should call put_device().
Until now it has been impossible to handle the memory leaks, because of lack of support in the UDC core for separately initializing and adding gadgets, or for separately deleting and freeing gadgets. An earlier patch in this series adds the necessary support, making it possible to fix the outstanding problems properly.
This patch adds an "added" flag to the net2272 structure to indicate whether or not the gadget has been registered (and thus whether or not to call usb_del_gadget()), and it fixes the deallocation issues by calling usb_put_gadget() at the appropriate places.
A similar memory leak issue, apparently never before recognized, stems from the fact that the driver never initializes the drvdata field in the gadget's embedded struct device! Evidently this wasn't noticed because the pointer is only ever used as an argument to kfree(), which doesn't mind getting called with a NULL pointer. In fact, the drvdata for gadget device will be written by usb_composite_dev structure if any gadget class is loaded, so it needs to use usb_gadget structure to get net2280 private data.
--- drivers/usb/gadget/udc/net2272.c | 23 +++++++++++++---------- drivers/usb/gadget/udc/net2272.h | 1 + 2 files changed, 14 insertions(+), 10 deletions(-)
drivers/usb/gadget/udc/net2272.c +13 -10
@@ -2196,7 +2196,8 @@ static int net2272_present(struct net2272 *dev)static void net2272_gadget_release (struct device *_dev) { -struct net2272 *dev =dev_get_drvdata (_dev); + struct net2272 *dev = container_of(_dev, struct net2272, gadget.dev); +kfree (dev); }
@@ -2205,7 +2206,8 @@ net2272_gadget_release(struct device *_dev)static void net2272_remove (struct net2272 *dev) { -usb_del_gadget_udc (&dev->gadget); +if (dev->added) +usb_del_gadget (&dev->gadget);free_irq (dev->irq, dev);iounmap (dev->base_addr);device_remove_file (dev->dev, &dev_attr_registers);
@@ -2235,6 +2237,7 @@ static struct net2272 *net2272_probe_init(struct device *dev, unsigned int irq)/* the "gadget" abstracts/virtualizes the controller */ ret->gadget.name = driver_name; +usb_initialize_gadget (dev, &ret->gadget, net2272_gadget_release);return ret; }
@@ -2273,10 +2276,10 @@ net2272_probe_fin(struct net2272 *dev, unsigned int irqflags)if (ret) goto err_irq; - ret =usb_add_gadget_udc_release (dev->dev, &dev->gadget, - net2272_gadget_release); + ret =usb_add_gadget (&dev->gadget);if (ret) goto err_add_udc; + dev->added =1 ;return 0 ;
@@ -2451,7 +2454,7 @@ net2272_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)if (pci_enable_device (pdev) <0 ) { ret = -ENODEV ; - goto err_free; + goto err_put; }pci_set_master (pdev);
@@ -2474,8 +2477,8 @@ net2272_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id) err_pci:pci_disable_device (pdev); - err_free: -kfree (dev); + err_put: +usb_put_gadget (&dev->gadget);return ret; }
@@ -2536,7 +2539,7 @@ net2272_pci_remove(struct pci_dev *pdev)pci_disable_device (pdev); -kfree (dev); +usb_put_gadget (&dev->gadget); }/* Table of matching PCI IDs */
@@ -2649,7 +2652,7 @@ net2272_plat_probe(struct platform_device *pdev) err_req:release_mem_region (base, len); err: -kfree (dev); +usb_put_gadget (&dev->gadget);return ret; }
@@ -2664,7 +2667,7 @@ net2272_plat_remove(struct platform_device *pdev)release_mem_region (pdev->resource[0 ].start,resource_size (&pdev->resource[0 ])); -kfree (dev); +usb_put_gadget (&dev->gadget);return 0 ; }
drivers/usb/gadget/udc/net2272.h +1 -0
@@ -441,6 +441,7 @@ struct net2272 { unsigned protocol_stall:1, softconnect:1, wakeup:1, + added:1, dma_eot_polarity:1, dma_dack_polarity:1, dma_dreq_polarity:1,
Signature · 1 line
2.17.1
PATCH v4 4/6 usb: cdns3: gadget: fix possible memory leak
In reply to Peter ChenIf cdns3_gadget_start is failed, it never frees cdns3_device structure. Meanwhile, there is no release function for gadget device, it causes there is no sync with driver core.
To fix this, we add release function for gadget device, and free cdns3_device structure at there. Meanwhile, With the new UDC core APIs, we could work with driver core better to handle memory leak issue.
--- drivers/usb/cdns3/gadget.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-)
drivers/usb/cdns3/gadget.c +15 -5
@@ -2988,6 +2988,14 @@ static int cdns3_init_eps(struct cdns3_device *priv_dev)return -ENOMEM ; } +static void cdns3_gadget_release (struct device *dev) +{ +struct cdns3_device *priv_dev =container_of (dev, + struct cdns3_device, gadget.dev); + +kfree (priv_dev); +} +void cdns3_gadget_exit (struct cdns3 *cdns) {struct cdns3_device *priv_dev;
@@ -2999,7 +3007,7 @@ void cdns3_gadget_exit(struct cdns3 *cdns)pm_runtime_mark_last_busy (cdns->dev);pm_runtime_put_autosuspend (cdns->dev); -usb_del_gadget_udc (&priv_dev->gadget); +usb_del_gadget (&priv_dev->gadget);cdns3_free_all_eps (priv_dev);
@@ -3019,7 +3027,7 @@ void cdns3_gadget_exit(struct cdns3 *cdns) priv_dev->setup_dma);kfree (priv_dev->zlp_buf); -kfree (priv_dev); +usb_put_gadget (&priv_dev->gadget); cdns->gadget_dev =NULL ;cdns3_drd_gadget_off (cdns); }
@@ -3034,6 +3042,8 @@ static int cdns3_gadget_start(struct cdns3 *cdns)if (!priv_dev)return -ENOMEM ; +usb_initialize_gadget (cdns->dev, &priv_dev->gadget, + cdns3_gadget_release); cdns->gadget_dev = priv_dev; priv_dev->sysdev = cdns->dev; priv_dev->dev = cdns->dev;
@@ -3121,10 +3131,9 @@ static int cdns3_gadget_start(struct cdns3 *cdns) }/* add USB gadget device */ - ret =usb_add_gadget_udc (priv_dev->dev, &priv_dev->gadget); + ret =usb_add_gadget (&priv_dev->gadget);if (ret <0 ) { -dev_err (priv_dev->dev, -"Failed to register USB device controller\n" ); +dev_err (priv_dev->dev,"Failed to add gadget\n" ); goto err4; }
@@ -3137,6 +3146,7 @@ static int cdns3_gadget_start(struct cdns3 *cdns) err2:cdns3_free_all_eps (priv_dev); err1: +usb_put_gadget (&priv_dev->gadget); cdns->gadget_dev =NULL ;return ret; }
Signature · 1 line
2.17.1
PATCH v4 5/6 usb: dwc3: allocate gadget structure dynamically
In reply to Peter ChenThe current code uses commit fac323471df6 ("usb: udc: allow adding and removing the same gadget device") as the workaround to let the gadget device is re-used, but it is not allowed from driver core point. In this commit, we allocate gadget structure dynamically, and free it at its release function. Since the gadget device's driver_data has already occupied by usb_composite_dev structure, we have to use gadget device's platform data to store dwc3 structure.
--- drivers/usb/dwc3/core.h | 2 +- drivers/usb/dwc3/ep0.c | 26 ++++----- drivers/usb/dwc3/gadget.c | 108 ++++++++++++++++++++++---------------- drivers/usb/dwc3/gadget.h | 2 +- 4 files changed, 78 insertions(+), 60 deletions(-)
drivers/usb/dwc3/core.h +1 -1
@@ -1079,7 +1079,7 @@ struct dwc3 {struct dwc3_event_buffer *ev_buf;struct dwc3_ep *eps[DWC3_ENDPOINTS_NUM ]; -struct usb_gadget gadget; +struct usb_gadget *gadget;struct usb_gadget_driver *gadget_driver;struct clk_bulk_data *clks;
drivers/usb/dwc3/ep0.c +13 -13
@@ -131,7 +131,7 @@ static int __dwc3_gadget_ep0_queue(struct dwc3_ep *dep, direction = !dwc->ep0_expect_in; dwc->delayed_status = false; -usb_gadget_set_state (&dwc->gadget,USB_STATE_CONFIGURED ); +usb_gadget_set_state (dwc->gadget,USB_STATE_CONFIGURED );if (dwc->ep0state ==EP0_STATUS_PHASE )__dwc3_ep0_do_control_status (dwc, dwc->eps[direction]);
@@ -325,7 +325,7 @@ static int dwc3_ep0_handle_status(struct dwc3 *dwc,/* * LTM will be set once we know how to set this in HW. */ - usb_status |= dwc->gadget.is_selfpowered; + usb_status |= dwc->gadget->is_selfpowered;if ((dwc->speed ==DWC3_DSTS_SUPERSPEED ) || (dwc->speed ==DWC3_DSTS_SUPERSPEED_PLUS )) {
@@ -450,7 +450,7 @@ static int dwc3_ep0_handle_device(struct dwc3 *dwc, wValue =le16_to_cpu (ctrl->wValue); wIndex =le16_to_cpu (ctrl->wIndex); - state = dwc->gadget.state; + state = dwc->gadget->state;switch (wValue) {case USB_DEVICE_REMOTE_WAKEUP :
@@ -559,7 +559,7 @@ static int dwc3_ep0_handle_feature(struct dwc3 *dwc,static int dwc3_ep0_set_address (struct dwc3 *dwc,struct usb_ctrlrequest *ctrl) { -enum usb_device_state state = dwc->gadget.state; +enum usb_device_state state = dwc->gadget->state;u32 addr;u32 reg;
@@ -580,9 +580,9 @@ static int dwc3_ep0_set_address(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)dwc3_writel (dwc->regs,DWC3_DCFG , reg);if (addr) -usb_gadget_set_state (&dwc->gadget,USB_STATE_ADDRESS ); +usb_gadget_set_state (dwc->gadget,USB_STATE_ADDRESS );else -usb_gadget_set_state (&dwc->gadget,USB_STATE_DEFAULT ); +usb_gadget_set_state (dwc->gadget,USB_STATE_DEFAULT );return 0 ; }
@@ -592,14 +592,14 @@ static int dwc3_ep0_delegate_req(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)int ret;spin_unlock (&dwc->lock); - ret = dwc->gadget_driver->setup (&dwc->gadget, ctrl); + ret = dwc->gadget_driver->setup (dwc->gadget, ctrl);spin_lock (&dwc->lock);return ret; }static int dwc3_ep0_set_config (struct dwc3 *dwc,struct usb_ctrlrequest *ctrl) { -enum usb_device_state state = dwc->gadget.state; +enum usb_device_state state = dwc->gadget->state;u32 cfg;int ret;u32 reg;
@@ -622,7 +622,7 @@ static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)* to change the state on the next usb_ep_queue() */ if (ret ==0 ) -usb_gadget_set_state (&dwc->gadget, +usb_gadget_set_state (dwc->gadget,USB_STATE_CONFIGURED );/*
@@ -641,7 +641,7 @@ static int dwc3_ep0_set_config(struct dwc3 *dwc, struct usb_ctrlrequest *ctrl)case USB_STATE_CONFIGURED : ret =dwc3_ep0_delegate_req (dwc, ctrl);if (!cfg && !ret) -usb_gadget_set_state (&dwc->gadget, +usb_gadget_set_state (dwc->gadget,USB_STATE_ADDRESS );break ;default :
@@ -697,7 +697,7 @@ static void dwc3_ep0_set_sel_cmpl(struct usb_ep *ep, struct usb_request *req)static int dwc3_ep0_set_sel (struct dwc3 *dwc,struct usb_ctrlrequest *ctrl) {struct dwc3_ep *dep; -enum usb_device_state state = dwc->gadget.state; +enum usb_device_state state = dwc->gadget->state;u16 wLength;if (state ==USB_STATE_DEFAULT )
@@ -741,7 +741,7 @@ static int dwc3_ep0_set_isoch_delay(struct dwc3 *dwc, struct usb_ctrlrequest *ctif (wIndex || wLength)return -EINVAL ; - dwc->gadget.isoch_delay = wValue; + dwc->gadget->isoch_delay = wValue;return 0 ; }
@@ -1102,7 +1102,7 @@ static void dwc3_ep0_xfernotready(struct dwc3 *dwc,*/ if (!list_empty (&dep->pending_list)) { dwc->delayed_status = false; -usb_gadget_set_state (&dwc->gadget, +usb_gadget_set_state (dwc->gadget,USB_STATE_CONFIGURED );dwc3_ep0_do_control_status (dwc, event); }
drivers/usb/dwc3/gadget.c +63 -45
285 lines not on this page · raw message
drivers/usb/dwc3/gadget.h +1 -1
@@ -17,7 +17,7 @@struct dwc3 ;#define to_dwc3_ep (ep) (container_of(ep, struct dwc3_ep, endpoint)) -#define gadget_to_dwc (g) (container_of(g, struct dwc3, gadget)) +#define gadget_to_dwc (g) (dev_get_platdata(&g->dev))/* DEPCFG parameter 1 */ #define DWC3_DEPCFG_INT_NUM (n) (((n) & 0x1f) << 0)
Signature · 1 line
2.17.1
PATCH v4 6/6 Revert "usb: udc: allow adding and removing the same gadget device"
In reply to Peter ChenWe have already allocated gadget structure dynamically at UDC (dwc3) driver, so commit fac323471df6 ("usb: udc: allow adding and removing the same gadget device")could be reverted.
--- drivers/usb/gadget/udc/core.c | 1 - 1 file changed, 1 deletion(-)
drivers/usb/gadget/udc/core.c +0 -1
@@ -1389,7 +1389,6 @@ void usb_del_gadget_udc(struct usb_gadget *gadget) {usb_del_gadget (gadget);usb_put_gadget (gadget); -memset (&gadget->dev,0x00 ,sizeof (gadget->dev)); }EXPORT_SYMBOL_GPL (usb_del_gadget_udc);
Signature · 1 line
2.17.1