Thread (11 messages) 11 messages, 5 authors, 2022-09-01

Re: [PATCH] Use a spinlock to guard `fep->ptp_clk_on`

From: Andrew Lunn <andrew@lunn.ch>
Date: 2022-08-31 16:25:03

On Wed, Aug 31, 2022 at 04:21:47PM +0200, Csókás Bence wrote:
On 2022. 08. 31. 16:03, Andrew Lunn wrote:
quoted
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.
checkpatch does not have the smarts to detect this. And it is a netdev
only thing.
quoted
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.
Those using real time will probably disagree.

There is also a different between not being able to sleep, and not
being able to process an interrupt for some other hardware. You got a
report about taking a mutex in atomic context. That just means you
cannot sleep, probably because a spinlock is held. That is very
different to not being able to handle interrupts. You only need
spin_lock_irqsave() if the interrupt handler also needs the same spin
lock to protect it from a thread using the spin lock.

     Andrew
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help