From patchwork Mon May 13 01:51:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Fang X-Patchwork-Id: 13662969 Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-db5eur01on2041.outbound.protection.outlook.com [40.107.15.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 11B7633C9 for ; Mon, 13 May 2024 02:02:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.15.41 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715565779; cv=fail; b=EPV6K8jvxSSH01mO3qQgyW1rgyGyH0gL54+gohE3t+4G+ytSTPkb7gQH3UlqcygrRy0gI8+JtaHCA5sz6zcTVsPP5Sx7l6cqncEKPuz8sxz0UJWwadjHt5gp//lcq1sww+BGpXkHoJU5QbmVex2OE8gef2/CBsUzUgaFyrplb6M= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715565779; c=relaxed/simple; bh=mS8buf+BgiCQZkciPKSJ0NHaDiyM6AZ0laX6A90b1hI=; h=From:To:Cc:Subject:Date:Message-Id:Content-Type:MIME-Version; b=PWEIGtGHMw0CaCE1LmDPV2MT7qbOdaAx4GYI75HWfofHkbtER+p7vPJ6czsG72hxe0uzSN0JXRayj5YSCUXDmXJUGttpOF/yzgOo3GOU2kPjm+WWRCchztU45Qn0AWQB4gLvXpkC/IqvqjWHHJ9e3s82tEXgj/ndPoXoH633+VQ= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b=c8+m6JlF; arc=fail smtp.client-ip=40.107.15.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="c8+m6JlF" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JGp2EOQigP1CEfk0iFqr5JpezCMll0fOpVBOwO3UgTj04jmNmAbu/nEDGbpDA9xAeRrcjqdECtCYSu0y40lRoKVyZgkurE3lr/XCflzgvmQLqDQsyvx4eMGdO4HfbADNZ3ar1ZiKF7PPMTBdf4tv14TGPFeH/NC1QKZau50FTqg4leZF23tl6hi1pSna//VhokwuHf7IqFl+lAK7LLQtas2U3FmTlH+Z8BCBTecsdKkG4kGgeEBwStVy2Jz1s0yXxcg9y+H4KHI48ASLeCylTwFgvfSPEmKyB2JxIC5tbd75FRAXt96ko8FKU/pqeudZ6tK+PMiLCkmdm7nVn3LicQ== 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=kg6NgPVIPBGzsKPV2QOevCcaYQsebXVAh7Loga0bQec=; b=B1V6wc2jdyI8p6vMLRVXvOO/n4XZ9f0KwZR0wyM+le+ksLhd3f3gvoQ4fund/Xap7tpFS3/2UBbhVNPfCBION5Oybrwnzh44j8oZ6BCWwchtXpk2ss/84tvy0aZoxPw0h0xn0GKOnWKb4lzhRhy+zQrpInYM1Xy4dqY4ByGHwDY05rYW0HVXbuIPguhKk+wSaVmgI0tXuY/ddXoVxryqqI8/QfzM8zC+8PRtFNSJwUuX4nAFX8v0a/sRuWK5ATGaL+zPnqz358I5AsV9AO9mJUV2OdS9PilqtY937XJGQsyNA+5CJWA79paldYu+C0M/fmTiEQ9c08CURqCTpWOAaA== 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=kg6NgPVIPBGzsKPV2QOevCcaYQsebXVAh7Loga0bQec=; b=c8+m6JlFIG+q4jKtbfm+tVG/TQ6S5G4Yb0jzC0KRYWco2nVh7FY2xGw+z3TidIByhm/lLH/dWBTZKDV3x92rCZ8cWVXXQaWrQIyoNJ4q+8xhQOxChtL913SS8L/q2iWdQte06grQOU7geUB2Y8EPy7/BNWt0hTBTs6oEBa53Ce8= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB8510.eurprd04.prod.outlook.com (2603:10a6:102:211::7) by PAXPR04MB9400.eurprd04.prod.outlook.com (2603:10a6:102:2b2::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.55; Mon, 13 May 2024 02:02:55 +0000 Received: from PAXPR04MB8510.eurprd04.prod.outlook.com ([fe80::baed:1f6d:59b4:957]) by PAXPR04MB8510.eurprd04.prod.outlook.com ([fe80::baed:1f6d:59b4:957%5]) with mapi id 15.20.7544.052; Mon, 13 May 2024 02:02:55 +0000 From: Wei Fang To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, shenwei.wang@nxp.com, xiaoning.wang@nxp.com, richardcochran@gmail.com, andrew@lunn.ch, netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, imx@lists.linux.dev Subject: [PATCH net] net: fec: avoid lock evasion when reading pps_enable Date: Mon, 13 May 2024 09:51:26 +0800 Message-Id: <20240513015127.961360-1-wei.fang@nxp.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: SI1PR02CA0040.apcprd02.prod.outlook.com (2603:1096:4:1f6::7) To PAXPR04MB8510.eurprd04.prod.outlook.com (2603:10a6:102:211::7) Precedence: bulk X-Mailing-List: imx@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB8510:EE_|PAXPR04MB9400:EE_ X-MS-Office365-Filtering-Correlation-Id: 0c219309-f373-49e1-85d6-08dc72f0cdcb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230031|52116005|1800799015|366007|376005|38350700005; X-Microsoft-Antispam-Message-Info: xDsz/qAsjKM9P1BapO8hAMkYbK7M3bS+8Sa6tR+PNTj+8Tduk6WLN3d6Pq5i99KRKY6HaT3nqYVsLo0eO/5ZroXUBloUL/SX7K/DN5XwQwI3y3kntoindw5sLORAZABzugJSJWRK2q74fPfbfUN1RY4oU+x7fF17L+N7AyUXVPn65wKZxAt0i6eov6o8QltWmzeG3CWqe3lA2gvHGFXy520FlF0MMlxOuBc8sMf3riVyNCw7Msey3OIuA1tddM+E52HkhPuyEIDHJey8S+xe7pr/u6VRYBWm21APuC5SqnBL6l4AOFyzLx6pJohiWmPoNXeky8jzUyCRHx4rEt3uMVR/KMm9oUrnP1rUjcEhy3Xf1zU8eQHCtg13p274PM0XY127nwMcDdfk5VWxBHcx44T9hcayLw1VYyxgE6DUF3K7r66s2YuOE7bfrGwx007zdiCOVe9x047jcKfQl8UQ80F4ZUNZmXHB/r3R3JHbCC0+TaXEon7JFqJVi8/q56UCoPEK3FgBh2sByNa1E2RmDLz9ZegekJYma6W+C1mLMVTUIY1RDMULHDYEBk/i0uzBV31BpsbuSh1tesTbDOyTgn+53KGyhH1q+ZwBxt0NQQnpkroqqw8XQDr3StDQkQEe4VIODCM8aJnfVCSEvsstZ1itFjfKWiM//OV+Cx4kO9n7hFv3BUjxuZ9uECpAoh376TQd/G+Ke6AlIjoV5tT7jyRFlIpH0PekOQu7UXpHSPay7bpn94GQgRoASdGB6uCOXB4mENaifSA0+RQaHxs0HDlHNDTqyrMpitpLAy+yrzaFe3Vk2jtSq6a95XmFjex7sWXZ0PMBrBVkMLt8fhNufKbvRV33im6RiKseUWcGVlPAqpBvhdHwFP3YGOhuAhV8j3NcWm4p4nQ2SVVbW7gJQfJdKsus0COw5zLlNd6WQYFIOKqxDnlmKzXXNhNeiZAvGd8qiMvg/sKbiLxg+fg075UDK/EMuLG7dWoXL3EEm6Umc7y9FXqhGbsMqidxmJHZDnE1OvYcoU+1oH2O9F8GzmcA1bG82D5oMqJtw6zWddfNGntMAcO8y8IDqQuMbceWuctb4PxUQHOXhYfyJT/RLurIdt0saI5S4FnBD9RGxjyem4CqEqHYzoBabRbhCjl20wCy8YoCDDHGziKuy/qscK4Gh+c8NBnCUsonHGSewoefCwRbBOSbJzH0oy0qSD/rqYqi3tw5mdy11bPtP4FeogBDPQ8aAhL1AAgUpogy3LLQL4cFHQj/IbnwPf2aUdN17jx1vmDIBAJuIJypXB8QNQAkktBto3xNy39xgGEjHtM4WGeIO+HCUK3ty2Ck4I8ptPr/TNMOH4y/b5I/3+q1Aw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB8510.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(52116005)(1800799015)(366007)(376005)(38350700005);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: z7OXDaBpZURMe472MsXjanxiiGi6FSYfSxAUsswDAw+iD80QwI3Hkmtud9Pj5pAwaZwWe1QRLcT0eUHbF/AJ2omEYGOvNzgGE1FmuMC3wLl39fN93MHjnaS9P7tvET8qgkIL4ZATzZfLQQZto8L+O5HYLzhLoaOdqSkkmAjsPws4z1cK79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YlRITC4RE8jiHnwy2JOvsEUL9M68puK8oeaUOdc1o6DesTjuadEUVQUt+ZPvmmSxgW1/9vWwYkpqoGHb4fkCYXP1m2KWtPEnmfWg97R3k0d4rO6EUIO5L2G3ZnedG1XLhY880nVwNpGlOOYT6i+l/CpjnRCRFhmkmtxdbGJhta9+n3N/+RlvOGqsjgJxFPtNMChlBFHvOnXk5Xv6zkKXbOTnZCRPUEE/op615o6EVWsN2jN1UaiL5podLpyEkARKi/yFbylP8sNgT4MRH4DgxeRh7x7GTxg1gqiRLSR+PhtSPIDN1dQlMegCd4DINCYhG9+OArHaG3rzrnzV0vnqzcpm X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0c219309-f373-49e1-85d6-08dc72f0cdcb X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB8510.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 May 2024 02:02:55.2008 (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: 34C+iKhBmeQapjTgg6UfoXfHP8H5T9SsOQALF9ikkzJJnVy87GRsUvnKlYmXmMaXA4FStkrMyaeBgwAIJalnpA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB9400 The assignment of pps_enable is protected by tmreg_lock, but the read operation of pps_enable is not. So the Coverity tool reports a lock evasion warning which may cause data race to occur when running in a multithread environment. Although this issue is almost impossible to occur, we'd better fix it, at least it seems more logically reasonable, and it also prevents Coverity from continuing to issue warnings. Fixes: 278d24047891 ("net: fec: ptp: Enable PPS output based on ptp clock") Signed-off-by: Wei Fang Reviewed-by: Simon Horman --- drivers/net/ethernet/freescale/fec_ptp.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/freescale/fec_ptp.c b/drivers/net/ethernet/freescale/fec_ptp.c index 181d9bfbee22..8d37274a3fb0 100644 --- a/drivers/net/ethernet/freescale/fec_ptp.c +++ b/drivers/net/ethernet/freescale/fec_ptp.c @@ -104,14 +104,16 @@ static int fec_ptp_enable_pps(struct fec_enet_private *fep, uint enable) struct timespec64 ts; u64 ns; - if (fep->pps_enable == enable) - return 0; - fep->pps_channel = DEFAULT_PPS_CHANNEL; fep->reload_period = PPS_OUPUT_RELOAD_PERIOD; spin_lock_irqsave(&fep->tmreg_lock, flags); + if (fep->pps_enable == enable) { + spin_unlock_irqrestore(&fep->tmreg_lock, flags); + return 0; + } + if (enable) { /* clear capture or output compare interrupt status if have. */