Skip to content

Commit 5f07929

Browse files
r-vigneshPaolo Abeni
authored andcommitted
net: ethernet: ti: am65-cpsw: Fix NAPI registration sequence
Registering the interrupts for TX or RX DMA Channels prior to registering their respective NAPI callbacks can result in a NULL pointer dereference. This is seen in practice as a random occurrence since it depends on the randomness associated with the generation of traffic by Linux and the reception of traffic from the wire. Fixes: 681eb2b ("net: ethernet: ti: am65-cpsw: ensure proper channel cleanup in error path") Signed-off-by: Vignesh Raghavendra <[email protected]> Co-developed-by: Siddharth Vadapalli <[email protected]> Signed-off-by: Siddharth Vadapalli <[email protected]> Reviewed-by: Alexander Sverdlin <[email protected]> Reviewed-by: Roger Quadros <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Paolo Abeni <[email protected]>
1 parent 4003c9e commit 5f07929

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

drivers/net/ethernet/ti/am65-cpsw-nuss.c

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2306,14 +2306,18 @@ static void am65_cpsw_nuss_remove_tx_chns(struct am65_cpsw_common *common)
23062306
static int am65_cpsw_nuss_ndev_add_tx_napi(struct am65_cpsw_common *common)
23072307
{
23082308
struct device *dev = common->dev;
2309+
struct am65_cpsw_tx_chn *tx_chn;
23092310
int i, ret = 0;
23102311

23112312
for (i = 0; i < common->tx_ch_num; i++) {
2312-
struct am65_cpsw_tx_chn *tx_chn = &common->tx_chns[i];
2313+
tx_chn = &common->tx_chns[i];
23132314

23142315
hrtimer_init(&tx_chn->tx_hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL_PINNED);
23152316
tx_chn->tx_hrtimer.function = &am65_cpsw_nuss_tx_timer_callback;
23162317

2318+
netif_napi_add_tx(common->dma_ndev, &tx_chn->napi_tx,
2319+
am65_cpsw_nuss_tx_poll);
2320+
23172321
ret = devm_request_irq(dev, tx_chn->irq,
23182322
am65_cpsw_nuss_tx_irq,
23192323
IRQF_TRIGGER_HIGH,
@@ -2323,19 +2327,16 @@ static int am65_cpsw_nuss_ndev_add_tx_napi(struct am65_cpsw_common *common)
23232327
tx_chn->id, tx_chn->irq, ret);
23242328
goto err;
23252329
}
2326-
2327-
netif_napi_add_tx(common->dma_ndev, &tx_chn->napi_tx,
2328-
am65_cpsw_nuss_tx_poll);
23292330
}
23302331

23312332
return 0;
23322333

23332334
err:
2334-
for (--i ; i >= 0 ; i--) {
2335-
struct am65_cpsw_tx_chn *tx_chn = &common->tx_chns[i];
2336-
2337-
netif_napi_del(&tx_chn->napi_tx);
2335+
netif_napi_del(&tx_chn->napi_tx);
2336+
for (--i; i >= 0; i--) {
2337+
tx_chn = &common->tx_chns[i];
23382338
devm_free_irq(dev, tx_chn->irq, tx_chn);
2339+
netif_napi_del(&tx_chn->napi_tx);
23392340
}
23402341

23412342
return ret;
@@ -2569,6 +2570,9 @@ static int am65_cpsw_nuss_init_rx_chns(struct am65_cpsw_common *common)
25692570
HRTIMER_MODE_REL_PINNED);
25702571
flow->rx_hrtimer.function = &am65_cpsw_nuss_rx_timer_callback;
25712572

2573+
netif_napi_add(common->dma_ndev, &flow->napi_rx,
2574+
am65_cpsw_nuss_rx_poll);
2575+
25722576
ret = devm_request_irq(dev, flow->irq,
25732577
am65_cpsw_nuss_rx_irq,
25742578
IRQF_TRIGGER_HIGH,
@@ -2577,23 +2581,23 @@ static int am65_cpsw_nuss_init_rx_chns(struct am65_cpsw_common *common)
25772581
dev_err(dev, "failure requesting rx %d irq %u, %d\n",
25782582
i, flow->irq, ret);
25792583
flow->irq = -EINVAL;
2580-
goto err_flow;
2584+
goto err_request_irq;
25812585
}
2582-
2583-
netif_napi_add(common->dma_ndev, &flow->napi_rx,
2584-
am65_cpsw_nuss_rx_poll);
25852586
}
25862587

25872588
/* setup classifier to route priorities to flows */
25882589
cpsw_ale_classifier_setup_default(common->ale, common->rx_ch_num_flows);
25892590

25902591
return 0;
25912592

2593+
err_request_irq:
2594+
netif_napi_del(&flow->napi_rx);
2595+
25922596
err_flow:
2593-
for (--i; i >= 0 ; i--) {
2597+
for (--i; i >= 0; i--) {
25942598
flow = &rx_chn->flows[i];
2595-
netif_napi_del(&flow->napi_rx);
25962599
devm_free_irq(dev, flow->irq, flow);
2600+
netif_napi_del(&flow->napi_rx);
25972601
}
25982602

25992603
err:

0 commit comments

Comments
 (0)