From patchwork Thu Feb 18 10:34:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 62163 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp503095lbl; Thu, 18 Feb 2016 02:35:06 -0800 (PST) X-Received: by 10.98.16.86 with SMTP id y83mr8842394pfi.45.1455791705608; Thu, 18 Feb 2016 02:35:05 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q28si8690832pfi.178.2016.02.18.02.35.05; Thu, 18 Feb 2016 02:35:05 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1426336AbcBRKfB (ORCPT + 30 others); Thu, 18 Feb 2016 05:35:01 -0500 Received: from mailout3.w1.samsung.com ([210.118.77.13]:39579 "EHLO mailout3.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1425384AbcBRKe6 (ORCPT ); Thu, 18 Feb 2016 05:34:58 -0500 Received: from eucpsbgm2.samsung.com (unknown [203.254.199.245]) by mailout3.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0O2Q00I6ZO27OK50@mailout3.w1.samsung.com>; Thu, 18 Feb 2016 10:34:55 +0000 (GMT) X-AuditID: cbfec7f5-f79b16d000005389-b7-56c59e4eea7c Received: from eusync1.samsung.com ( [203.254.199.211]) by eucpsbgm2.samsung.com (EUCPMTA) with SMTP id 70.7A.21385.E4E95C65; Thu, 18 Feb 2016 10:34:54 +0000 (GMT) Received: from amdc1339.digital.local ([106.116.147.30]) by eusync1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0O2Q00HKVO23EO50@eusync1.samsung.com>; Thu, 18 Feb 2016 10:34:54 +0000 (GMT) From: Marek Szyprowski To: linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Marek Szyprowski , Ruslan Bilovol , Bartlomiej Zolnierkiewicz , Vegard Nossum , Maxime Ripard , Greg Kroah-Hartman , Peter Chen , Felipe Balbi Subject: [PATCH v3] usb: gadget: provide interface for legacy gadgets to get UDC name Date: Thu, 18 Feb 2016 11:34:43 +0100 Message-id: <1455791683-4154-1-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.2 In-reply-to: <56B87C8A.6090609@oracle.com> References: <56B87C8A.6090609@oracle.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrPLMWRmVeSWpSXmKPExsVy+t/xy7p+846GGRyYZGmxccZ6VotjbU/Y LZoXr2ezuLxrDpvFomWtzBZrj9xlt9i6aS+zxbHZf5ksenaeYLQ427SG1YHL48mmi4we/w73 M3nsnHWX3WPTqk42j/1z17B7fHx6i8Wjb8sqRo/Pm+QCOKK4bFJSczLLUov07RK4MqbM7Wcv 2KhS0fdzM0sD4wq5LkZODgkBE4k37yazQdhiEhfurQeyuTiEBJYySnQ9vskO4TQxSfxdsZgZ pIpNwFCi620XUBUHh4iAtUTfwSCQGmaBj0wSHXMnMIHUCAuES7x/8Z0RxGYRUJW49OU1C0g9 r4C7xOXeCIhlchL/X65gAglzCmhJLPipAWIKCWhKLG6UmMDIu4CRYRWjaGppckFxUnqukV5x Ym5xaV66XnJ+7iZGSDB+3cG49JjVIUYBDkYlHt4NL46ECbEmlhVX5h5ilOBgVhLhfTLnaJgQ b0piZVVqUX58UWlOavEhRmkOFiVx3pm73ocICaQnlqRmp6YWpBbBZJk4OKUaGNfn7y+V/3v2 zkZ9ySuxs0tkHRsKlvN1StVvFAyeEd5d6NY3j3+h0yFB68vlsz+KTnqve0v0AntxjmfIp2Xl R9m3ZMezGJpN+lH3PfLf2YJPohpWM0oKPiy4vDxvo2GBYEmP1VpBL9Vl1zTZcgOSloddbLeb vzTVfI1JrVnZBseSnXe0Zd6GK7EUZyQaajEXFScCAB8Dh35CAgAA Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since commit 855ed04a3758b205e84b269f92d26ab36ed8e2f7 ("usb: gadget: udc-core: independent registration of gadgets and gadget drivers") gadget drivers can not assume that UDC drivers are already available on their initialization. This broke the HACK, which was used in gadgetfs driver, to get UDC controller name. This patch removes this hack and replaces it by additional function in the UDC core (which is usefully only for legacy drivers, please don't use it in the new code). Reported-by: Vegard Nossum Signed-off-by: Marek Szyprowski Tested-by: Vegard Nossum --- changelog: v3: - simplified code a bit v2: https://lkml.org/lkml/2016/2/8/234 - properly report udc gagdet driver name instead of udc device name v1: https://lkml.org/lkml/2016/2/8/176 - initial version --- drivers/usb/gadget/legacy/inode.c | 28 +++------------------------- drivers/usb/gadget/udc/udc-core.c | 30 ++++++++++++++++++++++++++++++ include/linux/usb/gadget.h | 1 + 3 files changed, 34 insertions(+), 25 deletions(-) -- 1.9.2 diff --git a/drivers/usb/gadget/legacy/inode.c b/drivers/usb/gadget/legacy/inode.c index 87fb0fd..5cdaf01 100644 --- a/drivers/usb/gadget/legacy/inode.c +++ b/drivers/usb/gadget/legacy/inode.c @@ -1699,28 +1699,6 @@ static struct usb_gadget_driver gadgetfs_driver = { }; /*----------------------------------------------------------------------*/ - -static void gadgetfs_nop(struct usb_gadget *arg) { } - -static int gadgetfs_probe(struct usb_gadget *gadget, - struct usb_gadget_driver *driver) -{ - CHIP = gadget->name; - return -EISNAM; -} - -static struct usb_gadget_driver probe_driver = { - .max_speed = USB_SPEED_HIGH, - .bind = gadgetfs_probe, - .unbind = gadgetfs_nop, - .setup = (void *)gadgetfs_nop, - .disconnect = gadgetfs_nop, - .driver = { - .name = "nop", - }, -}; - - /* DEVICE INITIALIZATION * * fd = open ("/dev/gadget/$CHIP", O_RDWR) @@ -1971,9 +1949,7 @@ gadgetfs_fill_super (struct super_block *sb, void *opts, int silent) if (the_device) return -ESRCH; - /* fake probe to determine $CHIP */ - CHIP = NULL; - usb_gadget_probe_driver(&probe_driver); + CHIP = usb_get_gadget_udc_name(); if (!CHIP) return -ENODEV; @@ -2034,6 +2010,8 @@ gadgetfs_kill_sb (struct super_block *sb) put_dev (the_device); the_device = NULL; } + kfree(CHIP); + CHIP = NULL; } /*----------------------------------------------------------------------*/ diff --git a/drivers/usb/gadget/udc/udc-core.c b/drivers/usb/gadget/udc/udc-core.c index fd73a3e..fd30242 100644 --- a/drivers/usb/gadget/udc/udc-core.c +++ b/drivers/usb/gadget/udc/udc-core.c @@ -442,6 +442,36 @@ err1: EXPORT_SYMBOL_GPL(usb_add_gadget_udc_release); /** + * usb_get_gadget_udc_name - get the name of the first UDC controller + * This functions returns the name of the first UDC controller in the system. + * Please note that this interface is usefull only for legacy drivers which + * assume that there is only one UDC controller in the system and they need to + * get its name before initialization. There is no guarantee that the UDC + * of the returned name will be still available, when gadget driver registers + * itself. + * + * Returns pointer to string with UDC controller name on success, NULL + * otherwise. Caller should kfree() returned string. + */ +char *usb_get_gadget_udc_name(void) +{ + struct usb_udc *udc; + char *name = NULL; + + /* For now we take the first available UDC */ + mutex_lock(&udc_lock); + list_for_each_entry(udc, &udc_list, list) { + if (!udc->driver) { + name = kstrdup(udc->gadget->name, GFP_KERNEL); + break; + } + } + mutex_unlock(&udc_lock); + return name; +} +EXPORT_SYMBOL_GPL(usb_get_gadget_udc_name); + +/** * usb_add_gadget_udc - adds a new gadget to the udc class driver list * @parent: the parent device to this udc. Usually the controller * driver's device. diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h index d82d006..547d86d 100644 --- a/include/linux/usb/gadget.h +++ b/include/linux/usb/gadget.h @@ -1126,6 +1126,7 @@ 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); /*-------------------------------------------------------------------------*/