From patchwork Fri Mar 17 06:15:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xu Yang X-Patchwork-Id: 13178563 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 09F1EC6FD1D for ; Fri, 17 Mar 2023 06:13:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229680AbjCQGN5 (ORCPT ); Fri, 17 Mar 2023 02:13:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229477AbjCQGNz (ORCPT ); Fri, 17 Mar 2023 02:13:55 -0400 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2063.outbound.protection.outlook.com [40.107.21.63]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CEDD7D538 for ; Thu, 16 Mar 2023 23:13:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RPsshA7hs2vhjYhrkTFuATnKOTAkoijZoTG+ReyBVmiffIAFil2XvdtFe7qjmWucXPYQ7qxiJdn17eNQLDUX4UQzUaD1whszjefMBo/NJJ7wvFLQdhf2QclxFgYwVldPxqKqmrE3d1ayT/H3duNHiQatV4j7rc7+yRuqjpr3lnAEAuli8wVV5PU9o6Sa31STKKIAvyBsNI/nXmh201jkcTLQsuxd4esKnkhepEe+YCxLq7DFqxOaJfvxIlXtD4xkr1YR0vgl7LGTuc4V4aMt4EsCd9DptGDk4MlXHkaxbuV2Wnl7uqjCkY2bvp47+yanza+MYCWh2gqzEHSbbDEHpw== 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=V8DrIXeZlDUTfGstEdQGon4yIw4bL7V+5etchI+9FV4=; b=ev8Wpg56WNqKcFcWkJ4EWWcO2eAoYYuufGYez64u0OV6NOrAJbBgY65QgA/I67IsJpU+I5cHTq2miVouhl8GpNd66iFNoJ8FB4LNcsN+Es3I9/RRYZaglAH3GBGWJ8AH50uu6w9gxMShe8yblklIbaonAkuEJszcVArAwAtnIdlFTJcgVut0Obk9KhXrPEfZWMP92iODAwg3G3kzaoYGEsYPvoaEtmNmhXyOfhQTl9CdPBtqVtkGrqrXqe6NksKrr1vbFCWemINndFDodUkkT02GQOxH4VVB3rzyre/5/ZWxV0/l1SOtMh4tP8U1pXTD+jWEZssLYaktTMBHtCV/Kw== 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=V8DrIXeZlDUTfGstEdQGon4yIw4bL7V+5etchI+9FV4=; b=C3eO2dFNUFC+iJl1JLormaUc9XJgf3gtPo6O6giMLiQbASCO+ETlOl8ZG9fie7O1IBJjBlV8xPrhGZbiOkE4tTfovvDBkvqZRUTOs8BMpC2VW6QyAxlk8gCg/xYtAyYrpq8t70641OAO1JkC+OSJYxb7nUF5lySMs2AAqMqeKDE= 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 DBAPR04MB7366.eurprd04.prod.outlook.com (2603:10a6:10:1a0::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.31; Fri, 17 Mar 2023 06:13:49 +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 06:13:49 +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 v3 1/2] usb: chipdea: core: fix return -EINVAL if request role is the same with current role Date: Fri, 17 Mar 2023 14:15:15 +0800 Message-Id: <20230317061516.2451728-1-xu.yang_2@nxp.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: SI2PR01CA0009.apcprd01.prod.exchangelabs.com (2603:1096:4:191::18) To DB7PR04MB4505.eurprd04.prod.outlook.com (2603:10a6:5:39::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB7PR04MB4505:EE_|DBAPR04MB7366:EE_ X-MS-Office365-Filtering-Correlation-Id: 4dba8294-bbbb-425b-53e7-08db26aec61d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MAN3ECxjYiqtEqG+abeYLigWrQb2XjLijpmnnL7/8SQf1DxzjWd6qXqjk9jCf5jAayUADZgk2YoniBF3nnetO7n2YV3CqSq20akZMIZJFq99q4Qqk3GfWAWDW5YOx00rfkE1mcPYnm6OlrUFsmpneP0zkdKAKJ/7RTq5Qtb1MtfvT3vKn3riaLh0YnP5Wz1G6AwgiDG+X3S9jFJRk4fLfpMUw2fcX18XSMjelpFmV5AJmBLHgjPpxU4cPAsl75vQzpZQdj2ztEZHHQ79kM02KmbZKxJg1ReNQbXfKYuCkSyjzFpPI9L9v6i2DgrwBNkvJez1G/jpyHTRkxvjQrlt98ZRw/ywKFHFYPXiTyeSBoR8uehRmE8PggWVLPTLmSOls2ZDqy6lLlTEUMmrqV+s0cg3cGjHiIjk/p4VY3Cx6cUboHf+7HOV50QtV+pC8Fqrxd6VZBH4nj15A+NnSgQca3ZGoo42jxVFXc5LEIBwNb8DuSrN5WyxfCxFfpd5QvQ59uORmYmjkN4HgN64sTzUA9tpcHcK8svRmdT2G19c3cI512tdo6QcR/IRTXjCGR7DZHqV1Js0z5QMM8vdGgsoUxx05pmfv6aZ0jia/otZvfue8d8LQEujxuaW2SeDNqPNtfrZQTRmRMDjD+WzOpAhP+jTPJy3ooDPgZvzJ2ZgdkcGhhNDa1usM2Xx8j679SwdpV5jVeBR34pjd9kCA0tJMg== 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)(346002)(376002)(136003)(39860400002)(396003)(366004)(451199018)(38350700002)(38100700002)(86362001)(4744005)(36756003)(2906002)(4326008)(41300700001)(5660300002)(8936002)(6916009)(1076003)(6512007)(186003)(26005)(2616005)(83380400001)(316002)(6506007)(66556008)(6486002)(8676002)(66946007)(6666004)(52116002)(66476007)(478600001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ewfRm3aYoqtrtA+dUNO16BAu7OrQHUv5XYupQQyiN7CHzEhbOC/64QrgbGXdY0SAsuwRNp6QGraEF0MIQxdDzeh1WOdVH6cPUkUw4OGGtYras5wZ6qhlA6kL1lhFErvNJKs2jAk2Iog5yM2ACOocDYmgtH/kHV2bLBep8CmOwqc0s3OPasRin9GHgz7GBCJaV3weYvcNSmm2QYFayih7qbrvtESXxyxx6T31C+XmN/rwcLQkB1fvwdgHSmhh/xM942NXzra7tEYgamrH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qsTmv9do+Xmvl0HM3EH8zdL4+9V8jdvrBGgI3u9SiRNyF/NRVHZhdowzWuzN6J/2OWRXDTRhCEdi7jlpHeDk3hDIOoDYIsdI+lxI3sKejSjy28Ok6nabNW7PRxdHu6skyPjFyD236n6o30sxiADr3yI+HACFYisJmw5PrE4VpC39Nb1U8k1A95mPBvkPHpMw+jHhVka8QVCcxjhmoKjmewGyT6V7ulHtdLUWpz8SKRV0Nbtyu+ X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4dba8294-bbbb-425b-53e7-08db26aec61d X-MS-Exchange-CrossTenant-AuthSource: DB7PR04MB4505.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Mar 2023 06:13:49.7251 (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: itowQ3umNyu/4dHIYzvEgOXV7WFM5xHpUmBAq6BxVAtiP1EFfchd10AiEGY0kwRBeRpzOyBT7rLvEW27Mns9HQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR04MB7366 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 changes since v2: - add acked-by tag --- 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 06:15:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xu Yang X-Patchwork-Id: 13178564 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 1008FC74A5B for ; Fri, 17 Mar 2023 06:13:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229707AbjCQGN6 (ORCPT ); Fri, 17 Mar 2023 02:13:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48406 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229665AbjCQGN5 (ORCPT ); Fri, 17 Mar 2023 02:13:57 -0400 Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2063.outbound.protection.outlook.com [40.107.21.63]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A07615C9B for ; Thu, 16 Mar 2023 23:13:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Xb4wsQLFZnrYMtF8TKbjxlGLyjqY5IGwFNy54VEGg9/fcQVNt9M4VpBKB156GQPztPT1jJVdPjQKzWmMUb9N1sYLRHgEi6NQeU04bwy5woOilyp6mhwN19EzYvn1FBJEVdLncW7LOg0Jr58qv4lgAkaZA/X/ElKRpQ3dHdQWcOAiIGs/+GGCC6tKY8etilPIH6ToFNZj/PFgJPpR41a6kqy0kkixZ0mIGGownFvzuVC50VYxNHGqsEgxDGqxK+l+loGjSw36sN3/JPZGkvpul4cRVOytaebZVMISx32kwGy4iomgiBOPYB0Hy4JTlbur2OsRWUEAUHHWHz6Tuy6FZw== 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=KXKwHk+doV4seaYidYmL+DfOUvNFJ6zK2SudNbXQk64=; b=JFZuJ4DKtjJnt4NkTOPzd4TK360RovQjm64d84Mqwap1cZmZbhEbJy9dh+5jE4RUptE/SdiftUbe2DfF2jcoskzWTi9uClPUVgnu6vPzwcXLfD4sldfortsiKM+aDlpUni73yzx0+jwyld89mtOjaSwvFhs9VlUwXil9MxlGeI6EE0qSXSSWu1PAd4JbSEbWq3kKj8cpfu3HahMP6Z4+0ZDsMxg3HA5rZX3Wv9X0WPbOsTp4YuEN3eLsxu5qloMA1rvCulCEyDvFfCWN0g7hJSBVBdy6KgXY0KjCElNC7ENrDaQeLDEllPdrAlZjW22gedPaSgW/94srYq6eNV4OOg== 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=KXKwHk+doV4seaYidYmL+DfOUvNFJ6zK2SudNbXQk64=; b=nU/rXp6mkxsu8cTHqJlDfNfjXsm9llQvRRPXpK36yn8SEqx2/O4mknEnEpfE8L6BVTh5Kh8p+/Ygk2kIzmFlK0BzsrQ8ACkqkCi9jzwTiVJOkFpmcPfTsZNAy4vwfkWifI2YvKb3R0D0a9/cRn0YOlLHClBvhk2xVnv+vs4IB4o= 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 DBAPR04MB7366.eurprd04.prod.outlook.com (2603:10a6:10:1a0::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6178.31; Fri, 17 Mar 2023 06:13:51 +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 06:13:52 +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 v3 2/2] usb: chipidea: core: fix possible concurrent when switch role Date: Fri, 17 Mar 2023 14:15:16 +0800 Message-Id: <20230317061516.2451728-2-xu.yang_2@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230317061516.2451728-1-xu.yang_2@nxp.com> References: <20230317061516.2451728-1-xu.yang_2@nxp.com> X-ClientProxiedBy: SI2PR01CA0009.apcprd01.prod.exchangelabs.com (2603:1096:4:191::18) To DB7PR04MB4505.eurprd04.prod.outlook.com (2603:10a6:5:39::26) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DB7PR04MB4505:EE_|DBAPR04MB7366:EE_ X-MS-Office365-Filtering-Correlation-Id: c04aa84d-f7b1-4dbe-4e20-08db26aec7a4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BhpQFkCIQtAcsHFwyVCKtn6JmHmqAMt5xYrulGg1i3idSPLW+ZGVKYraTLA1NOotszBlhF5Y34Gkbh4RtkBLNu0C2k9UX0VhZv8guoXPpM2SasEAO4w4V7W5em+Bap3b7vGT0+XSjfLQTVYkJh7v0rfVR7v7Q9utPVNUzK0BqJi3PqY4o0PTK8thULf7mus3iR5eqH8/o6dZgD0Yf9jtMJ3s0IUwSu0bp+DBkVtIzZqpjb/4Uof7IoyMKzhdCCMTEfNhNoNNxNoKKCE2G9yjQEO2aoFxgvJbk/w02+crdc1AtyGpBtvh+BeCSdAPdHpGSuQM1Zc/V9vIQLROi8Lbct+GspV/xyUOzdLFHiSAXg0lzRjZJdJkWQkxuOB4HpQKMgSI6jeleqCVc5hogtbF9esJHZTpn+Eb5rsvst3KayWAxHfmhz/QB6M/nK32qTPjQ8JRvjXLUwcWcPKMVjokmNZmxNfL5jXqklv1uu43LI3Kcl+jZJNHBnK+AoKqPCTmADnrSD2Y19po/+OPNHCUFwpITWjFZJvJDKRHRCDveaVgnHcoQ6vWOF0A+x01Q066sQo37b/75f+tAG56hhiG/UO0GZhJwftM2FukJ9dfuQVdWH8fsZ2LIv6jPBMe6PZptOX5HUouYrKC9BWHjkeJLOHmbpnsDHA0/XNy7DHObHFaYzVHdOTiC3VKYlS/q9icJkHbt6tKUUpZM9LCI7SKWA== 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)(346002)(376002)(136003)(39860400002)(396003)(366004)(451199018)(38350700002)(38100700002)(86362001)(36756003)(2906002)(4326008)(41300700001)(5660300002)(8936002)(6916009)(1076003)(6512007)(186003)(26005)(2616005)(83380400001)(316002)(6506007)(66556008)(6486002)(8676002)(66946007)(6666004)(52116002)(66476007)(478600001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: PRrFzOv7IVYnEzuAwtjmF/jaEWJgZncBv2zBz59HWibW8XIGZSJCsdR24ZsMHAFNr4LoRiXF0Ld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Kl4HWgQR8q0EGbvEwFzHFMCZvscnLWOwOK/Co+p34tRCRusan7jnnMVILlv2EBiCNL6QVNTMAHlOTyyoaQQ3EOpEyOnWKd/u1NOAAEnmk7Nrx009znAe5EWHpUteMHKSGzUkUEZm1za6tIBQ6HyAKVfqCuYI8s/6NLoPXQyRsf9ntezBi0EQw9iWDd1Os8LG8XGEyoJ9Sh9hNwu43+zDEWbKBGSgAQRspf0GP8y3UkfmAo+49XrHtpTz0Y8U4+XulebGmSFRQkoMPqjs7KVS3BRKXMnfaRqBMVAJSPGsxQ/iYMwOC1ehmvkvPUz5EroADPEh44Bow5Z/bjeYbiiCk5mf/Pk9RxYndgREz6CeQeFtFUmj68+fKkW+gFMAGpRzRvtrldfe0C072xLI1LUXAA6pNf7CcapsrkN2MvW09fmzOo3VBkFtbKIQ X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: c04aa84d-f7b1-4dbe-4e20-08db26aec7a4 X-MS-Exchange-CrossTenant-AuthSource: DB7PR04MB4505.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Mar 2023 06:13:52.0687 (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: qSAWnxNr5NgWZ+Bcqh8gnUQ++NuM5W7qqg+t6S2Dbj3xDacf5AytbXkdedTdEZaZNryY6L8cEFKP1teC3EYZ9w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR04MB7366 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 changes since v2: - add acked-by tag --- 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