Re: [PATCH] Use a spinlock to guard `fep->ptp_clk_on`
From: Csókás Bence <hidden>
Date: 2022-08-31 14:21:56
On 2022. 08. 31. 16:03, Andrew Lunn wrote:
quoted
diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c index b0d60f898249..98d8f8d6034e 100644 --- a/drivers/net/ethernet/freescale/fec_main.c +++ b/drivers/net/ethernet/freescale/fec_main.c@@ -2029,6 +2029,7 @@ static int fec_enet_clk_enable(struct net_device *ndev, bool enable) { struct fec_enet_private *fep = netdev_priv(ndev); int ret; + unsigned long flags;Please keep to reverse christmas tree
checkpatch didn't tell me that was a requirement... Easy to fix though.
quoted
if (enable) { ret = clk_prepare_enable(fep->clk_enet_out);@@ -2036,15 +2037,15 @@ static int fec_enet_clk_enable(struct net_device *ndev, bool enable) return ret; if (fep->clk_ptp) { - mutex_lock(&fep->ptp_clk_mutex); + spin_lock_irqsave(&fep->ptp_clk_lock, flags);Is the ptp hardware accessed in interrupt context? If not, you can use a plain spinlock, not _irqsave..
`fec_suspend()` calls `fec_enet_clk_enable()`, which may be a non-preemptible context, I'm not sure how the PM subsystem's internals work... Besides, with the way this driver is built, function call dependencies all over the place, I think it's better safe than sorry. I don't think there is any disadvantage (besides maybe a few lost cycles) of using _irqsave in regular process context anyways. Bence