Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'spi-fix-v7.1-merge-window' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi

Pull spi fixes from Mark Brown:
"This is quite a big set of fixes, almost all from Johan Hovold who is
on an ongoing quest to clean up issues with probe and removal handling
in drivers.

There isn't anything too concerning here especially with the
deregistration stuff which will very rarely get run in production
systems since this is all platform devices in the SoC on embedded
hardware, but it's all real issues which should be fixed. There's more
in flight here.

We also have a few other minor fixes, one from Felix Gu along the same
lines as Johan's work and a couple of documentation things"

* tag 'spi-fix-v7.1-merge-window' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi: (23 commits)
spi: fix controller cleanup() documentation
spi: fix resource leaks on device setup failure
spi: axiado: clean up probe return value
spi: axiado: rename probe error labels
spi: axiado: fix runtime pm imbalance on probe failure
spi: orion: clean up probe return value
spi: orion: fix clock imbalance on registration failure
spi: orion: fix runtime pm leak on unbind
spi: imx: fix runtime pm leak on probe deferral
spi: mpc52xx: fix use-after-free on registration failure
spi: Fix the error description in the `ptp_sts_word_post` comment
spi: topcliff-pch: fix use-after-free on unbind
spi: topcliff-pch: fix controller deregistration
spi: orion: fix controller deregistration
spi: mxic: fix controller deregistration
spi: mpc52xx: fix use-after-free on unbind
spi: mpc52xx: fix controller deregistration
spi: cadence-quadspi: fix controller deregistration
spi: cadence: fix controller deregistration
spi: mtk-snfi: fix memory leak in probe
...

+110 -58
+3 -3
Documentation/devicetree/bindings/spi/fsl,spi.yaml
··· 59 59 60 60 examples: 61 61 - | 62 - #include <dt-bindings/interrupt-controller/irq.h> 62 + #include <dt-bindings/gpio/gpio.h> 63 63 64 64 spi@4c0 { 65 65 compatible = "fsl,spi"; ··· 67 67 cell-index = <0>; 68 68 interrupts = <82 0>; 69 69 mode = "cpu"; 70 - cs-gpios = <&gpio 18 IRQ_TYPE_EDGE_RISING // device reg=<0> 71 - &gpio 19 IRQ_TYPE_EDGE_RISING>; // device reg=<1> 70 + cs-gpios = <&gpio 18 GPIO_ACTIVE_HIGH>, // device reg=<0> 71 + <&gpio 19 GPIO_ACTIVE_HIGH>; // device reg=<1> 72 72 }; 73 73 74 74 ...
+2 -2
MAINTAINERS
··· 24655 24655 F: drivers/net/ethernet/socionext/netsec.c 24656 24656 24657 24657 SOCIONEXT (SNI) Synquacer SPI DRIVER 24658 - M: Masahisa Kojima <masahisa.kojima@linaro.org> 24659 - M: Jassi Brar <jaswinder.singh@linaro.org> 24658 + M: Masahisa Kojima <kojima.masahisa@socionext.com> 24659 + M: Jassi Brar <jassisinghbrar@gmail.com> 24660 24660 L: linux-spi@vger.kernel.org 24661 24661 S: Maintained 24662 24662 F: Documentation/devicetree/bindings/spi/socionext,synquacer-spi.yaml
+19 -12
drivers/spi/spi-axiado.c
··· 751 751 */ 752 752 static int ax_spi_probe(struct platform_device *pdev) 753 753 { 754 - int ret = 0, irq; 755 754 struct spi_controller *ctlr; 756 755 struct ax_spi *xspi; 756 + int ret, irq; 757 757 u32 num_cs; 758 758 759 759 ctlr = devm_spi_alloc_host(&pdev->dev, sizeof(*xspi)); ··· 785 785 ret = clk_prepare_enable(xspi->ref_clk); 786 786 if (ret) { 787 787 dev_err(&pdev->dev, "Unable to enable device clock.\n"); 788 - goto clk_dis_apb; 788 + goto err_disable_apb; 789 789 } 790 790 791 791 pm_runtime_use_autosuspend(&pdev->dev); ··· 815 815 irq = platform_get_irq(pdev, 0); 816 816 if (irq <= 0) { 817 817 ret = -ENXIO; 818 - goto clk_dis_all; 818 + goto err_disable_rpm; 819 819 } 820 820 821 821 ret = devm_request_irq(&pdev->dev, irq, ax_spi_irq, ··· 823 823 if (ret != 0) { 824 824 ret = -ENXIO; 825 825 dev_err(&pdev->dev, "request_irq failed\n"); 826 - goto clk_dis_all; 826 + goto err_disable_rpm; 827 827 } 828 828 829 829 ctlr->use_gpio_descriptors = true; ··· 842 842 843 843 ctlr->bits_per_word_mask = SPI_BPW_MASK(8); 844 844 845 - pm_runtime_put_autosuspend(&pdev->dev); 846 - 847 845 ctlr->mem_ops = &ax_spi_mem_ops; 848 846 849 847 ret = spi_register_controller(ctlr); 850 848 if (ret) { 851 849 dev_err(&pdev->dev, "spi_register_controller failed\n"); 852 - goto clk_dis_all; 850 + goto err_disable_rpm; 853 851 } 854 852 855 - return ret; 853 + pm_runtime_put_autosuspend(&pdev->dev); 856 854 857 - clk_dis_all: 858 - pm_runtime_set_suspended(&pdev->dev); 855 + return 0; 856 + 857 + err_disable_rpm: 859 858 pm_runtime_disable(&pdev->dev); 859 + pm_runtime_put_noidle(&pdev->dev); 860 + pm_runtime_set_suspended(&pdev->dev); 861 + pm_runtime_dont_use_autosuspend(&pdev->dev); 862 + 860 863 clk_disable_unprepare(xspi->ref_clk); 861 - clk_dis_apb: 864 + err_disable_apb: 862 865 clk_disable_unprepare(xspi->pclk); 863 866 864 867 return ret; ··· 880 877 struct spi_controller *ctlr = platform_get_drvdata(pdev); 881 878 struct ax_spi *xspi = spi_controller_get_devdata(ctlr); 882 879 880 + pm_runtime_get_sync(&pdev->dev); 881 + 883 882 spi_unregister_controller(ctlr); 884 883 885 - pm_runtime_set_suspended(&pdev->dev); 886 884 pm_runtime_disable(&pdev->dev); 885 + pm_runtime_put_noidle(&pdev->dev); 886 + pm_runtime_set_suspended(&pdev->dev); 887 + pm_runtime_dont_use_autosuspend(&pdev->dev); 887 888 888 889 clk_disable_unprepare(xspi->ref_clk); 889 890 clk_disable_unprepare(xspi->pclk);
+2 -2
drivers/spi/spi-cadence-quadspi.c
··· 2016 2016 2017 2017 ddata = of_device_get_match_data(dev); 2018 2018 2019 + spi_unregister_controller(cqspi->host); 2020 + 2019 2021 refcount_set(&cqspi->refcount, 0); 2020 2022 2021 2023 if (!refcount_dec_and_test(&cqspi->inflight_ops)) 2022 2024 cqspi_wait_idle(cqspi); 2023 - 2024 - spi_unregister_controller(cqspi->host); 2025 2025 2026 2026 if (cqspi->rx_chan) 2027 2027 dma_release_channel(cqspi->rx_chan);
+5 -1
drivers/spi/spi-cadence.c
··· 777 777 struct spi_controller *ctlr = platform_get_drvdata(pdev); 778 778 struct cdns_spi *xspi = spi_controller_get_devdata(ctlr); 779 779 780 + spi_controller_get(ctlr); 781 + 782 + spi_unregister_controller(ctlr); 783 + 780 784 cdns_spi_write(xspi, CDNS_SPI_ER, CDNS_SPI_ER_DISABLE); 781 785 782 786 if (!spi_controller_is_target(ctlr)) { ··· 788 784 pm_runtime_set_suspended(&pdev->dev); 789 785 } 790 786 791 - spi_unregister_controller(ctlr); 787 + spi_controller_put(ctlr); 792 788 } 793 789 794 790 /**
+1
drivers/spi/spi-imx.c
··· 2373 2373 out_runtime_pm_put: 2374 2374 pm_runtime_dont_use_autosuspend(spi_imx->dev); 2375 2375 pm_runtime_disable(spi_imx->dev); 2376 + pm_runtime_put_noidle(spi_imx->dev); 2376 2377 pm_runtime_set_suspended(&pdev->dev); 2377 2378 2378 2379 clk_disable_unprepare(spi_imx->clk_ipg);
+7 -2
drivers/spi/spi-mpc52xx.c
··· 498 498 499 499 err_register: 500 500 dev_err(&ms->host->dev, "initialization failed\n"); 501 + free_irq(ms->irq0, ms); 502 + free_irq(ms->irq1, ms); 503 + cancel_work_sync(&ms->work); 501 504 err_gpio: 502 505 while (i-- > 0) 503 506 gpiod_put(ms->gpio_cs[i]); ··· 520 517 struct mpc52xx_spi *ms = spi_controller_get_devdata(host); 521 518 int i; 522 519 523 - cancel_work_sync(&ms->work); 520 + spi_unregister_controller(host); 521 + 524 522 free_irq(ms->irq0, ms); 525 523 free_irq(ms->irq1, ms); 524 + 525 + cancel_work_sync(&ms->work); 526 526 527 527 for (i = 0; i < ms->gpio_cs_count; i++) 528 528 gpiod_put(ms->gpio_cs[i]); 529 529 530 530 kfree(ms->gpio_cs); 531 - spi_unregister_controller(host); 532 531 iounmap(ms->regs); 533 532 spi_controller_put(host); 534 533 }
+5 -3
drivers/spi/spi-mtk-snfi.c
··· 1447 1447 ret = nand_ecc_register_on_host_hw_engine(&ms->ecc_eng); 1448 1448 if (ret) { 1449 1449 dev_err(&pdev->dev, "failed to register ecc engine.\n"); 1450 - goto release_ecc; 1450 + goto free_buf; 1451 1451 } 1452 1452 1453 1453 ret = devm_add_action_or_reset(&pdev->dev, mtk_unregister_ecc_engine, 1454 1454 &ms->ecc_eng); 1455 1455 if (ret) { 1456 1456 dev_err_probe(&pdev->dev, ret, "failed to add ECC unregister action\n"); 1457 - goto release_ecc; 1457 + goto free_buf; 1458 1458 } 1459 1459 1460 1460 ctlr->num_chipselect = 1; ··· 1465 1465 ret = spi_register_controller(ctlr); 1466 1466 if (ret) { 1467 1467 dev_err(&pdev->dev, "spi_register_controller failed.\n"); 1468 - goto release_ecc; 1468 + goto free_buf; 1469 1469 } 1470 1470 1471 1471 return 0; 1472 + free_buf: 1473 + kfree(ms->buf); 1472 1474 release_ecc: 1473 1475 mtk_ecc_release(ms->ecc); 1474 1476 return ret;
+2 -1
drivers/spi/spi-mxic.c
··· 832 832 struct spi_controller *host = platform_get_drvdata(pdev); 833 833 struct mxic_spi *mxic = spi_controller_get_devdata(host); 834 834 835 + spi_unregister_controller(host); 836 + 835 837 pm_runtime_disable(&pdev->dev); 836 838 mxic_spi_mem_ecc_remove(mxic); 837 - spi_unregister_controller(host); 838 839 } 839 840 840 841 static const struct of_device_id mxic_spi_of_ids[] = {
+17 -3
drivers/spi/spi-orion.c
··· 648 648 struct orion_spi *spi; 649 649 struct resource *r; 650 650 unsigned long tclk_hz; 651 - int status = 0; 652 651 struct device_node *np; 652 + int status; 653 653 654 654 host = spi_alloc_host(&pdev->dev, sizeof(*spi)); 655 655 if (host == NULL) { ··· 774 774 pm_runtime_set_active(&pdev->dev); 775 775 pm_runtime_use_autosuspend(&pdev->dev); 776 776 pm_runtime_set_autosuspend_delay(&pdev->dev, SPI_AUTOSUSPEND_TIMEOUT); 777 + pm_runtime_get_noresume(&pdev->dev); 777 778 pm_runtime_enable(&pdev->dev); 778 779 779 780 status = orion_spi_reset(spi); ··· 785 784 if (status < 0) 786 785 goto out_rel_pm; 787 786 788 - return status; 787 + pm_runtime_put_autosuspend(&pdev->dev); 788 + 789 + return 0; 789 790 790 791 out_rel_pm: 791 792 pm_runtime_disable(&pdev->dev); 793 + pm_runtime_put_noidle(&pdev->dev); 794 + pm_runtime_set_suspended(&pdev->dev); 795 + pm_runtime_dont_use_autosuspend(&pdev->dev); 792 796 out_rel_axi_clk: 793 797 clk_disable_unprepare(spi->axi_clk); 794 798 out: ··· 807 801 struct spi_controller *host = platform_get_drvdata(pdev); 808 802 struct orion_spi *spi = spi_controller_get_devdata(host); 809 803 804 + spi_controller_get(host); 805 + 806 + spi_unregister_controller(host); 807 + 810 808 pm_runtime_get_sync(&pdev->dev); 811 809 clk_disable_unprepare(spi->axi_clk); 812 810 813 - spi_unregister_controller(host); 811 + spi_controller_put(host); 812 + 814 813 pm_runtime_disable(&pdev->dev); 814 + pm_runtime_put_noidle(&pdev->dev); 815 + pm_runtime_set_suspended(&pdev->dev); 816 + pm_runtime_dont_use_autosuspend(&pdev->dev); 815 817 } 816 818 817 819 MODULE_ALIAS("platform:" DRIVER_NAME);
+8 -3
drivers/spi/spi-topcliff-pch.c
··· 1406 1406 dev_dbg(&plat_dev->dev, "%s:[ch%d] irq=%d\n", 1407 1407 __func__, plat_dev->id, board_dat->pdev->irq); 1408 1408 1409 - if (use_dma) 1410 - pch_free_dma_buf(board_dat, data); 1409 + spi_controller_get(data->host); 1410 + 1411 + spi_unregister_controller(data->host); 1411 1412 1412 1413 /* check for any pending messages; no action is taken if the queue 1413 1414 * is still full; but at least we tried. Unload anyway */ ··· 1433 1432 free_irq(board_dat->pdev->irq, data); 1434 1433 } 1435 1434 1435 + if (use_dma) 1436 + pch_free_dma_buf(board_dat, data); 1437 + 1436 1438 pci_iounmap(board_dat->pdev, data->io_remap_addr); 1437 - spi_unregister_controller(data->host); 1439 + 1440 + spi_controller_put(data->host); 1438 1441 } 1439 1442 #ifdef CONFIG_PM 1440 1443 static int pch_spi_pd_suspend(struct platform_device *pd_dev,
+37 -24
drivers/spi/spi.c
··· 43 43 44 44 #include "internals.h" 45 45 46 + static int __spi_setup(struct spi_device *spi, bool initial_setup); 47 + 46 48 static DEFINE_IDR(spi_controller_idr); 47 49 48 50 static void spidev_release(struct device *dev) ··· 745 743 * normally rely on the device being setup. Devices 746 744 * using SPI_CS_HIGH can't coexist well otherwise... 747 745 */ 748 - status = spi_setup(spi); 746 + status = __spi_setup(spi, true); 749 747 if (status < 0) { 750 748 dev_err(dev, "can't setup %s, status %d\n", 751 749 dev_name(&spi->dev), status); ··· 4051 4049 return status; 4052 4050 } 4053 4051 4054 - /** 4055 - * spi_setup - setup SPI mode and clock rate 4056 - * @spi: the device whose settings are being modified 4057 - * Context: can sleep, and no requests are queued to the device 4058 - * 4059 - * SPI protocol drivers may need to update the transfer mode if the 4060 - * device doesn't work with its default. They may likewise need 4061 - * to update clock rates or word sizes from initial values. This function 4062 - * changes those settings, and must be called from a context that can sleep. 4063 - * Except for SPI_CS_HIGH, which takes effect immediately, the changes take 4064 - * effect the next time the device is selected and data is transferred to 4065 - * or from it. When this function returns, the SPI device is deselected. 4066 - * 4067 - * Note that this call will fail if the protocol driver specifies an option 4068 - * that the underlying controller or its driver does not support. For 4069 - * example, not all hardware supports wire transfers using nine bit words, 4070 - * LSB-first wire encoding, or active-high chipselects. 4071 - * 4072 - * Return: zero on success, else a negative error code. 4073 - */ 4074 - int spi_setup(struct spi_device *spi) 4052 + static int __spi_setup(struct spi_device *spi, bool initial_setup) 4075 4053 { 4076 4054 unsigned bad_bits, ugly_bits; 4077 4055 int status; ··· 4136 4154 status = spi_set_cs_timing(spi); 4137 4155 if (status) { 4138 4156 mutex_unlock(&spi->controller->io_mutex); 4139 - return status; 4157 + goto err_cleanup; 4140 4158 } 4141 4159 4142 4160 if (spi->controller->auto_runtime_pm && spi->controller->set_cs) { ··· 4145 4163 mutex_unlock(&spi->controller->io_mutex); 4146 4164 dev_err(&spi->controller->dev, "Failed to power device: %d\n", 4147 4165 status); 4148 - return status; 4166 + goto err_cleanup; 4149 4167 } 4150 4168 4151 4169 /* ··· 4181 4199 status); 4182 4200 4183 4201 return status; 4202 + 4203 + err_cleanup: 4204 + if (initial_setup) 4205 + spi_cleanup(spi); 4206 + 4207 + return status; 4208 + } 4209 + 4210 + /** 4211 + * spi_setup - setup SPI mode and clock rate 4212 + * @spi: the device whose settings are being modified 4213 + * Context: can sleep, and no requests are queued to the device 4214 + * 4215 + * SPI protocol drivers may need to update the transfer mode if the 4216 + * device doesn't work with its default. They may likewise need 4217 + * to update clock rates or word sizes from initial values. This function 4218 + * changes those settings, and must be called from a context that can sleep. 4219 + * Except for SPI_CS_HIGH, which takes effect immediately, the changes take 4220 + * effect the next time the device is selected and data is transferred to 4221 + * or from it. When this function returns, the SPI device is deselected. 4222 + * 4223 + * Note that this call will fail if the protocol driver specifies an option 4224 + * that the underlying controller or its driver does not support. For 4225 + * example, not all hardware supports wire transfers using nine bit words, 4226 + * LSB-first wire encoding, or active-high chipselects. 4227 + * 4228 + * Return: zero on success, else a negative error code. 4229 + */ 4230 + int spi_setup(struct spi_device *spi) 4231 + { 4232 + return __spi_setup(spi, false); 4184 4233 } 4185 4234 EXPORT_SYMBOL_GPL(spi_setup); 4186 4235
+2 -2
include/linux/spi/spi.h
··· 701 701 int (*transfer)(struct spi_device *spi, 702 702 struct spi_message *mesg); 703 703 704 - /* Called on release() to free memory provided by spi_controller */ 704 + /* Called on deregistration to free memory provided by spi_controller */ 705 705 void (*cleanup)(struct spi_device *spi); 706 706 707 707 /* ··· 1019 1019 * this value may have changed compared to what was requested, depending 1020 1020 * on the available snapshotting resolution (DMA transfer, 1021 1021 * @ptp_sts_supported is false, etc). 1022 - * @ptp_sts_word_post: See @ptp_sts_word_post. The two can be equal (meaning 1022 + * @ptp_sts_word_post: See @ptp_sts_word_pre. The two can be equal (meaning 1023 1023 * that a single byte should be snapshotted). 1024 1024 * If the core takes care of the timestamp (if @ptp_sts_supported is false 1025 1025 * for this controller), it will set @ptp_sts_word_pre to 0, and