From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 A1A9A1448C3; Thu, 13 Jun 2024 12:23:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718281395; cv=none; b=hzV7FGkUBkQEzPklVYqvScfYb8LKmzOWewvXEUcfe4kqA8GZtRirjO3V7K+Wo9Ha+31wz8+HPw2njTCCGt044M+laj4LKL2gBgoviVF3F2nMMhROAP6UJuZTZLjrb6KkXgKW8HkowHBpwS2qbj0JyY/1eMFnGSvo6J5OCFRYf1c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718281395; c=relaxed/simple; bh=MzkRFN9aaz38FXsH4oH4MQjwwGO3jvw1vJrmETI9LOw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=HRESWICOulppwekE6YNplx2+3sU9v6xczyowYfXEhmm4oMBWRtsrXA4f5W5e17C4zoxizAiYOxcu+aDOaXMeyBhYhBuOdShyROARXRVUz3NhJ2h7D0Fl8Jho92Wyj8o402eJ8Pli8RDWUYMHe4I00uiIcB4ZaLMGLM3Yqc1l2Pg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=adGSIUDC; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="adGSIUDC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2995CC32786; Thu, 13 Jun 2024 12:23:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1718281395; bh=MzkRFN9aaz38FXsH4oH4MQjwwGO3jvw1vJrmETI9LOw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=adGSIUDCrKv6owAwMizFmdnTCvj1IbzorGCZ2oeUqUvwvXDBuC2bcOxNzq1B89+Vj UzEGTEjosjlYM0B6Nf/fSLQx3YZ4Y/N0rjLmNwc7escvV4c5dRtWSrInrXJjsepHpl PIht/gha5NEzWr3L4bl5BkNvXhLWOUZ5BnmAJC7Q= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Wei Fang , Paolo Abeni , Sasha Levin Subject: [PATCH 5.10 241/317] net: fec: avoid lock evasion when reading pps_enable Date: Thu, 13 Jun 2024 13:34:19 +0200 Message-ID: <20240613113256.871741090@linuxfoundation.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240613113247.525431100@linuxfoundation.org> References: <20240613113247.525431100@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 5.10-stable review patch. If anyone has any objections, please let me know. ------------------ From: Wei Fang [ Upstream commit 3b1c92f8e5371700fada307cc8fd2c51fa7bc8c1 ] 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 Link: https://lore.kernel.org/r/20240521023800.17102-1-wei.fang@nxp.com Signed-off-by: Paolo Abeni Signed-off-by: Sasha Levin --- drivers/net/ethernet/freescale/fec_ptp.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/freescale/fec_ptp.c b/drivers/net/ethernet/freescale/fec_ptp.c index c5ae673005908..780fbb3e1ed06 100644 --- a/drivers/net/ethernet/freescale/fec_ptp.c +++ b/drivers/net/ethernet/freescale/fec_ptp.c @@ -103,14 +103,13 @@ static int fec_ptp_enable_pps(struct fec_enet_private *fep, uint enable) u64 ns; val = 0; - 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. */ @@ -441,6 +440,9 @@ static int fec_ptp_enable(struct ptp_clock_info *ptp, int ret = 0; if (rq->type == PTP_CLK_REQ_PPS) { + fep->pps_channel = DEFAULT_PPS_CHANNEL; + fep->reload_period = PPS_OUPUT_RELOAD_PERIOD; + ret = fec_ptp_enable_pps(fep, on); return ret; -- 2.43.0