[PATCH v4 14/43] usb: gadget: composite: introduce clear_alt() operation

From: Robert Baldyga
Date: Wed Feb 03 2016 - 07:53:27 EST


Introduce clear_alt() callback, which is called when prevoiusly set
altsetting is cleared. This can take place in two situations:
- when another altsetting is selected,
- during function disable.

Thanks to symetry to set_alt(), clear_alt() simplifies managing of
resources allocated in set_alt(). It also takes over the function of
disable() opetarion, so it can be removed after converting all USB
functions to new API.

Signed-off-by: Robert Baldyga <r.baldyga@xxxxxxxxxxx>
---
drivers/usb/gadget/composite.c | 12 ++++++++----
include/linux/usb/composite.h | 4 ++++
2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 0c962d4..1c26443 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -981,6 +981,9 @@ static void disable_interface(struct usb_function *f, unsigned i)
for (e = 0; e < alt->eps_num; ++e)
usb_ep_disable(alt->eps[e]->ep);

+ if (f->clear_alt)
+ f->clear_alt(f, i, intf->cur_altset);
+
intf->cur_altset = -1;
}

@@ -992,12 +995,13 @@ static void disable_function(struct usb_function *f)
{
int i;

- if (usb_function_is_new_api(f))
+ if (usb_function_is_new_api(f)) {
for (i = 0; i < f->descs->intfs_num; ++i)
disable_interface(f, i);
-
- if (f->disable)
- f->disable(f);
+ } else {
+ if (f->disable)
+ f->disable(f);
+ }

bitmap_zero(f->endpoints, 32);
}
diff --git a/include/linux/usb/composite.h b/include/linux/usb/composite.h
index e985f3a..aa55377 100644
--- a/include/linux/usb/composite.h
+++ b/include/linux/usb/composite.h
@@ -308,6 +308,8 @@ struct usb_os_desc_table {
* initialize usb_ep.driver data at this time (when it is used).
* Note that setting an interface to its current altsetting resets
* interface state, and that all interfaces have a disabled state.
+ * @clear_alt: (REQUIRED) Clears altsetting, frees all ep requiests and other
+ * resources allocated by set_alt.
* @get_alt: Returns the active altsetting. If this is not provided,
* then only altsetting zero is supported.
* @disable: (REQUIRED) Indicates the function should be disabled. Reasons
@@ -380,6 +382,8 @@ struct usb_function {
/* runtime state management */
int (*set_alt)(struct usb_function *,
unsigned interface, unsigned alt);
+ void (*clear_alt)(struct usb_function *,
+ unsigned interface, unsigned alt);
int (*get_alt)(struct usb_function *,
unsigned interface);
void (*disable)(struct usb_function *);
--
1.9.1