Skip to content

Commit 699a875

Browse files
WeiFang-NXProxanan1996
authored andcommitted
net: fec: avoid lock evasion when reading pps_enable
BugLink: https://bugs.launchpad.net/bugs/2072617 [ Upstream commit 3b1c92f ] 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: 278d240 ("net: fec: ptp: Enable PPS output based on ptp clock") Signed-off-by: Wei Fang <wei.fang@nxp.com> Link: https://lore.kernel.org/r/20240521023800.17102-1-wei.fang@nxp.com Signed-off-by: Paolo Abeni <pabeni@redhat.com> Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Portia Stephens <portia.stephens@canonical.com> Signed-off-by: Stefan Bader <stefan.bader@canonical.com>
1 parent 8e2ed91 commit 699a875

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

drivers/net/ethernet/freescale/fec_ptp.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,13 @@ static int fec_ptp_enable_pps(struct fec_enet_private *fep, uint enable)
103103
u64 ns;
104104
val = 0;
105105

106-
if (fep->pps_enable == enable)
107-
return 0;
108-
109-
fep->pps_channel = DEFAULT_PPS_CHANNEL;
110-
fep->reload_period = PPS_OUPUT_RELOAD_PERIOD;
111-
112106
spin_lock_irqsave(&fep->tmreg_lock, flags);
113107

108+
if (fep->pps_enable == enable) {
109+
spin_unlock_irqrestore(&fep->tmreg_lock, flags);
110+
return 0;
111+
}
112+
114113
if (enable) {
115114
/* clear capture or output compare interrupt status if have.
116115
*/
@@ -441,6 +440,9 @@ static int fec_ptp_enable(struct ptp_clock_info *ptp,
441440
int ret = 0;
442441

443442
if (rq->type == PTP_CLK_REQ_PPS) {
443+
fep->pps_channel = DEFAULT_PPS_CHANNEL;
444+
fep->reload_period = PPS_OUPUT_RELOAD_PERIOD;
445+
444446
ret = fec_ptp_enable_pps(fep, on);
445447

446448
return ret;

0 commit comments

Comments
 (0)