From patchwork Wed Oct 27 20:10:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 12588007 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EA59BC433F5 for ; Wed, 27 Oct 2021 20:10:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D140260234 for ; Wed, 27 Oct 2021 20:10:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243847AbhJ0UMp (ORCPT ); Wed, 27 Oct 2021 16:12:45 -0400 Received: from alexa-out.qualcomm.com ([129.46.98.28]:54288 "EHLO alexa-out.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243835AbhJ0UMo (ORCPT ); Wed, 27 Oct 2021 16:12:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1635365418; x=1666901418; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=ZcejEIJ9EOZAgE5eHfWgNEFBqqGWcfS5JpCwc2ATJTM=; b=QgRSumWRJnPFjkNDNao5YJQr4zUF4rIf5TWfFJlDk9FiRw2TVw72t3rh NogT3tz+Nyc2XE1vZGkwG8pPxvOsazx6TOWiuhU86BgPjW2JZYe7loRkt rFAvI0K3AE/7lt3yZ06/Fa0jqCTz+C8q3ZthO+AvoOzUoIcxe0YaqcGgX A=; Received: from ironmsg09-lv.qualcomm.com ([10.47.202.153]) by alexa-out.qualcomm.com with ESMTP; 27 Oct 2021 13:10:18 -0700 X-QCInternal: smtphost Received: from nasanex01c.na.qualcomm.com ([10.47.97.222]) by ironmsg09-lv.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Oct 2021 13:10:17 -0700 Received: from nalasex01b.na.qualcomm.com (10.47.209.197) by nasanex01c.na.qualcomm.com (10.47.97.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.922.7; Wed, 27 Oct 2021 13:10:17 -0700 Received: from wcheng-linux1.qualcomm.com (10.80.80.8) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.922.7; Wed, 27 Oct 2021 13:10:16 -0700 From: Wesley Cheng To: , CC: , , , Wesley Cheng Subject: [PATCH v3 1/2] usb: gadget: udc: core: Revise comments for USB ep enable/disable Date: Wed, 27 Oct 2021 13:10:06 -0700 Message-ID: <1635365407-31337-2-git-send-email-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1635365407-31337-1-git-send-email-quic_wcheng@quicinc.com> References: <1635365407-31337-1-git-send-email-quic_wcheng@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01b.na.qualcomm.com (10.47.209.197) Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The usb_ep_disable() and usb_ep_enable() routines are being widely used in atomic/interrupt context by function drivers. Hence, the statement about it being able to only run in process context may not be true. Add an explicit comment mentioning that it can be used in atomic context. Signed-off-by: Wesley Cheng --- drivers/usb/gadget/udc/core.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c index d626511..568534a 100644 --- a/drivers/usb/gadget/udc/core.c +++ b/drivers/usb/gadget/udc/core.c @@ -91,7 +91,7 @@ EXPORT_SYMBOL_GPL(usb_ep_set_maxpacket_limit); * configurable, with more generic names like "ep-a". (remember that for * USB, "in" means "towards the USB host".) * - * This routine must be called in process context. + * This routine may be called in an atomic (interrupt) context. * * returns zero, or a negative error code. */ @@ -136,7 +136,7 @@ EXPORT_SYMBOL_GPL(usb_ep_enable); * gadget drivers must call usb_ep_enable() again before queueing * requests to the endpoint. * - * This routine must be called in process context. + * This routine may be called in an atomic (interrupt) context. * * returns zero, or a negative error code. */ From patchwork Wed Oct 27 20:10:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 12588009 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71EFBC4332F for ; Wed, 27 Oct 2021 20:10:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5E46960FC0 for ; Wed, 27 Oct 2021 20:10:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243836AbhJ0UMr (ORCPT ); Wed, 27 Oct 2021 16:12:47 -0400 Received: from alexa-out-sd-01.qualcomm.com ([199.106.114.38]:10131 "EHLO alexa-out-sd-01.qualcomm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243839AbhJ0UMo (ORCPT ); Wed, 27 Oct 2021 16:12:44 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; i=@quicinc.com; q=dns/txt; s=qcdkim; t=1635365418; x=1666901418; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=v1X2j5whadQ5qsqNX1PcC/XgYJy3oUyc4E5mS3fnRHY=; b=ciWrRGsD2Gz4Y9SnOVYxEwDg6ufU9G3k069406xbbWrz3SZ2Xio3SEro gM9IjE2Q0r7YhtqNqMxWEQg9jt57ivytU8CsC5vpbvZbQkNjqTgxDfxXh /tQhm8qPTW5wSf/ved/qkYb6IGdnFvdN8cQhGK6PqSJYbejQsZi8t3iCp o=; Received: from unknown (HELO ironmsg-SD-alpha.qualcomm.com) ([10.53.140.30]) by alexa-out-sd-01.qualcomm.com with ESMTP; 27 Oct 2021 13:10:18 -0700 X-QCInternal: smtphost Received: from nasanex01c.na.qualcomm.com ([10.47.97.222]) by ironmsg-SD-alpha.qualcomm.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Oct 2021 13:10:18 -0700 Received: from nalasex01b.na.qualcomm.com (10.47.209.197) by nasanex01c.na.qualcomm.com (10.47.97.222) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.922.7; Wed, 27 Oct 2021 13:10:17 -0700 Received: from wcheng-linux1.qualcomm.com (10.80.80.8) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.922.7; Wed, 27 Oct 2021 13:10:17 -0700 From: Wesley Cheng To: , CC: , , , Wesley Cheng Subject: [PATCH v3 2/2] usb: gadget: f_mass_storage: Disable eps during disconnect Date: Wed, 27 Oct 2021 13:10:07 -0700 Message-ID: <1635365407-31337-3-git-send-email-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1635365407-31337-1-git-send-email-quic_wcheng@quicinc.com> References: <1635365407-31337-1-git-send-email-quic_wcheng@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.80.80.8] X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01b.na.qualcomm.com (10.47.209.197) Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org 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 3cabf76..7524396 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); + 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); }