Skip to content

Commit b2680ba

Browse files
committed
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 ...
2 parents f643998 + 16ab65d commit b2680ba

13 files changed

Lines changed: 110 additions & 58 deletions

File tree

Documentation/devicetree/bindings/spi/fsl,spi.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,16 @@ unevaluatedProperties: false
5959

6060
examples:
6161
- |
62-
#include <dt-bindings/interrupt-controller/irq.h>
62+
#include <dt-bindings/gpio/gpio.h>
6363
6464
spi@4c0 {
6565
compatible = "fsl,spi";
6666
reg = <0x4c0 0x40>;
6767
cell-index = <0>;
6868
interrupts = <82 0>;
6969
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>
7272
};
7373
7474
...

MAINTAINERS

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24655,8 +24655,8 @@ F: Documentation/devicetree/bindings/net/socionext,synquacer-netsec.yaml
2465524655
F: drivers/net/ethernet/socionext/netsec.c
2465624656

2465724657
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>
2466024660
L: linux-spi@vger.kernel.org
2466124661
S: Maintained
2466224662
F: Documentation/devicetree/bindings/spi/socionext,synquacer-spi.yaml

drivers/spi/spi-axiado.c

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -751,9 +751,9 @@ static const struct spi_controller_mem_ops ax_spi_mem_ops = {
751751
*/
752752
static int ax_spi_probe(struct platform_device *pdev)
753753
{
754-
int ret = 0, irq;
755754
struct spi_controller *ctlr;
756755
struct ax_spi *xspi;
756+
int ret, irq;
757757
u32 num_cs;
758758

759759
ctlr = devm_spi_alloc_host(&pdev->dev, sizeof(*xspi));
@@ -785,7 +785,7 @@ static int ax_spi_probe(struct platform_device *pdev)
785785
ret = clk_prepare_enable(xspi->ref_clk);
786786
if (ret) {
787787
dev_err(&pdev->dev, "Unable to enable device clock.\n");
788-
goto clk_dis_apb;
788+
goto err_disable_apb;
789789
}
790790

791791
pm_runtime_use_autosuspend(&pdev->dev);
@@ -815,15 +815,15 @@ static int ax_spi_probe(struct platform_device *pdev)
815815
irq = platform_get_irq(pdev, 0);
816816
if (irq <= 0) {
817817
ret = -ENXIO;
818-
goto clk_dis_all;
818+
goto err_disable_rpm;
819819
}
820820

821821
ret = devm_request_irq(&pdev->dev, irq, ax_spi_irq,
822822
0, pdev->name, ctlr);
823823
if (ret != 0) {
824824
ret = -ENXIO;
825825
dev_err(&pdev->dev, "request_irq failed\n");
826-
goto clk_dis_all;
826+
goto err_disable_rpm;
827827
}
828828

829829
ctlr->use_gpio_descriptors = true;
@@ -842,23 +842,26 @@ static int ax_spi_probe(struct platform_device *pdev)
842842

843843
ctlr->bits_per_word_mask = SPI_BPW_MASK(8);
844844

845-
pm_runtime_put_autosuspend(&pdev->dev);
846-
847845
ctlr->mem_ops = &ax_spi_mem_ops;
848846

849847
ret = spi_register_controller(ctlr);
850848
if (ret) {
851849
dev_err(&pdev->dev, "spi_register_controller failed\n");
852-
goto clk_dis_all;
850+
goto err_disable_rpm;
853851
}
854852

855-
return ret;
853+
pm_runtime_put_autosuspend(&pdev->dev);
856854

857-
clk_dis_all:
858-
pm_runtime_set_suspended(&pdev->dev);
855+
return 0;
856+
857+
err_disable_rpm:
859858
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+
860863
clk_disable_unprepare(xspi->ref_clk);
861-
clk_dis_apb:
864+
err_disable_apb:
862865
clk_disable_unprepare(xspi->pclk);
863866

864867
return ret;
@@ -877,10 +880,14 @@ static void ax_spi_remove(struct platform_device *pdev)
877880
struct spi_controller *ctlr = platform_get_drvdata(pdev);
878881
struct ax_spi *xspi = spi_controller_get_devdata(ctlr);
879882

883+
pm_runtime_get_sync(&pdev->dev);
884+
880885
spi_unregister_controller(ctlr);
881886

882-
pm_runtime_set_suspended(&pdev->dev);
883887
pm_runtime_disable(&pdev->dev);
888+
pm_runtime_put_noidle(&pdev->dev);
889+
pm_runtime_set_suspended(&pdev->dev);
890+
pm_runtime_dont_use_autosuspend(&pdev->dev);
884891

885892
clk_disable_unprepare(xspi->ref_clk);
886893
clk_disable_unprepare(xspi->pclk);

drivers/spi/spi-cadence-quadspi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2016,13 +2016,13 @@ static void cqspi_remove(struct platform_device *pdev)
20162016

20172017
ddata = of_device_get_match_data(dev);
20182018

2019+
spi_unregister_controller(cqspi->host);
2020+
20192021
refcount_set(&cqspi->refcount, 0);
20202022

20212023
if (!refcount_dec_and_test(&cqspi->inflight_ops))
20222024
cqspi_wait_idle(cqspi);
20232025

2024-
spi_unregister_controller(cqspi->host);
2025-
20262026
if (cqspi->rx_chan)
20272027
dma_release_channel(cqspi->rx_chan);
20282028

drivers/spi/spi-cadence.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,14 +777,18 @@ static void cdns_spi_remove(struct platform_device *pdev)
777777
struct spi_controller *ctlr = platform_get_drvdata(pdev);
778778
struct cdns_spi *xspi = spi_controller_get_devdata(ctlr);
779779

780+
spi_controller_get(ctlr);
781+
782+
spi_unregister_controller(ctlr);
783+
780784
cdns_spi_write(xspi, CDNS_SPI_ER, CDNS_SPI_ER_DISABLE);
781785

782786
if (!spi_controller_is_target(ctlr)) {
783787
pm_runtime_disable(&pdev->dev);
784788
pm_runtime_set_suspended(&pdev->dev);
785789
}
786790

787-
spi_unregister_controller(ctlr);
791+
spi_controller_put(ctlr);
788792
}
789793

790794
/**

drivers/spi/spi-imx.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2373,6 +2373,7 @@ static int spi_imx_probe(struct platform_device *pdev)
23732373
out_runtime_pm_put:
23742374
pm_runtime_dont_use_autosuspend(spi_imx->dev);
23752375
pm_runtime_disable(spi_imx->dev);
2376+
pm_runtime_put_noidle(spi_imx->dev);
23762377
pm_runtime_set_suspended(&pdev->dev);
23772378

23782379
clk_disable_unprepare(spi_imx->clk_ipg);

drivers/spi/spi-mpc52xx.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,9 @@ static int mpc52xx_spi_probe(struct platform_device *op)
498498

499499
err_register:
500500
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);
501504
err_gpio:
502505
while (i-- > 0)
503506
gpiod_put(ms->gpio_cs[i]);
@@ -517,15 +520,17 @@ static void mpc52xx_spi_remove(struct platform_device *op)
517520
struct mpc52xx_spi *ms = spi_controller_get_devdata(host);
518521
int i;
519522

520-
cancel_work_sync(&ms->work);
523+
spi_unregister_controller(host);
524+
521525
free_irq(ms->irq0, ms);
522526
free_irq(ms->irq1, ms);
523527

528+
cancel_work_sync(&ms->work);
529+
524530
for (i = 0; i < ms->gpio_cs_count; i++)
525531
gpiod_put(ms->gpio_cs[i]);
526532

527533
kfree(ms->gpio_cs);
528-
spi_unregister_controller(host);
529534
iounmap(ms->regs);
530535
spi_controller_put(host);
531536
}

drivers/spi/spi-mtk-snfi.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,14 +1447,14 @@ static int mtk_snand_probe(struct platform_device *pdev)
14471447
ret = nand_ecc_register_on_host_hw_engine(&ms->ecc_eng);
14481448
if (ret) {
14491449
dev_err(&pdev->dev, "failed to register ecc engine.\n");
1450-
goto release_ecc;
1450+
goto free_buf;
14511451
}
14521452

14531453
ret = devm_add_action_or_reset(&pdev->dev, mtk_unregister_ecc_engine,
14541454
&ms->ecc_eng);
14551455
if (ret) {
14561456
dev_err_probe(&pdev->dev, ret, "failed to add ECC unregister action\n");
1457-
goto release_ecc;
1457+
goto free_buf;
14581458
}
14591459

14601460
ctlr->num_chipselect = 1;
@@ -1465,10 +1465,12 @@ static int mtk_snand_probe(struct platform_device *pdev)
14651465
ret = spi_register_controller(ctlr);
14661466
if (ret) {
14671467
dev_err(&pdev->dev, "spi_register_controller failed.\n");
1468-
goto release_ecc;
1468+
goto free_buf;
14691469
}
14701470

14711471
return 0;
1472+
free_buf:
1473+
kfree(ms->buf);
14721474
release_ecc:
14731475
mtk_ecc_release(ms->ecc);
14741476
return ret;

drivers/spi/spi-mxic.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -832,9 +832,10 @@ static void mxic_spi_remove(struct platform_device *pdev)
832832
struct spi_controller *host = platform_get_drvdata(pdev);
833833
struct mxic_spi *mxic = spi_controller_get_devdata(host);
834834

835+
spi_unregister_controller(host);
836+
835837
pm_runtime_disable(&pdev->dev);
836838
mxic_spi_mem_ecc_remove(mxic);
837-
spi_unregister_controller(host);
838839
}
839840

840841
static const struct of_device_id mxic_spi_of_ids[] = {

drivers/spi/spi-orion.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -648,8 +648,8 @@ static int orion_spi_probe(struct platform_device *pdev)
648648
struct orion_spi *spi;
649649
struct resource *r;
650650
unsigned long tclk_hz;
651-
int status = 0;
652651
struct device_node *np;
652+
int status;
653653

654654
host = spi_alloc_host(&pdev->dev, sizeof(*spi));
655655
if (host == NULL) {
@@ -774,6 +774,7 @@ static int orion_spi_probe(struct platform_device *pdev)
774774
pm_runtime_set_active(&pdev->dev);
775775
pm_runtime_use_autosuspend(&pdev->dev);
776776
pm_runtime_set_autosuspend_delay(&pdev->dev, SPI_AUTOSUSPEND_TIMEOUT);
777+
pm_runtime_get_noresume(&pdev->dev);
777778
pm_runtime_enable(&pdev->dev);
778779

779780
status = orion_spi_reset(spi);
@@ -784,10 +785,15 @@ static int orion_spi_probe(struct platform_device *pdev)
784785
if (status < 0)
785786
goto out_rel_pm;
786787

787-
return status;
788+
pm_runtime_put_autosuspend(&pdev->dev);
789+
790+
return 0;
788791

789792
out_rel_pm:
790793
pm_runtime_disable(&pdev->dev);
794+
pm_runtime_put_noidle(&pdev->dev);
795+
pm_runtime_set_suspended(&pdev->dev);
796+
pm_runtime_dont_use_autosuspend(&pdev->dev);
791797
out_rel_axi_clk:
792798
clk_disable_unprepare(spi->axi_clk);
793799
out:
@@ -801,11 +807,19 @@ static void orion_spi_remove(struct platform_device *pdev)
801807
struct spi_controller *host = platform_get_drvdata(pdev);
802808
struct orion_spi *spi = spi_controller_get_devdata(host);
803809

810+
spi_controller_get(host);
811+
812+
spi_unregister_controller(host);
813+
804814
pm_runtime_get_sync(&pdev->dev);
805815
clk_disable_unprepare(spi->axi_clk);
806816

807-
spi_unregister_controller(host);
817+
spi_controller_put(host);
818+
808819
pm_runtime_disable(&pdev->dev);
820+
pm_runtime_put_noidle(&pdev->dev);
821+
pm_runtime_set_suspended(&pdev->dev);
822+
pm_runtime_dont_use_autosuspend(&pdev->dev);
809823
}
810824

811825
MODULE_ALIAS("platform:" DRIVER_NAME);

0 commit comments

Comments
 (0)