Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754169AbbKCMy6 (ORCPT ); Tue, 3 Nov 2015 07:54:58 -0500 Received: from mailout4.samsung.com ([203.254.224.34]:36669 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754061AbbKCMyx (ORCPT ); Tue, 3 Nov 2015 07:54:53 -0500 X-AuditID: cbfee61b-f79d56d0000048c5-8a-5638ae9b59f6 From: Robert Baldyga To: balbi@ti.com Cc: gregkh@linuxfoundation.org, andrzej.p@samsung.com, m.szyprowski@samsung.com, b.zolnierkie@samsung.com, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Robert Baldyga Subject: [PATCH 12/23] usb: gadget: composite: disable eps before calling disable() callback Date: Tue, 03 Nov 2015 13:53:51 +0100 Message-id: <1446555242-3733-13-git-send-email-r.baldyga@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1446555242-3733-1-git-send-email-r.baldyga@samsung.com> References: <1446555242-3733-1-git-send-email-r.baldyga@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprCLMWRmVeSWpSXmKPExsVy+t9jQd3Z6yzCDHpm6lrMetnOYrFxxnpW i4P36y2aF69ns7i8aw6bxaJlrcwWa4/cZbd4cHgnuwOHx/65a9g9+rasYvQ4fmM7k8fnTXIB LFFcNimpOZllqUX6dglcGdMXfWItOCFc8bR9J3sD43SBLkZODgkBE4m9//8zQ9hiEhfurWcD sYUEZjFKbPmW3MXIBWT/ZJT4cuIcWIJNQEdiy/cJjCC2iICAxPoXl9hBipgFzjFKPLzTBpYQ FoiTOLr1C9hUFgFViaapu5lAbF4BV4k3j5YyQWyTkzh5bDJrFyMHBydQ/NI7ZRBTSMBF4vh2 ngmMvAsYGVYxSqQWJBcUJ6XnGuWllusVJ+YWl+al6yXn525iBIfVM+kdjId3uR9iFOBgVOLh XbDEPEyINbGsuDL3EKMEB7OSCO/uuRZhQrwpiZVVqUX58UWlOanFhxilOViUxHn1PY3ChATS E0tSs1NTC1KLYLJMHJxSDYxT9cpyXkhsk3A/p2cstuUzs2fUrSmnSsWv3/U5lL5aubR2kZSI eNBufZ6KjpjUg1J6+0ImN00tO8gp5sb3oyw3ZpbeCaMDhmd0n38+VW9sYLuZLVHWbtVWv4/+ 29f/nLLAod3ujVLrrsn7O3kdGWadrIhdlDt1xs53y+dt5Uif8Lvm3TzXd9ZKLMUZiYZazEXF iQB9Zw4aJwIAAA== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2657 Lines: 97 Changes meaning of disable() operation for functions using new API. Before calling disable() callback composite automatically disables endpoints of active altsettings of given USB function. This reduces amount of boilerplate code in USB functions. Signed-off-by: Robert Baldyga --- drivers/usb/gadget/composite.c | 51 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c index b50ebdb..a965fbc 100644 --- a/drivers/usb/gadget/composite.c +++ b/drivers/usb/gadget/composite.c @@ -246,12 +246,12 @@ done: } EXPORT_SYMBOL_GPL(usb_add_function); +static void disable_function(struct usb_function *f); + void usb_remove_function(struct usb_configuration *c, struct usb_function *f) { - if (f->disable) - f->disable(f); + disable_function(f); - bitmap_zero(f->endpoints, 32); list_del(&f->list); if (f->unbind) f->unbind(c, f); @@ -943,6 +943,46 @@ static void device_qual(struct usb_composite_dev *cdev) /*-------------------------------------------------------------------------*/ +/** + * disable_interface - disable all endpoints in given interface + * @f: USB function + * @i: interface index in function + */ +static void disable_interface(struct usb_function *f, unsigned i) +{ + struct usb_composite_intf *intf; + struct usb_composite_altset *alt; + int e; + + intf = f->descs->intfs[i]; + if (intf->cur_altset < 0) + return; + + alt = intf->altsets[intf->cur_altset]; + for (e = 0; e < alt->eps_num; ++e) + usb_ep_disable(alt->eps[e]->ep); + + intf->cur_altset = -1; +} + +/** + * disable_function - disable all endpoints in given function + * @f: USB function + */ +static void disable_function(struct usb_function *f) +{ + int i; + + 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); + + bitmap_zero(f->endpoints, 32); +} + static void reset_config(struct usb_composite_dev *cdev) { struct usb_function *f; @@ -950,10 +990,7 @@ static void reset_config(struct usb_composite_dev *cdev) DBG(cdev, "reset config\n"); list_for_each_entry(f, &cdev->config->functions, list) { - if (f->disable) - f->disable(f); - - bitmap_zero(f->endpoints, 32); + disable_function(f); } cdev->config = NULL; cdev->delayed_status = 0; -- 1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/