Skip to content

Commit 705beef

Browse files
shimodaygregkh
authored andcommitted
net: ethernet: ravb: exit if re-initialization fails in tx timeout
[ Upstream commit 015c5d5 ] According to the report of [1], this driver is possible to cause the following error in ravb_tx_timeout_work(). ravb e6800000.ethernet ethernet: failed to switch device to config mode This error means that the hardware could not change the state from "Operation" to "Configuration" while some tx and/or rx queue are operating. After that, ravb_config() in ravb_dmac_init() will fail, and then any descriptors will be not allocaled anymore so that NULL pointer dereference happens after that on ravb_start_xmit(). To fix the issue, the ravb_tx_timeout_work() should check the return values of ravb_stop_dma() and ravb_dmac_init(). If ravb_stop_dma() fails, ravb_tx_timeout_work() re-enables TX and RX and just exits. If ravb_dmac_init() fails, just exits. [1] https://lore.kernel.org/linux-renesas-soc/20200518045452.2390-1-dirk.behme@de.bosch.com/ Reported-by: Dirk Behme <dirk.behme@de.bosch.com> Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com> Reviewed-by: Sergei Shtylyov <sergei.shtylyov@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 0587509 commit 705beef

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

‎drivers/net/ethernet/renesas/ravb_main.c‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,7 @@ static void ravb_tx_timeout_work(struct work_struct *work)
14441444
struct ravb_private *priv = container_of(work, struct ravb_private,
14451445
work);
14461446
struct net_device *ndev = priv->ndev;
1447+
int error;
14471448

14481449
netif_tx_stop_all_queues(ndev);
14491450

@@ -1452,15 +1453,36 @@ static void ravb_tx_timeout_work(struct work_struct *work)
14521453
ravb_ptp_stop(ndev);
14531454

14541455
/* Wait for DMA stopping */
1455-
ravb_stop_dma(ndev);
1456+
if (ravb_stop_dma(ndev)) {
1457+
/* If ravb_stop_dma() fails, the hardware is still operating
1458+
* for TX and/or RX. So, this should not call the following
1459+
* functions because ravb_dmac_init() is possible to fail too.
1460+
* Also, this should not retry ravb_stop_dma() again and again
1461+
* here because it's possible to wait forever. So, this just
1462+
* re-enables the TX and RX and skip the following
1463+
* re-initialization procedure.
1464+
*/
1465+
ravb_rcv_snd_enable(ndev);
1466+
goto out;
1467+
}
14561468

14571469
ravb_ring_free(ndev, RAVB_BE);
14581470
ravb_ring_free(ndev, RAVB_NC);
14591471

14601472
/* Device init */
1461-
ravb_dmac_init(ndev);
1473+
error = ravb_dmac_init(ndev);
1474+
if (error) {
1475+
/* If ravb_dmac_init() fails, descriptors are freed. So, this
1476+
* should return here to avoid re-enabling the TX and RX in
1477+
* ravb_emac_init().
1478+
*/
1479+
netdev_err(ndev, "%s: ravb_dmac_init() failed, error %d\n",
1480+
__func__, error);
1481+
return;
1482+
}
14621483
ravb_emac_init(ndev);
14631484

1485+
out:
14641486
/* Initialise PTP Clock driver */
14651487
if (priv->chip_id == RCAR_GEN2)
14661488
ravb_ptp_init(ndev, priv->pdev);

0 commit comments

Comments
 (0)