Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1655039pxb; Tue, 26 Oct 2021 13:08:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz6u/JFH1M2TLaXux7J+EJu1WdzmdU8Jtyn+Q8JEfPlbdPM8a6CoveLTK0+ILMPIMigIXpy X-Received: by 2002:a17:907:8a26:: with SMTP id sc38mr13167378ejc.38.1635278926793; Tue, 26 Oct 2021 13:08:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635278926; cv=none; d=google.com; s=arc-20160816; b=FIGOgP+h/hQgulqk5o6FgFCVb2u9YYEtFK0IJ5Npl+QoyO1l6Qf9kMR9C+Wm86tg+n dcD4vmQWRaq0JpvredB+izeZL3OL4AyBz3cnPFFM788VKHmXwlKNdqt+7mE+CWylx9at 6c6f4EpC7T+yMl+O/Mkoo2BHrNmfG+nVdWWT+6R7JCo7UI2mi6LYPOq9u5mPbTjnQfT+ o2iffFHN38tOQBMIAmIM4b2NTqRUh7DE7/SltA4mYDPRmFk1WDxTJnY/rwzVVg3qa6H8 sWvlBypl4kYFA9ZaEFEAv5tdzppTL3XpQz0K6yCvwPWRJPQhG9hGV5XEO6OhbXRWEGKl IRWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=Mgdel/4YxHebCWfONrz9Q4HWV8Qwh/srOXuWWESmKB0=; b=jSD51q1OaO1Vihsw0P5k89cyuxoSZl4+ivQFGYZXzJ1rvQ5dvGaF0vY9EhAoUE0ZPm biI3lLp4RYG4D37gkiGnLoOeR3jFtp2xOyDt9d7cGyBIFJK+Ukc3OX1+W8+h8G9zxamc /TUt50jiThSfGIrpcZeXIMQx5k9ToyOV5BgQJEQXhZuvjCcLscpshYkHKp8rQAnGLkyr a9s8R/c/kqb+rWVqg60Fu1k6liDebJMJfBikXtuMo9MzRPkfxIZhgURrz0bEY+eSrTvT SqDOMcXBvjPjr0UUswB6Ku035/puQitlX7EdAERv3g5mYUCGA3/rAHjAGowXsyVdFc9O CYpw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l16si28040458edj.324.2021.10.26.13.08.10; Tue, 26 Oct 2021 13:08:46 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236864AbhJZOoG (ORCPT + 99 others); Tue, 26 Oct 2021 10:44:06 -0400 Received: from netrider.rowland.org ([192.131.102.5]:41131 "HELO netrider.rowland.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S236851AbhJZOoE (ORCPT ); Tue, 26 Oct 2021 10:44:04 -0400 Received: (qmail 1289069 invoked by uid 1000); 26 Oct 2021 10:41:40 -0400 Date: Tue, 26 Oct 2021 10:41:40 -0400 From: Alan Stern To: Wesley Cheng Cc: balbi@kernel.org, gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Wesley Cheng Subject: Re: [PATCH] usb: gadget: f_mass_storage: Disable eps during disconnect Message-ID: <20211026144140.GA1288435@rowland.harvard.edu> References: <20211026004456.23054-1-quic_wcheng@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20211026004456.23054-1-quic_wcheng@quicinc.com> User-Agent: Mutt/1.10.1 (2018-07-13) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Oct 25, 2021 at 05:44:56PM -0700, Wesley Cheng wrote: > From: Wesley Cheng > > When receiving a disconnect event from the UDC, the mass storage > function driver currently runs the handle_exception() routine > asynchronously. For UDCs that support runtime PM, there is a > possibility the UDC is already suspended by the time the > do_set_interface() is executed. This can lead to HW register access > while the UDC is already suspended. > > Signed-off-by: Wesley Cheng > --- > drivers/usb/gadget/function/f_mass_storage.c | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/drivers/usb/gadget/function/f_mass_storage.c b/drivers/usb/gadget/function/f_mass_storage.c > index 3cabf7692ee1..752439690fda 100644 > --- a/drivers/usb/gadget/function/f_mass_storage.c > +++ b/drivers/usb/gadget/function/f_mass_storage.c > @@ -2342,6 +2342,16 @@ static void fsg_disable(struct usb_function *f) > { > struct fsg_dev *fsg = fsg_from_func(f); > > + /* Disable the endpoints */ > + if (fsg->bulk_in_enabled) { > + usb_ep_disable(fsg->bulk_in); According to the kerneldoc, this routine must be called in process context. > + fsg->bulk_in_enabled = 0; > + } > + if (fsg->bulk_out_enabled) { > + usb_ep_disable(fsg->bulk_out); > + fsg->bulk_out_enabled = 0; > + } > + > __raise_exception(fsg->common, FSG_STATE_CONFIG_CHANGE, NULL); > } Looks like you'll have to find a different way to avoid the problem. For example, if an exception is pending then you might prevent the gadget from going into runtime suspend until the exception has been handled. Alan Stern