From patchwork Mon Feb 8 11:12:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Szyprowski X-Patchwork-Id: 61387 Delivered-To: patch@linaro.org Received: by 10.112.43.199 with SMTP id y7csp1371303lbl; Mon, 8 Feb 2016 03:13:07 -0800 (PST) X-Received: by 10.66.132.81 with SMTP id os17mr40777174pab.98.1454929987726; Mon, 08 Feb 2016 03:13:07 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w12si45987103pfa.177.2016.02.08.03.13.07; Mon, 08 Feb 2016 03:13:07 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-usb-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-usb-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-usb-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750957AbcBHLNF (ORCPT + 4 others); Mon, 8 Feb 2016 06:13:05 -0500 Received: from mailout1.w1.samsung.com ([210.118.77.11]:41827 "EHLO mailout1.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750802AbcBHLNE (ORCPT ); Mon, 8 Feb 2016 06:13:04 -0500 Received: from eucpsbgm1.samsung.com (unknown [203.254.199.244]) by mailout1.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0O2800IZL75OGS90@mailout1.w1.samsung.com>; Mon, 08 Feb 2016 11:13:00 +0000 (GMT) X-AuditID: cbfec7f4-f79026d00000418a-ca-56b8783cddd5 Received: from eusync1.samsung.com ( [203.254.199.211]) by eucpsbgm1.samsung.com (EUCPMTA) with SMTP id 36.04.16778.C3878B65; Mon, 8 Feb 2016 11:13:00 +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 <0O28001LG75K09D0@eusync1.samsung.com>; Mon, 08 Feb 2016 11:13:00 +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] usb: gadget: provide interface for legacy gadgets to get UDC name Date: Mon, 08 Feb 2016 12:12:45 +0100 Message-id: <1454929965-19897-1-git-send-email-m.szyprowski@samsung.com> X-Mailer: git-send-email 1.9.2 In-reply-to: <56B7D2C9.5070301@oracle.com> References: <56B7D2C9.5070301@oracle.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrILMWRmVeSWpSXmKPExsVy+t/xy7o2FTvCDL5t0rTYOGM9q8Wxtifs Fs2L17NZXN41h81i0bJWZou1R+6yW2zdtJfZ4tjsv0wWPTtPMFqcbVrD6sDl8WTTRUaPf4f7 mTx2zrrL7rFpVSebx/65a9g9Pj69xeLRt2UVo8fnTXIBHFFcNimpOZllqUX6dglcGX1/p7MU TFGpOPSxhbmB8Z9sFyMnh4SAicTtDXeYIWwxiQv31rN1MXJxCAksZZQ40tXOBOE0MUks3fCb HaSKTcBQouttF1AVB4eIgLVE38EgkBpmgY9MEh1zJzCB1AgLhEjMenASzGYRUJU48O8sC4jN K+Ah0f/gEdQ2OYn/L1cwgczhFNCSmPHBDyQsJKAp0fmsk3ECI+8CRoZVjKKppckFxUnpuYZ6 xYm5xaV56XrJ+bmbGCEB+WUH4+JjVocYBTgYlXh4Kzq2hwmxJpYVV+YeYpTgYFYS4S3P3REm xJuSWFmVWpQfX1Sak1p8iFGag0VJnHfurvchQgLpiSWp2ampBalFMFkmDk6pBsaSP14px77a zhV9fWHv16sKwW9j/m3nlfbsmFS7LU505udpOtPLvgTs26CrrFITXhlr+ccyc/WfxYp+c/m7 PXbfD1ALy1s14ftUYbHEyS85Pqrvbpe4cnJ95V/D//O37g56HX/88iM2l9x9pXM/J7xwdJl9 cGfRt9b8262BzX/dFq3qX3S58P0XJZbijERDLeai4kQAnwW87EQCAAA= Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@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). Signed-off-by: Marek Szyprowski --- Vegard: Could you check if this patch fixes your issue with gadgetfs and NULL pointer dereference? Best regards, Marek Szyprowski --- drivers/usb/gadget/legacy/inode.c | 29 ++--------------------------- drivers/usb/gadget/udc/udc-core.c | 33 +++++++++++++++++++++++++++++++++ include/linux/usb/gadget.h | 1 + 3 files changed, 36 insertions(+), 27 deletions(-) -- 1.9.2 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/usb/gadget/legacy/inode.c b/drivers/usb/gadget/legacy/inode.c index 7e179f81d05c..7a62a2f7bc18 100644 --- a/drivers/usb/gadget/legacy/inode.c +++ b/drivers/usb/gadget/legacy/inode.c @@ -227,7 +227,7 @@ static void put_ep (struct ep_data *data) * implicitly, starting with the driver name and then endpoint names. */ -static const char *CHIP; +static char CHIP[32]; /*----------------------------------------------------------------------*/ @@ -1697,28 +1697,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) @@ -1968,10 +1946,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); - if (!CHIP) + if (usb_get_gadget_udc_name(CHIP, sizeof(CHIP)) != 0) return -ENODEV; /* superblock */ diff --git a/drivers/usb/gadget/udc/udc-core.c b/drivers/usb/gadget/udc/udc-core.c index fd73a3ea07c2..eb70051d5949 100644 --- a/drivers/usb/gadget/udc/udc-core.c +++ b/drivers/usb/gadget/udc/udc-core.c @@ -442,6 +442,39 @@ err1: EXPORT_SYMBOL_GPL(usb_add_gadget_udc_release); /** + * usb_get_gadget_udc_name - get the name of the first UDC controller + * @dst_name + * @len + * 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 zero on success, negative errno otherwise. + */ +int usb_get_gadget_udc_name(char *dst_name, int len) +{ + struct usb_udc *udc; + int ret = -ENODEV; + + mutex_lock(&udc_lock); + list_for_each_entry(udc, &udc_list, list) { + const char *name = dev_name(&udc->dev); + /* For now we take the first one */ + if (!udc->driver && strlen(name) + 1 <= len) { + strcpy(dst_name, name); + ret = 0; + break; + } + } + mutex_unlock(&udc_lock); + return ret; +} +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 d82d0068872b..0a8f08302a34 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 int usb_get_gadget_udc_name(char *dst_name, int len); /*-------------------------------------------------------------------------*/