Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755390AbbLKLgj (ORCPT ); Fri, 11 Dec 2015 06:36:39 -0500 Received: from mailout2.samsung.com ([203.254.224.25]:46046 "EHLO mailout2.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754027AbbLKL0H (ORCPT ); Fri, 11 Dec 2015 06:26:07 -0500 X-AuditID: cbfee61b-f793c6d00000236c-a7-566ab2cdbad3 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 v3 12/36] usb: gadget: composite: disable eps before calling disable() callback Date: Fri, 11 Dec 2015 12:24:51 +0100 Message-id: <1449833115-24065-13-git-send-email-r.baldyga@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1449833115-24065-1-git-send-email-r.baldyga@samsung.com> References: <1449833115-24065-1-git-send-email-r.baldyga@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprOLMWRmVeSWpSXmKPExsVy+t9jQd2zm7LCDNqPGVjMetnOYrFxxnpW i4P36y2aF69ns7i8aw6bxaJlrcwWa4/cZbd4cHgnuwOHx/65a9g9+rasYvQ4fmM7k8fnTXIB LFFcNimpOZllqUX6dglcGf9mXGUsOCFcMXXvDqYGxukCXYycHBICJhL/t/xnh7DFJC7cW8/W xcjFISQwi1Hi7Pc+ZgjnJ6NE/4UOFpAqNgEdiS3fJzCC2CICAhLrX1xiByliFjjHKPHwThtY QlggUeLg/0dgNouAqsTLrqtgzbwCbhLf701nhlgnJ3Hy2GRWEJsTKD755CWwuJCAq8Sb1+sY JzDyLmBkWMUokVqQXFCclJ5rlJdarlecmFtcmpeul5yfu4kRHFzPpHcwHt7lfohRgINRiYd3 AUdWmBBrYllxZe4hRgkOZiUR3l8bgEK8KYmVValF+fFFpTmpxYcYpTlYlMR5912KDBMSSE8s Sc1OTS1ILYLJMnFwSjUwbg1fajP7+b74/v8sa9byf/bYYX9Az+6j+yf3DXdnZCrWOFUGcs1/ cjXWcUO9rfaMl4pnNvfqy5vVCOdenpvaU5n2ulNT7YhY+KFytxWGy+4wP3znofngxCq770sv PTYpbLgqZLj1V2qG6JMm9+6AVqf0FHGlg/bttVbFJ6prV7/een+xV3qxEktxRqKhFnNRcSIA okDeRSoCAAA= 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 fdd0cbe..3695b75 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); @@ -946,6 +946,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; @@ -953,10 +993,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/