Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp777974ybh; Tue, 21 Jul 2020 07:45:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxWbf1wPYSbqajR3Z7YA+Etf9CwIUzdN2ZhV/eTP5q1ooTgUKKu61E0ordtZggx0wcsmMrv X-Received: by 2002:a17:906:3816:: with SMTP id v22mr15048328ejc.332.1595342702542; Tue, 21 Jul 2020 07:45:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595342702; cv=none; d=google.com; s=arc-20160816; b=w0RNluPAQx7wUXcgs3DqdxiSw28BpcXaG78+J57rQW12hP9u4AP3JMmFawFKQcVrit pyjmN9SxNw2YZ0xc/ShsR0xah0CUGPZ9VkvaNIx39eFvVOPT5EFSPoBlYVXKGK9ztzzU 1uTP9I5W4XkdhkBR2+4MzbrrXablxS40MMsYQHnsh8PmFwldwQrrXilXkPDLt3QvZN99 QWiR9KSw1XvIsMQLE4//d6it5BHZ1VWXYOtoKL1QWBzQ0D+25R76hXoEZE/KOIe1SJOV bYG3kDfo9+hkkz/m7DHMZAS7YOOxhnfe5n3hpH0gCEv0kwIlMcG7JJwQScAaMusTmW8C kb+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=zFRW11/heyizj2QZJPL2QMgceFRIzgQa3xn1BGXBSyA=; b=dPB6A/R4KkGOs1uPgTuM1WY+2DlH9vreP2yxZl9hLI/jOb8fPzitT+al2WcyoAEGPe ZDuTMUrZIGE6ehPQqRJa6gUqRudpVjjdJVcT44pw3W9FaYvYARbYgDnwhXVb9GOiu+qa azZY2ll4FA0d4q+M26FdhIRV9k4BMq3tQH3iy4NCK+yxGZtHkwWragbCKAWYum6PnsRn wer0shgtSaF2rhViwk5QG026R5tC+9/Qkn/op0lyQ1ohqaRKvXe3OaouKlHT6ckXkHe2 hoFsj6NB400liaeNcCp5ox3F8uwJnkK6oaOFVFbtg6utd+p2J4RKhhTosOjGgHIYa0YW obVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=bCFvKqDX; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x4si12712971edq.506.2020.07.21.07.44.39; Tue, 21 Jul 2020 07:45:02 -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=@gmail.com header.s=20161025 header.b=bCFvKqDX; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729702AbgGUOn5 (ORCPT + 99 others); Tue, 21 Jul 2020 10:43:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726710AbgGUOn4 (ORCPT ); Tue, 21 Jul 2020 10:43:56 -0400 Received: from mail-wm1-x342.google.com (mail-wm1-x342.google.com [IPv6:2a00:1450:4864:20::342]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC644C061794; Tue, 21 Jul 2020 07:43:55 -0700 (PDT) Received: by mail-wm1-x342.google.com with SMTP id 184so3168911wmb.0; Tue, 21 Jul 2020 07:43:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zFRW11/heyizj2QZJPL2QMgceFRIzgQa3xn1BGXBSyA=; b=bCFvKqDXVub2qkB9Bl6sG8ZzR78ncR9CNECo8vYQkXrHxMZH3OeyHKqVCpbUMUFKLm 9UowELavNsk6T5L3BOoHYviyVJGNOmgup8IGUn1iFNSkNq/9iqIisTEp24cTFPt8/Iog XPX4Pd7Wtdw5gic7khwZA6DOU88c7nty9oYe/E7V8xUmFCVOrZzkG+JXWYvTejqVHg1i lSLhTMf8p7kEQqnBNZH4+B4z/mD4gM3eEgJYgZLZCkccmUnVsBYLHIvn+zoh7t3fRf/h dYWQfjVqahe0vqF2bv+LE45ZzouAa/WP0n5XTa2CaNcc++TshMa2DIHYj83fuCTs3JQ/ eQHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=zFRW11/heyizj2QZJPL2QMgceFRIzgQa3xn1BGXBSyA=; b=tZJDDBdel62KChC1vjRM8UlbZFUOymBB1TEcdBHp8qhvcJjIdiFItNrUxmejk6nIgO bhpwUZNKNmX+d/1a03TQPdncWoWo5Lc0lseObyQuc5Mt0fM/W2DhzOxug4vr8h0Oshkk jUGxBEOxAHby2M8lA4mgELn9kETku+qXxL7bgXeeM8NO/Ii1b4Jn7B5ZriooQ9IxtTxj FhTck3H1fFW3ZZT973lrEn+LVTvoEqVKguMdXvnTnOngu3FPwbJ6kEzuJ21rOwm+Bxaf wN+3tFO/nzydeCnJJQIzLz5oD4XFo1AGMd86lO5uw4YUufnR0jbHa8aKEiLyQrrdXNBI JPjA== X-Gm-Message-State: AOAM532pgrrsRbr+02MXs0e+1I9QHdh65KPkhAaBYCb/ijnweoiUSRf2 OVuaOCyp1xGvMdKThoeLIHifaEBh X-Received: by 2002:a7b:ca52:: with SMTP id m18mr4349730wml.92.1595342634347; Tue, 21 Jul 2020 07:43:54 -0700 (PDT) Received: from stbsrv-and-01.and.broadcom.net ([192.19.231.250]) by smtp.gmail.com with ESMTPSA id y6sm38043116wrr.74.2020.07.21.07.43.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Jul 2020 07:43:53 -0700 (PDT) From: Al Cooper To: linux-kernel@vger.kernel.org Cc: Sasi Kumar , Al Cooper , devicetree@vger.kernel.org, Felipe Balbi , Florian Fainelli , Greg Kroah-Hartman , linux-usb@vger.kernel.org, Rob Herring Subject: [PATCH v2 3/7] bdc: Fix bug causing crash after multiple disconnects Date: Tue, 21 Jul 2020 10:43:22 -0400 Message-Id: <20200721144326.7976-4-alcooperx@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200721144326.7976-1-alcooperx@gmail.com> References: <20200721144326.7976-1-alcooperx@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sasi Kumar 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 --- 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 18d510fc02fb..b70b438efff4 100644 --- a/drivers/usb/gadget/udc/bdc/bdc_core.c +++ b/drivers/usb/gadget/udc/bdc/bdc_core.c @@ -282,6 +282,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; @@ -291,6 +292,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 d49c6dc1082d..9ddc0b4e92c9 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.17.1