Skip to content

Commit 3b1c92f

Browse files
Wei FangPaolo Abeni
authored andcommitted
net: fec: avoid lock evasion when reading pps_enable
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent b35b1c0 commit 3b1c92f

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

drivers/net/ethernet/freescale/fec_ptp.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,13 @@ static int fec_ptp_enable_pps(struct fec_enet_private *fep, uint enable)
104104
struct timespec64 ts;
105105
u64 ns;
106106

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

109+
if (fep->pps_enable == enable) {
110+
spin_unlock_irqrestore(&fep->tmreg_lock, flags);
111+
return 0;
112+
}
113+
115114
if (enable) {
116115
/* clear capture or output compare interrupt status if have.
117116
*/
@@ -532,6 +531,9 @@ static int fec_ptp_enable(struct ptp_clock_info *ptp,
532531
int ret = 0;
533532

534533
if (rq->type == PTP_CLK_REQ_PPS) {
534+
fep->pps_channel = DEFAULT_PPS_CHANNEL;
535+
fep->reload_period = PPS_OUPUT_RELOAD_PERIOD;
536+
535537
ret = fec_ptp_enable_pps(fep, on);
536538

537539
return ret;

0 commit comments

Comments
 (0)