diff options
author | Mark Brown <broonie@kernel.org> | 2022-07-13 16:19:13 +0200 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2022-07-13 16:19:13 +0200 |
commit | 1ed34d367bad6329d656c9b6808b16cec3bfe040 (patch) | |
tree | 69908246eb9d37fad9175a0bdcda5c2ad7589361 /drivers/spi | |
parent | spi: tegra20-slink: fix UAF in tegra_slink_remove() (diff) | |
parent | spi: microchip-core: switch to use dev_err_probe() (diff) | |
download | linux-1ed34d367bad6329d656c9b6808b16cec3bfe040.tar.xz linux-1ed34d367bad6329d656c9b6808b16cec3bfe040.zip |
spi: microchip-core: fix and cleanups
Merge series from Yang Yingliang <yangyingliang@huawei.com>:
Patch #1 fix a UAF in mchp_corespi_remove().
Patch #2 and #3 some cleanups to simpify code.
Diffstat (limited to 'drivers/spi')
-rw-r--r-- | drivers/spi/spi-microchip-core.c | 56 |
1 files changed, 20 insertions, 36 deletions
diff --git a/drivers/spi/spi-microchip-core.c b/drivers/spi/spi-microchip-core.c index b3083075cd36..ce4385330b19 100644 --- a/drivers/spi/spi-microchip-core.c +++ b/drivers/spi/spi-microchip-core.c @@ -513,7 +513,7 @@ static int mchp_corespi_probe(struct platform_device *pdev) u32 num_cs; int ret = 0; - master = spi_alloc_master(&pdev->dev, sizeof(*spi)); + master = devm_spi_alloc_master(&pdev->dev, sizeof(*spi)); if (!master) return dev_err_probe(&pdev->dev, -ENOMEM, "unable to allocate master for SPI controller\n"); @@ -535,58 +535,44 @@ static int mchp_corespi_probe(struct platform_device *pdev) spi = spi_master_get_devdata(master); spi->regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res); - if (IS_ERR(spi->regs)) { - ret = PTR_ERR(spi->regs); - goto error_release_master; - } + if (IS_ERR(spi->regs)) + return PTR_ERR(spi->regs); spi->irq = platform_get_irq(pdev, 0); - if (spi->irq <= 0) { - dev_err(&pdev->dev, "invalid IRQ %d for SPI controller\n", spi->irq); - ret = -ENXIO; - goto error_release_master; - } + if (spi->irq <= 0) + return dev_err_probe(&pdev->dev, -ENXIO, + "invalid IRQ %d for SPI controller\n", + spi->irq); ret = devm_request_irq(&pdev->dev, spi->irq, mchp_corespi_interrupt, IRQF_SHARED, dev_name(&pdev->dev), master); - if (ret) { - dev_err(&pdev->dev, "could not request irq: %d\n", ret); - goto error_release_master; - } + if (ret) + return dev_err_probe(&pdev->dev, ret, + "could not request irq: %d\n", ret); spi->clk = devm_clk_get(&pdev->dev, NULL); - if (IS_ERR(spi->clk)) { - ret = PTR_ERR(spi->clk); - dev_err(&pdev->dev, "could not get clk: %d\n", ret); - goto error_release_master; - } + if (IS_ERR(spi->clk)) + return dev_err_probe(&pdev->dev, PTR_ERR(spi->clk), + "could not get clk: %d\n", ret); ret = clk_prepare_enable(spi->clk); - if (ret) { - dev_err(&pdev->dev, "failed to enable clock\n"); - goto error_release_master; - } + if (ret) + return dev_err_probe(&pdev->dev, ret, + "failed to enable clock\n"); mchp_corespi_init(master, spi); ret = devm_spi_register_master(&pdev->dev, master); if (ret) { - dev_err(&pdev->dev, - "unable to register master for SPI controller\n"); - goto error_release_hardware; + mchp_corespi_disable(spi); + clk_disable_unprepare(spi->clk); + return dev_err_probe(&pdev->dev, ret, + "unable to register master for SPI controller\n"); } dev_info(&pdev->dev, "Registered SPI controller %d\n", master->bus_num); return 0; - -error_release_hardware: - mchp_corespi_disable(spi); - clk_disable_unprepare(spi->clk); -error_release_master: - spi_master_put(master); - - return ret; } static int mchp_corespi_remove(struct platform_device *pdev) @@ -595,8 +581,6 @@ static int mchp_corespi_remove(struct platform_device *pdev) struct mchp_corespi *spi = spi_master_get_devdata(master); mchp_corespi_disable_ints(spi); - spi_unregister_master(master); - spi_master_put(master); clk_disable_unprepare(spi->clk); mchp_corespi_disable(spi); |