From patchwork Fri Mar 17 05:52:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xu Yang X-Patchwork-Id: 13178543 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74848C74A5B for ; Fri, 17 Mar 2023 05:50:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229693AbjCQFuP (ORCPT ); Fri, 17 Mar 2023 01:50:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48334 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229523AbjCQFuM (ORCPT ); Fri, 17 Mar 2023 01:50:12 -0400 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on2079.outbound.protection.outlook.com [40.107.8.79]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B0AFC1ADE1 for ; Thu, 16 Mar 2023 22:50:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=luRYPZ3zcrA9WTkRNlEFiBib82TxYw/E54kc4nXxg0LZXkAHlPjPTVVUipmnuJfVLBemOGBo2UQdvhrCYbPKGG3QdiWNYnVceqrHCyz5o1IT/D9zcv3HkXc/onlzmRlLrfKMU3o37eU7lnPs1Wz0JzXA0VIe4t09+uLpl8l5xy4jje25eHwmKtfjaseDq7zKsqUlDV0cIm8G0eZpNNT3MDHHtggfTye8JNCKhGlJzp8BbL7tsV57bnAt/H+OzzF5MFI6Gz9dyM4iiTrWpvIjGhKsCb4JC83S/ZXHAadmPyNmU7CF80I99gz3nbRb7pQdW3909jVcBa6UantzVEDh1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Aa0jrAlIfFnp1eQHifxu8upj210L829UF6/5n83kDOc=; b=oOl/0loz+QGCSWkWQxNDNyc0eEvqUDmuwxygr+x4D2P9ZtDepHIqvb9eh68uOstTrexRrccozeTVvZFzVLMAvqt3uajrvNhhv/NOJC483e5j1Kj/Y/c58/YdIMzuPf08hqO6F2Ym7pzAUoJhaku7h6+zIo0XuLJbwnwXkjuhGli8QYh1xuL8Y5bmYVtsmbzZODjnghzUsIBXcQ1GuPutAM/41sqJa+jm2fjQqDC6o4ValW0ysoPnqbMjlDjXcy2e10px6Epr2p01GCEZblvz6ft7JuitehF7qxDBMWxwD4ytPEPxH0zlwJvNHj7d+YePOSzKovqQ6UsmbLp2EXY4Uw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Aa0jrAlIfFnp1eQHifxu8upj210L829UF6/5n83kDOc=; b=Qqx82XPaezyXYoSxGo8fk6+NU9mfnu80pc3QFeqCFf0m9CbjEKBO1XwgXZh9aO6XDwn5HzEVS1wkCrNOt3009MtTBRGp9a/L38PKruQ8KCoFWiX4E7FNzl8gqIuevIYNo9O7cvETQScjIrQbkPEC5PVYgvONlMUihjXq4LEcpas= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DB7PR04MB4505.eurprd04.prod.outlook.com (2603:10a6:5:39::26) by VI1PR04MB7088.eurprd04.prod.outlook.com (2603:10a6:800:11d::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.35; Fri, 17 Mar 2023 05:50:01 +0000 Received: from DB7PR04MB4505.eurprd04.prod.outlook.com ([fe80::5466:bfa2:3158:97c6]) by DB7PR04MB4505.eurprd04.prod.outlook.com ([fe80::5466:bfa2:3158:97c6%3]) with mapi id 15.20.6178.035; Fri, 17 Mar 2023 05:50:01 +0000 From: Xu Yang To: peter.chen@kernel.org Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-imx@nxp.com, jun.li@nxp.com, xu.yang_2@nxp.com Subject: [PATCH RESEND v2 1/2] usb: chipdea: core: fix return -EINVAL if request role is the same with current role Date: Fri, 17 Mar 2023 13:52:01 +0800 Message-Id: <20230317055203.2366868-1-xu.yang_2@nxp.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: SG2PR02CA0109.apcprd02.prod.outlook.com (2603:1096:4:92::25) To DB7PR04MB4505.eurprd04.prod.outlook.com (2603:10a6:5:39::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB7PR04MB4505:EE_|VI1PR04MB7088:EE_ X-MS-Office365-Filtering-Correlation-Id: b9bd702c-5306-4acd-c7ba-08db26ab730d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: oujnVhEaAA2rpRdSrTPesmFKw+wHiPAcQ34VeJqJdhDdKrGjzStnLi8WtEtcoYCEe5B6TFDo6PcF1bmXeke10QFSnsvgip2qafwz8QXGpOB3Kzdjv2rppE/yFAtsr3YZCG1pcvhsGxp5FGPCgePk/Srp0cDPeqZ6iuTH9Si2tFSV/Sum1loqC7wBR166w/6f9+IIeJBsJgU04azX6zRojQH1pboZMzV1gTcF1qK3V6ISKea6+gn4yViODhueYk6qwizySUNgt5gzDbE2f7/4JdcvPN4Jul2PDnDMXuxLl6GK6FXuRGh4dm8ckAniu7/oEtKFj3XH4Aq6lAKg5HcpMCViKZZy8eixOM8DeH/K9wesZAvh2yi5Rn6I8YUCCSFxuAs7VVvPMFz7i8nj7j/suFG83Ho2/1yEvQpTQiGBNwJW2BEN8A9iRRmjXcHYWCekn6gvwvJsdLRlLl17dlTQQqLaroiXVWRnYjLtwdM88C45aurhND1aoWVy6Y/8Nc61Fun+MBSgQOm+rLhrPPoFPABprOKkfNdtKLH80xsMOmeox/vOitos0F4SkmYjUSZ243Spuy8fBLX2Q57zdkuykX7Ae03AudELQbuaSkiTuLrP0gGhiL6hlGD4dkc5QUclIhZWhEergCuIoessdspqz4Ybrmm/K2OTMs/7A3YXjhXJ37UBG3phmX9wwUOSKJjqvLOXb1Ci6N+Zg/rUP90nqw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DB7PR04MB4505.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(136003)(366004)(376002)(346002)(39860400002)(396003)(451199018)(8936002)(6486002)(52116002)(66946007)(8676002)(66476007)(66556008)(4326008)(6916009)(186003)(41300700001)(1076003)(6506007)(6512007)(2616005)(36756003)(26005)(2906002)(4744005)(86362001)(478600001)(316002)(38100700002)(38350700002)(5660300002)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: UYrpW70yYH6lguvTC10EEPxYYnAHcAhYaN27Jx//BdBD9ZrhLzULUO/C93YqTZgE3RglKdGHtlFo1MgVM1IgD7/X7NCHThxD4g3bc7C2jMM1EwtO0lANz9GEtk4u+93js+c3XGuo89GvLjBx2jAytuxFnTbAqRPxPv8Q8Cp14DaFAPhRKBjtBEAiXTC1CPvLtmJChcs65QX+XG1x6l8PUfAjAJLczcD3JrzO26pLjHVzT+tF6WuEnf7ug0rGR9YhqWYnOcEMzwdjti20rdm5CvxatsrnUG0Tu7Xk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irdA3yOaWGS5BTf0Py/8RpqDPC/lTGvmUG0uq0lbjKMLoobprgCPH6qfF6npw2xYI7DjgejJO8S+dS+sKX761IB3bg6ribNVvMxXMieRBEzvz5xgUUc7ujWbQq1fAuHxczk55W7gbAbbL21t4co+B3DY4V3XgCBqEYRCkxqT5bsUpRfVv+IMB6U7VuUMCDPBBF5ja1Rrfp7hxwlrGqAiSNlWyx8KMg9W8zwc1TMIGoAKLUN1OT X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: b9bd702c-5306-4acd-c7ba-08db26ab730d X-MS-Exchange-CrossTenant-AuthSource: DB7PR04MB4505.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Mar 2023 05:50:01.8040 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: i8zbR+12+Oc4/3CgyiAYehZ2MONFqfLZ9cTGCm/s1ff17ye0EPWNCrMAV0HljUkFVWL2v9ujWRcWnrFXehQC7w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB7088 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org It should not return -EINVAL if the request role is the same with current role, return non-error and without do anything instead. Fixes: a932a8041ff9 ("usb: chipidea: core: add sysfs group") cc: Acked-by: Peter Chen Signed-off-by: Xu Yang --- changes since v1: - no change --- drivers/usb/chipidea/core.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c index 7ccb223ed53c..eae4bf865a8e 100644 --- a/drivers/usb/chipidea/core.c +++ b/drivers/usb/chipidea/core.c @@ -984,9 +984,12 @@ static ssize_t role_store(struct device *dev, strlen(ci->roles[role]->name))) break; - if (role == CI_ROLE_END || role == ci->role) + if (role == CI_ROLE_END) return -EINVAL; + if (role == ci->role) + return n; + pm_runtime_get_sync(dev); disable_irq(ci->irq); ci_role_stop(ci); From patchwork Fri Mar 17 05:52:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xu Yang X-Patchwork-Id: 13178544 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 27017C6FD1D for ; Fri, 17 Mar 2023 05:50:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229669AbjCQFuS (ORCPT ); Fri, 17 Mar 2023 01:50:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229523AbjCQFuQ (ORCPT ); Fri, 17 Mar 2023 01:50:16 -0400 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on2079.outbound.protection.outlook.com [40.107.8.79]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01F5B2CFD1 for ; Thu, 16 Mar 2023 22:50:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PhdLkcXQaOpbiChoqOv3nE6ryr/zwBYXczY+d9FNgDijGOc5cwNkuX2Cj7CBrk9shSq2ZyFAMPwkE/vCJoodE8BRvAasSvaoq4ypLU/ZePDizcfJviQDpCHUkVP65ucLwow9MGeniojlPKl43n3XRT8+xryWUti0uf2Wm5uKFJgkx1De9aMeeYHx7S0s4QgUZHc+SuH6d8PgbDGhmZ15989Gp26IDJQCq7GIC0+G20MKiuqPlwcViv1kUO+kOBlJw0q9EIcGo5DI+BpnPDxadYGde3K9Q71LzonLrHZFxkjt2Mxk2p79ppaq911o5rspUIkfwG2MjG+4t5ZJM/4VGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=miOILX71lbWlWhBkYPTSuOGLWuulp/7a3EHAggB4vuw=; b=Mnbm4H33JKHrDpMdXGMhkx/VWf6hMty2yWIV0T5RaBNsepPFey2q0ZvSsdzV1uV/bd/VvBZLFci+Nr7i8CSp0q6/son6p5+4qHDAx7SRn1V3u7OKSKjYiw6olEHWbG+c49I0abfiyQiwkSOpAuec/yvY1NXeJTpLKkfiCJscr1zyKfE7EXObMXETZmnXjx+PPdzB2Lj8HdDOKkBaWyYTZf3rrblNJUzur8DEbpIwahQ1fKAGLjbZphdut10HwdqLidd7u23oAIDMfqZROPMDLmvbz/KACTGW3NFb+ik8qSpoLu1oJZvlZpxYtDAcVOSzBN0KXpQ7+EK0677F0mI1+Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=miOILX71lbWlWhBkYPTSuOGLWuulp/7a3EHAggB4vuw=; b=ByfPIxNN6Yw9DcCbWzRk0PZNnn23N4ZwUVbr9xf8SzRf2a4XRHedXk4cjWoSaxe8GrNNOmnzh3TrPACIIy5slvuQJtW/TcQlljzwM5FYb9UtwkupWVGJn0Wojv+PRDil1vKDT/9zUhi4c+G0iH3kG9SsKAhG5HWUkKEMX8SA9u8= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DB7PR04MB4505.eurprd04.prod.outlook.com (2603:10a6:5:39::26) by VI1PR04MB7088.eurprd04.prod.outlook.com (2603:10a6:800:11d::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.35; Fri, 17 Mar 2023 05:50:03 +0000 Received: from DB7PR04MB4505.eurprd04.prod.outlook.com ([fe80::5466:bfa2:3158:97c6]) by DB7PR04MB4505.eurprd04.prod.outlook.com ([fe80::5466:bfa2:3158:97c6%3]) with mapi id 15.20.6178.035; Fri, 17 Mar 2023 05:50:04 +0000 From: Xu Yang To: peter.chen@kernel.org Cc: gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-imx@nxp.com, jun.li@nxp.com, xu.yang_2@nxp.com Subject: [PATCH RESEND v2 2/2] usb: chipidea: core: fix possible concurrent when switch role Date: Fri, 17 Mar 2023 13:52:02 +0800 Message-Id: <20230317055203.2366868-2-xu.yang_2@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230317055203.2366868-1-xu.yang_2@nxp.com> References: <20230317055203.2366868-1-xu.yang_2@nxp.com> X-ClientProxiedBy: SG2PR02CA0109.apcprd02.prod.outlook.com (2603:1096:4:92::25) To DB7PR04MB4505.eurprd04.prod.outlook.com (2603:10a6:5:39::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB7PR04MB4505:EE_|VI1PR04MB7088:EE_ X-MS-Office365-Filtering-Correlation-Id: 75a85215-9fbe-48f2-5daf-08db26ab7492 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nacoCReWN5c5SivgvXRE7fwf0V3jxn//RiVWQDbhG7UmzuEIOLD2f8WDVLbLemf9DkTc65FBid67cdTavYPuJT7xqiKkB7wevC0PZcGnS1rrgynLEmeSPKKGzSiC80qX90QeY83bDLHrmkJRQRq7MoM8WCh+3A+gkH+UAaXvQblG0FJ6CFYoMbJPIIhPOgcRT7gU2vHyYn/VWsbExQ9NpqzRQ2xqp8jNENgJ3D5NXLEiGHtvkTd5243R6ma9cGiU0uhbyPjhLY+GOqOy7elvF+BhTsfHjT8tqhW6Z9dNXPSyx29TNBbKsWaV2PPP5LTl9nJwd3R2s40jsdhHm7kGxNf/qVArlrfixRfs6IQLXgJwhBJgzOc2mLQhZLHJ7JacHDaDATnaqgE8wb56T3ofxAIAoEihnwJSEPppeL7XXyIJGPHi+gzZu2a+tUrWsE35EDFfAvZqIQUlELKejbbnZ3FC7Dg3B6JpaooDpWnv01j7Ltex+ncyt4YASwLTWFhaTIZlvrSEAT78/lm32BtpumCk347YBUjng3S30eaqEzPaqIo1wfTAejlsPR3N/+RTws/V6blr4QBpm8XubMJ+o4qmPfbQ4AscGUZNR5SRVGEJ1a5WYiAxEfBZ/VBAGezOYrWiTrw4nnJ0gBxwnYYkYmt8Tk5RNKFHo4gqMaZJjGt6BvgWE3yMoGDoupRB7dO0i9so2BQ36fFSrN1lFDRvGg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DB7PR04MB4505.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230025)(4636009)(136003)(366004)(376002)(346002)(39860400002)(396003)(451199018)(8936002)(6486002)(52116002)(66946007)(8676002)(66476007)(66556008)(4326008)(6916009)(186003)(41300700001)(1076003)(6506007)(6512007)(2616005)(36756003)(26005)(2906002)(86362001)(478600001)(316002)(38100700002)(38350700002)(5660300002)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: TLK7T4jnVca4JGvyNHlgTomHvn+NMY9OKLQD5nRNREB++c4wCjkQ0rlC/F2gVSct2b3zUy8ilyJXIjfsGRL6wNChh8cbl8704oKvHv5wT4UjRuhEL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9bNWOinZYzZcBnSK2d2rPUSMsxHIh2AdM715/Gc9jgacqsqx8X/npueXxF1okOqKQlatJ5lDCXbC9LRSnFwlEy7MvgG+Sx5SffSgkkQg4JPghPe0RtHP7hehT0Oe3Yj/wN2iQQHhneYiOzYkTC1KQ9IBNngXwxT5ijyYxRBd9zw26hz2FUh0ZZmFOQdcBbjx671eNfvw2ADrtQwQn/xV7gvpga+mbY5UyOCSN1vOI7sYxXztYxOLdWwcvD6EqcJ7zm75PYtilpVqQL0J7Z5neONhA2y1hg7pbiWuLuwTMoIoWXrvrwD5qXIbCANd4UemvZr6XRB/hAvft0xjf+yi35h/TUkedhy45JhCzLXebRkPypxTkUl9hM3JI2zp6+vVz3RKu77eSU/O8quCa X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 75a85215-9fbe-48f2-5daf-08db26ab7492 X-MS-Exchange-CrossTenant-AuthSource: DB7PR04MB4505.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Mar 2023 05:50:04.1944 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: XEyfseEz7HCJUTsMGcFLpsRNdPlICbFEYtjrl90lkJRz2IjYjjk+lUrHGstuJ+QXmpNfClQpiX4ojkiKVb/mrg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB7088 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org The user may call role_store() when driver is handling ci_handle_id_switch() which is triggerred by otg event or power lost event. Unfortunately, the controller may go into chaos in this case. Fix this by protecting it with mutex lock. Fixes: a932a8041ff9 ("usb: chipidea: core: add sysfs group") cc: Acked-by: Peter Chen Signed-off-by: Xu Yang --- changes since v1: - modify description for mutex member - wrap role variable in ci_handle_id_switch() too --- drivers/usb/chipidea/ci.h | 2 ++ drivers/usb/chipidea/core.c | 8 +++++++- drivers/usb/chipidea/otg.c | 5 ++++- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/usb/chipidea/ci.h b/drivers/usb/chipidea/ci.h index 005c67cb3afb..f210b7489fd5 100644 --- a/drivers/usb/chipidea/ci.h +++ b/drivers/usb/chipidea/ci.h @@ -208,6 +208,7 @@ struct hw_bank { * @in_lpm: if the core in low power mode * @wakeup_int: if wakeup interrupt occur * @rev: The revision number for controller + * @mutex: protect code from concorrent running when doing role switch */ struct ci_hdrc { struct device *dev; @@ -260,6 +261,7 @@ struct ci_hdrc { bool in_lpm; bool wakeup_int; enum ci_revision rev; + struct mutex mutex; }; static inline struct ci_role_driver *ci_role(struct ci_hdrc *ci) diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c index eae4bf865a8e..d1d252c87e4f 100644 --- a/drivers/usb/chipidea/core.c +++ b/drivers/usb/chipidea/core.c @@ -987,8 +987,12 @@ static ssize_t role_store(struct device *dev, if (role == CI_ROLE_END) return -EINVAL; - if (role == ci->role) + mutex_lock(&ci->mutex); + + if (role == ci->role) { + mutex_unlock(&ci->mutex); return n; + } pm_runtime_get_sync(dev); disable_irq(ci->irq); @@ -998,6 +1002,7 @@ static ssize_t role_store(struct device *dev, ci_handle_vbus_change(ci); enable_irq(ci->irq); pm_runtime_put_sync(dev); + mutex_unlock(&ci->mutex); return (ret == 0) ? n : ret; } @@ -1033,6 +1038,7 @@ static int ci_hdrc_probe(struct platform_device *pdev) return -ENOMEM; spin_lock_init(&ci->lock); + mutex_init(&ci->mutex); ci->dev = dev; ci->platdata = dev_get_platdata(dev); ci->imx28_write_fix = !!(ci->platdata->flags & diff --git a/drivers/usb/chipidea/otg.c b/drivers/usb/chipidea/otg.c index 622c3b68aa1e..f5490f2a5b6b 100644 --- a/drivers/usb/chipidea/otg.c +++ b/drivers/usb/chipidea/otg.c @@ -167,8 +167,10 @@ static int hw_wait_vbus_lower_bsv(struct ci_hdrc *ci) void ci_handle_id_switch(struct ci_hdrc *ci) { - enum ci_role role = ci_otg_role(ci); + enum ci_role role; + mutex_lock(&ci->mutex); + role = ci_otg_role(ci); if (role != ci->role) { dev_dbg(ci->dev, "switching from %s to %s\n", ci_role(ci)->name, ci->roles[role]->name); @@ -198,6 +200,7 @@ void ci_handle_id_switch(struct ci_hdrc *ci) if (role == CI_ROLE_GADGET) ci_handle_vbus_change(ci); } + mutex_unlock(&ci->mutex); } /** * ci_otg_work - perform otg (vbus/id) event handle