[lkml]   [2021]   [May]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
    Patch in this message
    Subject[PATCH 5.10 162/530] spi: stm32: drop devres version of spi_register_master
    From: Antonio Borneo <>

    [ Upstream commit 8d559a64f00b59af9cc02b803ff52f6e6880a651 ]

    A call to spi_unregister_master() triggers calling remove()
    for all the spi devices binded to the spi master.

    Some spi device driver requires to "talk" with the spi device
    during the remove(), e.g.:
    - a LCD panel like drivers/gpu/drm/panel/panel-lg-lg4573.c
    will turn off the backlighting sending a command over spi.
    This implies that the spi master must be fully functional when
    spi_unregister_master() is called, either if it is called
    explicitly in the master's remove() code or implicitly by the
    devres framework.

    Devres calls devres_release_all() to release all the resources
    "after" the remove() of the spi master driver (check code of
    __device_release_driver() in drivers/base/dd.c).
    If the spi master driver has an empty remove() then there would
    be no issue; the devres_release_all() will release everything
    in reverse order w.r.t. probe().
    But if code in spi master driver remove() disables the spi or
    makes it not functional (like in this spi-stm32), then devres
    cannot be used safely for unregistering the spi master and the
    binded spi devices.

    Replace devm_spi_register_master() with spi_register_master()
    and add spi_unregister_master() as first action in remove().

    Fixes: dcbe0d84dfa5 ("spi: add driver for STM32 SPI controller")

    Signed-off-by: Antonio Borneo <>
    Signed-off-by: Alain Volmat <>
    Signed-off-by: Mark Brown <>
    Signed-off-by: Sasha Levin <>
    drivers/spi/spi-stm32.c | 3 ++-
    1 file changed, 2 insertions(+), 1 deletion(-)

    diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c
    index 53c4311cc6ab..8d8a32d46f2d 100644
    --- a/drivers/spi/spi-stm32.c
    +++ b/drivers/spi/spi-stm32.c
    @@ -1950,7 +1950,7 @@ static int stm32_spi_probe(struct platform_device *pdev)

    - ret = devm_spi_register_master(&pdev->dev, master);
    + ret = spi_register_master(master);
    if (ret) {
    dev_err(&pdev->dev, "spi master registration failed: %d\n",
    @@ -1987,6 +1987,7 @@ static int stm32_spi_remove(struct platform_device *pdev)
    struct spi_master *master = platform_get_drvdata(pdev);
    struct stm32_spi *spi = spi_master_get_devdata(master);

    + spi_unregister_master(master);

    if (master->dma_tx)

     \ /
      Last update: 2021-05-12 18:02    [W:4.065 / U:0.020 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site