Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp2652677pxa; Mon, 17 Aug 2020 15:34:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyB1NK92ZToYybDWo1Q8faSTKZDHdKOCdmcD6KUFXgKnpDa8x2c812/m7KtUZNkdKrGNUyN X-Received: by 2002:a05:6402:c84:: with SMTP id cm4mr16874337edb.20.1597703695528; Mon, 17 Aug 2020 15:34:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597703695; cv=none; d=google.com; s=arc-20160816; b=qaYUAme93tAtSfP0dyQFV5ztQ6itqYhgAkzvUsbacGcR4wMX5W86uqaqYlXTPhDegR 1JxTN21QXewNcUNYguWGeIa5lZP09RyInBPURWwGqYvJYRh/q6v+pdtSCatCco892cR6 xfcaDmelbrfm2XKP1wtHKRc49FLSje+UtvEfZkI6vLkmC+7d8pAO+KGSfT4MLFblNM78 ztK2iBE2jtYzZpcmUoxLkIFnwyblzA+shGxlRZe9mBUktkQefOXnOksjhE7ZNfvonTHy DEPVyZahRI9RM0X5r0T7BU+OVFSIwGSpuBTf0iXuxfJ/j+v0uTtfz/bMP5ywPo1zxcnY d3jQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=YWQVMAJ2megRb3136vzwNP7qe2n+NaXBX7fYn46/yHM=; b=W1Ve/LxWxI0mFlIA30KvL2o2OCti4aLkTqF+4Xg9q02QJ15BnmNl1voawJJa89JlKL lSKkoYmQyNoDfSXtL/9SGWjZwhnyrz4CngO+pcsyI5tNMCZjHoT/DXdCtIp3YHhSdkWC qk3qZzYzLgD7GuxSa6ELgpiieo8IGCBtt2zfYJ2+wcWGU3NIDvvildDNK5bs89+Vr0Z5 nQPVdjieQnAap1CGZBTA2FlW+kz/TTSA69UOkGstpt8EPeDbbhj4J8UJSbpZsNT53za0 VHlxUbqNYKEu4ET/fkRhZY9CfeCJusKSgAxh0JYcUTuGPssjaHblSuaM6I6l72BgKC3S wiTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=SRA6LPiD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k22si11732970edx.491.2020.08.17.15.34.32; Mon, 17 Aug 2020 15:34:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=SRA6LPiD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389536AbgHQRPC (ORCPT + 99 others); Mon, 17 Aug 2020 13:15:02 -0400 Received: from mail.kernel.org ([198.145.29.99]:45546 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388464AbgHQQMr (ORCPT ); Mon, 17 Aug 2020 12:12:47 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5CAA520658; Mon, 17 Aug 2020 16:12:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597680766; bh=ARaebd6r23AHRp7i41bEOBhp4oRUZXhVKblrjOHtCy8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SRA6LPiDq303qNs/72oIvkoUi6/JLITQIfTpEPGen5ptHqSAwtAKDfDKPfATa1yBX D2Th6GHBHYvIVZ9497dHu1uM2bI3kg1dxocqHNGTx1nJ4qrEWNQoo1Ew893e/IUGPK qKzlRRuW5oDQhzYFD/ZGqA9cGxSFgIoNBgHn3OSA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sasi Kumar , Al Cooper , Florian Fainelli , Felipe Balbi , Sasha Levin Subject: [PATCH 4.19 049/168] bdc: Fix bug causing crash after multiple disconnects Date: Mon, 17 Aug 2020 17:16:20 +0200 Message-Id: <20200817143736.202324557@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200817143733.692105228@linuxfoundation.org> References: <20200817143733.692105228@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sasi Kumar [ Upstream commit a95bdfd22076497288868c028619bc5995f5cc7f ] Multiple connects/disconnects can cause a crash on the second disconnect. The driver had a problem where it would try to send endpoint commands after it was disconnected which is not allowed by the hardware. The fix is to only allow the endpoint commands when the endpoint is connected. This will also fix issues that showed up when using configfs to create gadgets. Signed-off-by: Sasi Kumar Signed-off-by: Al Cooper Acked-by: Florian Fainelli Signed-off-by: Felipe Balbi Signed-off-by: Sasha Levin --- drivers/usb/gadget/udc/bdc/bdc_core.c | 4 ++++ drivers/usb/gadget/udc/bdc/bdc_ep.c | 16 ++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/drivers/usb/gadget/udc/bdc/bdc_core.c b/drivers/usb/gadget/udc/bdc/bdc_core.c index 01b44e1596237..4c557f3154460 100644 --- a/drivers/usb/gadget/udc/bdc/bdc_core.c +++ b/drivers/usb/gadget/udc/bdc/bdc_core.c @@ -283,6 +283,7 @@ static void bdc_mem_init(struct bdc *bdc, bool reinit) * in that case reinit is passed as 1 */ if (reinit) { + int i; /* Enable interrupts */ temp = bdc_readl(bdc->regs, BDC_BDCSC); temp |= BDC_GIE; @@ -292,6 +293,9 @@ static void bdc_mem_init(struct bdc *bdc, bool reinit) /* Initialize SRR to 0 */ memset(bdc->srr.sr_bds, 0, NUM_SR_ENTRIES * sizeof(struct bdc_bd)); + /* clear ep flags to avoid post disconnect stops/deconfigs */ + for (i = 1; i < bdc->num_eps; ++i) + bdc->bdc_ep_array[i]->flags = 0; } else { /* One time initiaization only */ /* Enable status report function pointers */ diff --git a/drivers/usb/gadget/udc/bdc/bdc_ep.c b/drivers/usb/gadget/udc/bdc/bdc_ep.c index d49c6dc1082dc..9ddc0b4e92c9c 100644 --- a/drivers/usb/gadget/udc/bdc/bdc_ep.c +++ b/drivers/usb/gadget/udc/bdc/bdc_ep.c @@ -615,7 +615,6 @@ int bdc_ep_enable(struct bdc_ep *ep) } bdc_dbg_bd_list(bdc, ep); /* only for ep0: config ep is called for ep0 from connect event */ - ep->flags |= BDC_EP_ENABLED; if (ep->ep_num == 1) return ret; @@ -759,10 +758,13 @@ static int ep_dequeue(struct bdc_ep *ep, struct bdc_req *req) __func__, ep->name, start_bdi, end_bdi); dev_dbg(bdc->dev, "ep_dequeue ep=%p ep->desc=%p\n", ep, (void *)ep->usb_ep.desc); - /* Stop the ep to see where the HW is ? */ - ret = bdc_stop_ep(bdc, ep->ep_num); - /* if there is an issue with stopping ep, then no need to go further */ - if (ret) + /* if still connected, stop the ep to see where the HW is ? */ + if (!(bdc_readl(bdc->regs, BDC_USPC) & BDC_PST_MASK)) { + ret = bdc_stop_ep(bdc, ep->ep_num); + /* if there is an issue, then no need to go further */ + if (ret) + return 0; + } else return 0; /* @@ -1911,7 +1913,9 @@ static int bdc_gadget_ep_disable(struct usb_ep *_ep) __func__, ep->name, ep->flags); if (!(ep->flags & BDC_EP_ENABLED)) { - dev_warn(bdc->dev, "%s is already disabled\n", ep->name); + if (bdc->gadget.speed != USB_SPEED_UNKNOWN) + dev_warn(bdc->dev, "%s is already disabled\n", + ep->name); return 0; } spin_lock_irqsave(&bdc->lock, flags); -- 2.25.1