From patchwork Tue Jan 17 21:21:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Magnus Lilja X-Patchwork-Id: 9521943 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 04D606020A for ; Tue, 17 Jan 2017 21:21:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E006F285E6 for ; Tue, 17 Jan 2017 21:21:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ACBDA285EA; Tue, 17 Jan 2017 21:21:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 73593285E6 for ; Tue, 17 Jan 2017 21:21:51 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cTbCQ-000551-RA; Tue, 17 Jan 2017 21:21:50 +0000 Received: from mail-lf0-x244.google.com ([2a00:1450:4010:c07::244]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cTbCF-0004lb-QC for linux-arm-kernel@lists.infradead.org; Tue, 17 Jan 2017 21:21:42 +0000 Received: by mail-lf0-x244.google.com with SMTP id x1so12513898lff.0 for ; Tue, 17 Jan 2017 13:21:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:subject:to:message-id:date:user-agent:mime-version :content-transfer-encoding; bh=4Ikduuzf9XM0VtmlNC3kr4wrseDcVbPC9KpzMyJbNWY=; b=CtHYSjBNTCPuJIb5yNcrUzUEVfOlionZugvBRz/hh5M0OGJOLazAwCgajXq99J4ghs P+Zya+t/B8Yd2yVeHg1prM0ohM/BRMU06ENh76d/GmtdjB2Zd/adTKZMrqI2BhpPIXaI 1iD7dSBQB6V/kEhu5jRr86wpx02dLwvPWqnShvsaDtev3ahJMHrPON2340UfeGRbdDdw oHDERuSjkPAsDAMqp0IHag/K7K6fO0HaP80Cc7RZgGzosqCHrAj55GTtfa+NwAqdIqDC upm57GBElPxWp+kvqH0CmyvJRVXN+jIhGEFW/XpJEnmQ4jPF9c2kRc+5r1Nn+senJA/B IVlw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:message-id:date:user-agent :mime-version:content-transfer-encoding; bh=4Ikduuzf9XM0VtmlNC3kr4wrseDcVbPC9KpzMyJbNWY=; b=mZmzBCWJVNDaEhqryZYwv2GOwLtDIXZDitKQIf2PJ8qkriOGGA/aErGCyWY67Xzku+ mlLKnx6JkrZ1FmBYf892A2yXg9MY8gqrFvmjoRhdKbDSX9CzI6ysiEs+McnDMmSJvAaZ cM9Lo3f5SFUmVgkLgmwqDYTfB4VYatv0sVLaL8trCMIYPnXsQU5d5XSyaT/zrI+Ertf6 RQlc6LH+7BETohrPgtCgZOuGkm8W/T83pw3Pzx+ckEvF/aH7zMa/gg/oWtoQzhrCBRpj FPrG8Iczn4JLxYXyR7p2CWGmeRAPxXp8MFLT1fpNohdg5B7Ug2SsnasbCUMwSQ2hJEIJ qAUw== X-Gm-Message-State: AIkVDXKonNdoLwp+5ATsP/QDjrocLkj0lPKiKDUu8YXF6c1DD3cwLe7eH5EYjekHK5Zg4g== X-Received: by 10.46.9.215 with SMTP id 206mr15340811ljj.3.1484688075481; Tue, 17 Jan 2017 13:21:15 -0800 (PST) Received: from [192.168.17.156] (h-38-149.a328.priv.bahnhof.se. [46.59.38.149]) by smtp.gmail.com with ESMTPSA id s6sm9762948ljd.42.2017.01.17.13.21.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Jan 2017 13:21:14 -0800 (PST) From: Magnus Lilja Subject: usb: gadget: Kernel panic (NULL pointer dereference) when using fsl_udc2_core on i.MX31 PDK To: balbi@kernel.org, gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, leoli@freescale.com, sojka@merica.cz, linux-arm-kernel@lists.infradead.org, Fabio Estevam Message-ID: Date: Tue, 17 Jan 2017 22:21:12 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170117_132140_190091_BC09E5BF X-CRM114-Status: GOOD ( 11.08 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Hi I tried the fsl_udc_core gadget driver on the i.MX31 PDK board and got a kernel panic (NULL pointer dereference) when connecting the USB cable. I had the g_serial module loaded as well. The NULL pointer panic comes from gadget/udc/core.c usb_gadget_giveback_request() which calls req->complete() and in some cases req->complete is NULL. Commit 304f7e5e1d08 ("usb: gadget: Refactor request completion") changed fsl_udc2_core.c (and several other files) and in fsl_udc2_core.c a check that req->complete is non-NULL was removed: If I re-introduce the check (either in fsl_udc_core.c or core.c) at least USB gadget operation using g_serial seems to work just fine. I don't know the logic in detail to understand whether this is a proper fix or if there is some other more problem with the fls_udc_core driver. Does anyone have input in this matter? I can produce a proper patch that fixes this problem by re-introducing the check (in either fsl_udc_core.c or core.c) if that is a proper solution and I can also assist in testing other fixes to the problem. Thanks, Magnus --- a/drivers/usb/gadget/udc/fsl_udc_core.c +++ b/drivers/usb/gadget/udc/fsl_udc_core.c @@ -197,10 +197,8 @@ __acquires(ep->udc->lock) ep->stopped = 1; spin_unlock(&ep->udc->lock); - /* complete() is from gadget layer, - * eg fsg->bulk_in_complete() */ - if (req->req.complete) - req->req.complete(&ep->ep, &req->req); + + usb_gadget_giveback_request(&ep->ep, &req->req); spin_lock(&ep->udc->lock); ep->stopped = stopped;