Skip to content

Commit 43b6f38

Browse files
Erwan Le RayADESTM
authored andcommitted
serial: stm32: fix probe and remove order
Fix probe and remove order to register the port at the end of the probe and to unregister the port at the beginning of the remove. This enforce resource allocation and free occur at proper time. Signed-off-by: Erwan Le Ray <erwan.leray@st.com> Change-Id: I219cad0a31238404b84a79eab4eaaecd65fa04b4 Reviewed-on: https://gerrit.st.com/c/mpu/oe/st/linux-stm32/+/155492 Reviewed-by: CITOOLS <smet-aci-reviews@lists.codex.cro.st.com> Reviewed-by: CIBUILD <smet-aci-builds@lists.codex.cro.st.com> Reviewed-by: Fabrice GASNIER <fabrice.gasnier@st.com>
1 parent 859bda4 commit 43b6f38

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

drivers/tty/serial/stm32-usart.c

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1313,10 +1313,6 @@ static int stm32_serial_probe(struct platform_device *pdev)
13131313
device_set_wakeup_enable(&pdev->dev, false);
13141314
}
13151315

1316-
ret = uart_add_one_port(&stm32_usart_driver, &stm32port->port);
1317-
if (ret)
1318-
goto err_wirq;
1319-
13201316
ret = stm32_of_dma_rx_probe(stm32port, pdev);
13211317
if (ret)
13221318
dev_info(&pdev->dev, "interrupt mode used for rx (no dma)\n");
@@ -1327,14 +1323,38 @@ static int stm32_serial_probe(struct platform_device *pdev)
13271323

13281324
platform_set_drvdata(pdev, &stm32port->port);
13291325

1326+
ret = uart_add_one_port(&stm32_usart_driver, &stm32port->port);
1327+
if (ret)
1328+
goto err_dma;
1329+
13301330
pm_runtime_get_noresume(&pdev->dev);
13311331
pm_runtime_set_active(&pdev->dev);
13321332
pm_runtime_enable(&pdev->dev);
13331333
pm_runtime_put_sync(&pdev->dev);
13341334

13351335
return 0;
13361336

1337-
err_wirq:
1337+
err_dma:
1338+
if (stm32port->rx_ch) {
1339+
dmaengine_terminate_async(stm32port->rx_ch);
1340+
dma_release_channel(stm32port->rx_ch);
1341+
}
1342+
1343+
if (stm32port->rx_dma_buf)
1344+
dma_free_coherent(&pdev->dev,
1345+
RX_BUF_L, stm32port->rx_buf,
1346+
stm32port->rx_dma_buf);
1347+
1348+
if (stm32port->tx_ch) {
1349+
dmaengine_terminate_async(stm32port->tx_ch);
1350+
dma_release_channel(stm32port->tx_ch);
1351+
}
1352+
1353+
if (stm32port->tx_dma_buf)
1354+
dma_free_coherent(&pdev->dev,
1355+
TX_BUF_L, stm32port->tx_buf,
1356+
stm32port->tx_dma_buf);
1357+
13381358
if (stm32port->wakeirq > 0)
13391359
dev_pm_clear_wake_irq(&pdev->dev);
13401360

@@ -1358,6 +1378,8 @@ static int stm32_serial_remove(struct platform_device *pdev)
13581378

13591379
pm_runtime_get_sync(&pdev->dev);
13601380

1381+
err = uart_remove_one_port(&stm32_usart_driver, port);
1382+
13611383
stm32_clr_bits(port, ofs->cr1, USART_CR1_PEIE);
13621384
cr3 = readl_relaxed(port->membase + ofs->cr3);
13631385
cr3 &= ~USART_CR3_EIE;
@@ -1394,8 +1416,6 @@ static int stm32_serial_remove(struct platform_device *pdev)
13941416

13951417
clk_disable_unprepare(stm32_port->clk);
13961418

1397-
err = uart_remove_one_port(&stm32_usart_driver, port);
1398-
13991419
pm_runtime_disable(&pdev->dev);
14001420
pm_runtime_put_noidle(&pdev->dev);
14011421

0 commit comments

Comments
 (0)