Skip to content

Commit 018af9b

Browse files
tititiou36vinodkoul
authored andcommitted
dmaengine: ti: k3-udma-glue: Fix an error handling path in 'k3_udma_glue_cfg_rx_flow()'
All but one error handling paths in the 'k3_udma_glue_cfg_rx_flow()' function 'goto err' and call 'k3_udma_glue_release_rx_flow()'. This not correct because this function has a 'channel->flows_ready--;' at the end, but 'flows_ready' has not been incremented here, when we branch to the error handling path. In order to keep a correct value in 'flows_ready', un-roll 'k3_udma_glue_release_rx_flow()', simplify it, add some labels and branch at the correct places when an error is detected. Doing so, we also NULLify 'flow->udma_rflow' in a path that was lacking it. Fixes: d702419 ("dmaengine: ti: k3-udma: Add glue layer for non DMAengine user") Signed-off-by: Christophe JAILLET <[email protected]> Acked-by: Peter Ujfalusi <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]>
1 parent 01c4df3 commit 018af9b

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

drivers/dma/ti/k3-udma-glue.c

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -564,12 +564,12 @@ static int k3_udma_glue_cfg_rx_flow(struct k3_udma_glue_rx_channel *rx_chn,
564564
if (IS_ERR(flow->udma_rflow)) {
565565
ret = PTR_ERR(flow->udma_rflow);
566566
dev_err(dev, "UDMAX rflow get err %d\n", ret);
567-
goto err;
567+
return ret;
568568
}
569569

570570
if (flow->udma_rflow_id != xudma_rflow_get_id(flow->udma_rflow)) {
571-
xudma_rflow_put(rx_chn->common.udmax, flow->udma_rflow);
572-
return -ENODEV;
571+
ret = -ENODEV;
572+
goto err_rflow_put;
573573
}
574574

575575
/* request and cfg rings */
@@ -578,27 +578,27 @@ static int k3_udma_glue_cfg_rx_flow(struct k3_udma_glue_rx_channel *rx_chn,
578578
if (!flow->ringrx) {
579579
ret = -ENODEV;
580580
dev_err(dev, "Failed to get RX ring\n");
581-
goto err;
581+
goto err_rflow_put;
582582
}
583583

584584
flow->ringrxfdq = k3_ringacc_request_ring(rx_chn->common.ringacc,
585585
flow_cfg->ring_rxfdq0_id, 0);
586586
if (!flow->ringrxfdq) {
587587
ret = -ENODEV;
588588
dev_err(dev, "Failed to get RXFDQ ring\n");
589-
goto err;
589+
goto err_ringrx_free;
590590
}
591591

592592
ret = k3_ringacc_ring_cfg(flow->ringrx, &flow_cfg->rx_cfg);
593593
if (ret) {
594594
dev_err(dev, "Failed to cfg ringrx %d\n", ret);
595-
goto err;
595+
goto err_ringrxfdq_free;
596596
}
597597

598598
ret = k3_ringacc_ring_cfg(flow->ringrxfdq, &flow_cfg->rxfdq_cfg);
599599
if (ret) {
600600
dev_err(dev, "Failed to cfg ringrxfdq %d\n", ret);
601-
goto err;
601+
goto err_ringrxfdq_free;
602602
}
603603

604604
if (rx_chn->remote) {
@@ -648,16 +648,25 @@ static int k3_udma_glue_cfg_rx_flow(struct k3_udma_glue_rx_channel *rx_chn,
648648
if (ret) {
649649
dev_err(dev, "flow%d config failed: %d\n", flow->udma_rflow_id,
650650
ret);
651-
goto err;
651+
goto err_ringrxfdq_free;
652652
}
653653

654654
rx_chn->flows_ready++;
655655
dev_dbg(dev, "flow%d config done. ready:%d\n",
656656
flow->udma_rflow_id, rx_chn->flows_ready);
657657

658658
return 0;
659-
err:
660-
k3_udma_glue_release_rx_flow(rx_chn, flow_idx);
659+
660+
err_ringrxfdq_free:
661+
k3_ringacc_ring_free(flow->ringrxfdq);
662+
663+
err_ringrx_free:
664+
k3_ringacc_ring_free(flow->ringrx);
665+
666+
err_rflow_put:
667+
xudma_rflow_put(rx_chn->common.udmax, flow->udma_rflow);
668+
flow->udma_rflow = NULL;
669+
661670
return ret;
662671
}
663672

0 commit comments

Comments
 (0)