Skip to content

Commit 864f051

Browse files
committed
spi: atmel-quadspi: Convert to platform remove
Merge series from Uwe Kleine-König <u.kleine-koenig@pengutronix.de>: This series converts the atmel-quadspi driver to use the .remove_new() callback that doesn't return an int but void. The motivation is to not give driver authors a reason to (wrongly) believe that returning an error code was sensible error handling. In fact the spi core only emits a warning message in this case and otherwise continues as if the return value was zero. This usually yields resource leaks that sometimes can lead to exceptions later on. The atmel-quadspi driver is one of these drivers that got error handling wrong, this is fixed here and in the last patch the driver is converted to .remove_new() with the eventual goal to change .remove() to return void once all drivers are converted this way.
2 parents 1e49291 + 4d70dd0 commit 864f051

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

drivers/spi/atmel-quadspi.c

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -700,25 +700,33 @@ static int atmel_qspi_probe(struct platform_device *pdev)
700700
return err;
701701
}
702702

703-
static int atmel_qspi_remove(struct platform_device *pdev)
703+
static void atmel_qspi_remove(struct platform_device *pdev)
704704
{
705705
struct spi_controller *ctrl = platform_get_drvdata(pdev);
706706
struct atmel_qspi *aq = spi_controller_get_devdata(ctrl);
707707
int ret;
708708

709-
ret = pm_runtime_resume_and_get(&pdev->dev);
710-
if (ret < 0)
711-
return ret;
712-
713709
spi_unregister_controller(ctrl);
714-
atmel_qspi_write(QSPI_CR_QSPIDIS, aq, QSPI_CR);
710+
711+
ret = pm_runtime_get_sync(&pdev->dev);
712+
if (ret >= 0) {
713+
atmel_qspi_write(QSPI_CR_QSPIDIS, aq, QSPI_CR);
714+
clk_disable(aq->qspick);
715+
clk_disable(aq->pclk);
716+
} else {
717+
/*
718+
* atmel_qspi_runtime_{suspend,resume} just disable and enable
719+
* the two clks respectively. So after resume failed these are
720+
* off, and we skip hardware access and disabling these clks again.
721+
*/
722+
dev_warn(&pdev->dev, "Failed to resume device on remove\n");
723+
}
724+
725+
clk_unprepare(aq->qspick);
726+
clk_unprepare(aq->pclk);
715727

716728
pm_runtime_disable(&pdev->dev);
717729
pm_runtime_put_noidle(&pdev->dev);
718-
719-
clk_disable_unprepare(aq->qspick);
720-
clk_disable_unprepare(aq->pclk);
721-
return 0;
722730
}
723731

724732
static int __maybe_unused atmel_qspi_suspend(struct device *dev)
@@ -786,7 +794,11 @@ static int __maybe_unused atmel_qspi_runtime_resume(struct device *dev)
786794
if (ret)
787795
return ret;
788796

789-
return clk_enable(aq->qspick);
797+
ret = clk_enable(aq->qspick);
798+
if (ret)
799+
clk_disable(aq->pclk);
800+
801+
return ret;
790802
}
791803

792804
static const struct dev_pm_ops __maybe_unused atmel_qspi_pm_ops = {
@@ -823,7 +835,7 @@ static struct platform_driver atmel_qspi_driver = {
823835
.pm = pm_ptr(&atmel_qspi_pm_ops),
824836
},
825837
.probe = atmel_qspi_probe,
826-
.remove = atmel_qspi_remove,
838+
.remove_new = atmel_qspi_remove,
827839
};
828840
module_platform_driver(atmel_qspi_driver);
829841

0 commit comments

Comments
 (0)