All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: qcom/emac: disable interrupts before calling phy_disconnect
@ 2016-10-14 19:14 Timur Tabi
  2016-10-15 21:35 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Timur Tabi @ 2016-10-14 19:14 UTC (permalink / raw)
  To: netdev

There is a race condition that can occur if EMAC interrupts are
enabled when phy_disconnect() is called.  phy_disconnect() sets
adjust_link to NULL.  When an interrupt occurs, the ISR might
call phy_mac_interrupt(), which wakes up the workqueue function
phy_state_machine().  This function might reference adjust_link,
thereby causing a null pointer exception.

Signed-off-by: Timur Tabi <timur@codeaurora.org>
---
 drivers/net/ethernet/qualcomm/emac/emac-mac.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/qualcomm/emac/emac-mac.c b/drivers/net/ethernet/qualcomm/emac/emac-mac.c
index e97968e..6fb3bee 100644
--- a/drivers/net/ethernet/qualcomm/emac/emac-mac.c
+++ b/drivers/net/ethernet/qualcomm/emac/emac-mac.c
@@ -1021,14 +1021,18 @@ void emac_mac_down(struct emac_adapter *adpt)
 	napi_disable(&adpt->rx_q.napi);
 
 	phy_stop(adpt->phydev);
-	phy_disconnect(adpt->phydev);
 
-	/* disable mac irq */
+	/* Interrupts must be disabled before the PHY is disconnected, to
+	 * avoid a race condition where adjust_link is null when we get
+	 * an interrupt.
+	 */
 	writel(DIS_INT, adpt->base + EMAC_INT_STATUS);
 	writel(0, adpt->base + EMAC_INT_MASK);
 	synchronize_irq(adpt->irq.irq);
 	free_irq(adpt->irq.irq, &adpt->irq);
 
+	phy_disconnect(adpt->phydev);
+
 	emac_mac_reset(adpt);
 
 	emac_tx_q_descs_free(adpt);
-- 
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm
Technologies, Inc.  Qualcomm Technologies, Inc. is a member of the
Code Aurora Forum, a Linux Foundation Collaborative Project.

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] net: qcom/emac: disable interrupts before calling phy_disconnect
  2016-10-14 19:14 [PATCH] net: qcom/emac: disable interrupts before calling phy_disconnect Timur Tabi
@ 2016-10-15 21:35 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2016-10-15 21:35 UTC (permalink / raw)
  To: timur; +Cc: netdev

From: Timur Tabi <timur@codeaurora.org>
Date: Fri, 14 Oct 2016 14:14:35 -0500

> There is a race condition that can occur if EMAC interrupts are
> enabled when phy_disconnect() is called.  phy_disconnect() sets
> adjust_link to NULL.  When an interrupt occurs, the ISR might
> call phy_mac_interrupt(), which wakes up the workqueue function
> phy_state_machine().  This function might reference adjust_link,
> thereby causing a null pointer exception.
> 
> Signed-off-by: Timur Tabi <timur@codeaurora.org>

Applied.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-10-15 21:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-14 19:14 [PATCH] net: qcom/emac: disable interrupts before calling phy_disconnect Timur Tabi
2016-10-15 21:35 ` David Miller

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.