Skip to content

Commit 9f582e3

Browse files
committed
Merge tag 'spi-fix-v7.0-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi
Pull spi fixes from Mark Brown: "There's a couple of core fixes here from Johan, fixing a race condition and an error handling path, plus a bunch of driver specific fixups. The Qualcomm issues could be nasty if you ran into them, especially the DMA ordering one" * tag 'spi-fix-v7.0-rc4' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi: spi: geni-qcom: Check DMA interrupts early in ISR spi: fix statistics allocation spi: fix use-after-free on controller registration failure spi: geni-qcom: Fix CPHA and CPOL mode change detection spi: axiado: Fix double-free in ax_spi_probe() spi: amlogic-spisg: Fix memory leak in aml_spisg_probe() spi: amlogic: spifc-a4: Remove redundant clock cleanup
2 parents 007fe23 + 8c89a07 commit 9f582e3

5 files changed

Lines changed: 41 additions & 86 deletions

File tree

drivers/spi/spi-amlogic-spifc-a4.c

Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,14 +1083,6 @@ static int aml_sfc_clk_init(struct aml_sfc *sfc)
10831083
return clk_set_rate(sfc->core_clk, SFC_BUS_DEFAULT_CLK);
10841084
}
10851085

1086-
static int aml_sfc_disable_clk(struct aml_sfc *sfc)
1087-
{
1088-
clk_disable_unprepare(sfc->core_clk);
1089-
clk_disable_unprepare(sfc->gate_clk);
1090-
1091-
return 0;
1092-
}
1093-
10941086
static int aml_sfc_probe(struct platform_device *pdev)
10951087
{
10961088
struct device_node *np = pdev->dev.of_node;
@@ -1141,27 +1133,21 @@ static int aml_sfc_probe(struct platform_device *pdev)
11411133

11421134
/* Enable Amlogic flash controller spi mode */
11431135
ret = regmap_write(sfc->regmap_base, SFC_SPI_CFG, SPI_MODE_EN);
1144-
if (ret) {
1145-
dev_err(dev, "failed to enable SPI mode\n");
1146-
goto err_out;
1147-
}
1136+
if (ret)
1137+
return dev_err_probe(dev, ret, "failed to enable SPI mode\n");
11481138

11491139
ret = dma_set_mask(sfc->dev, DMA_BIT_MASK(32));
1150-
if (ret) {
1151-
dev_err(sfc->dev, "failed to set dma mask\n");
1152-
goto err_out;
1153-
}
1140+
if (ret)
1141+
return dev_err_probe(sfc->dev, ret, "failed to set dma mask\n");
11541142

11551143
sfc->ecc_eng.dev = &pdev->dev;
11561144
sfc->ecc_eng.integration = NAND_ECC_ENGINE_INTEGRATION_PIPELINED;
11571145
sfc->ecc_eng.ops = &aml_sfc_ecc_engine_ops;
11581146
sfc->ecc_eng.priv = sfc;
11591147

11601148
ret = nand_ecc_register_on_host_hw_engine(&sfc->ecc_eng);
1161-
if (ret) {
1162-
dev_err(&pdev->dev, "failed to register Aml host ecc engine.\n");
1163-
goto err_out;
1164-
}
1149+
if (ret)
1150+
return dev_err_probe(&pdev->dev, ret, "failed to register Aml host ecc engine.\n");
11651151

11661152
ret = of_property_read_u32(np, "amlogic,rx-adj", &val);
11671153
if (!ret)
@@ -1177,24 +1163,7 @@ static int aml_sfc_probe(struct platform_device *pdev)
11771163
ctrl->min_speed_hz = SFC_MIN_FREQUENCY;
11781164
ctrl->num_chipselect = SFC_MAX_CS_NUM;
11791165

1180-
ret = devm_spi_register_controller(dev, ctrl);
1181-
if (ret)
1182-
goto err_out;
1183-
1184-
return 0;
1185-
1186-
err_out:
1187-
aml_sfc_disable_clk(sfc);
1188-
1189-
return ret;
1190-
}
1191-
1192-
static void aml_sfc_remove(struct platform_device *pdev)
1193-
{
1194-
struct spi_controller *ctlr = platform_get_drvdata(pdev);
1195-
struct aml_sfc *sfc = spi_controller_get_devdata(ctlr);
1196-
1197-
aml_sfc_disable_clk(sfc);
1166+
return devm_spi_register_controller(dev, ctrl);
11981167
}
11991168

12001169
static const struct of_device_id aml_sfc_of_match[] = {
@@ -1212,7 +1181,6 @@ static struct platform_driver aml_sfc_driver = {
12121181
.of_match_table = aml_sfc_of_match,
12131182
},
12141183
.probe = aml_sfc_probe,
1215-
.remove = aml_sfc_remove,
12161184
};
12171185
module_platform_driver(aml_sfc_driver);
12181186

drivers/spi/spi-amlogic-spisg.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -729,9 +729,9 @@ static int aml_spisg_probe(struct platform_device *pdev)
729729
};
730730

731731
if (of_property_read_bool(dev->of_node, "spi-slave"))
732-
ctlr = spi_alloc_target(dev, sizeof(*spisg));
732+
ctlr = devm_spi_alloc_target(dev, sizeof(*spisg));
733733
else
734-
ctlr = spi_alloc_host(dev, sizeof(*spisg));
734+
ctlr = devm_spi_alloc_host(dev, sizeof(*spisg));
735735
if (!ctlr)
736736
return -ENOMEM;
737737

@@ -750,10 +750,8 @@ static int aml_spisg_probe(struct platform_device *pdev)
750750
return dev_err_probe(dev, PTR_ERR(spisg->map), "regmap init failed\n");
751751

752752
irq = platform_get_irq(pdev, 0);
753-
if (irq < 0) {
754-
ret = irq;
755-
goto out_controller;
756-
}
753+
if (irq < 0)
754+
return irq;
757755

758756
ret = device_reset_optional(dev);
759757
if (ret)
@@ -817,8 +815,6 @@ static int aml_spisg_probe(struct platform_device *pdev)
817815
if (spisg->core)
818816
clk_disable_unprepare(spisg->core);
819817
clk_disable_unprepare(spisg->pclk);
820-
out_controller:
821-
spi_controller_put(ctlr);
822818

823819
return ret;
824820
}

drivers/spi/spi-axiado.c

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -765,30 +765,22 @@ static int ax_spi_probe(struct platform_device *pdev)
765765
platform_set_drvdata(pdev, ctlr);
766766

767767
xspi->regs = devm_platform_ioremap_resource(pdev, 0);
768-
if (IS_ERR(xspi->regs)) {
769-
ret = PTR_ERR(xspi->regs);
770-
goto remove_ctlr;
771-
}
768+
if (IS_ERR(xspi->regs))
769+
return PTR_ERR(xspi->regs);
772770

773771
xspi->pclk = devm_clk_get(&pdev->dev, "pclk");
774-
if (IS_ERR(xspi->pclk)) {
775-
dev_err(&pdev->dev, "pclk clock not found.\n");
776-
ret = PTR_ERR(xspi->pclk);
777-
goto remove_ctlr;
778-
}
772+
if (IS_ERR(xspi->pclk))
773+
return dev_err_probe(&pdev->dev, PTR_ERR(xspi->pclk),
774+
"pclk clock not found.\n");
779775

780776
xspi->ref_clk = devm_clk_get(&pdev->dev, "ref");
781-
if (IS_ERR(xspi->ref_clk)) {
782-
dev_err(&pdev->dev, "ref clock not found.\n");
783-
ret = PTR_ERR(xspi->ref_clk);
784-
goto remove_ctlr;
785-
}
777+
if (IS_ERR(xspi->ref_clk))
778+
return dev_err_probe(&pdev->dev, PTR_ERR(xspi->ref_clk),
779+
"ref clock not found.\n");
786780

787781
ret = clk_prepare_enable(xspi->pclk);
788-
if (ret) {
789-
dev_err(&pdev->dev, "Unable to enable APB clock.\n");
790-
goto remove_ctlr;
791-
}
782+
if (ret)
783+
return dev_err_probe(&pdev->dev, ret, "Unable to enable APB clock.\n");
792784

793785
ret = clk_prepare_enable(xspi->ref_clk);
794786
if (ret) {
@@ -869,8 +861,7 @@ static int ax_spi_probe(struct platform_device *pdev)
869861
clk_disable_unprepare(xspi->ref_clk);
870862
clk_dis_apb:
871863
clk_disable_unprepare(xspi->pclk);
872-
remove_ctlr:
873-
spi_controller_put(ctlr);
864+
874865
return ret;
875866
}
876867

drivers/spi/spi-geni-qcom.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -359,9 +359,9 @@ static int setup_fifo_params(struct spi_device *spi_slv,
359359
writel((spi_slv->mode & SPI_LOOP) ? LOOPBACK_ENABLE : 0, se->base + SE_SPI_LOOPBACK);
360360
if (cs_changed)
361361
writel(chipselect, se->base + SE_SPI_DEMUX_SEL);
362-
if (mode_changed & SE_SPI_CPHA)
362+
if (mode_changed & SPI_CPHA)
363363
writel((spi_slv->mode & SPI_CPHA) ? CPHA : 0, se->base + SE_SPI_CPHA);
364-
if (mode_changed & SE_SPI_CPOL)
364+
if (mode_changed & SPI_CPOL)
365365
writel((spi_slv->mode & SPI_CPOL) ? CPOL : 0, se->base + SE_SPI_CPOL);
366366
if ((mode_changed & SPI_CS_HIGH) || (cs_changed && (spi_slv->mode & SPI_CS_HIGH)))
367367
writel((spi_slv->mode & SPI_CS_HIGH) ? BIT(chipselect) : 0, se->base + SE_SPI_DEMUX_OUTPUT_INV);
@@ -906,10 +906,13 @@ static irqreturn_t geni_spi_isr(int irq, void *data)
906906
struct spi_controller *spi = data;
907907
struct spi_geni_master *mas = spi_controller_get_devdata(spi);
908908
struct geni_se *se = &mas->se;
909-
u32 m_irq;
909+
u32 m_irq, dma_tx_status, dma_rx_status;
910910

911911
m_irq = readl(se->base + SE_GENI_M_IRQ_STATUS);
912-
if (!m_irq)
912+
dma_tx_status = readl_relaxed(se->base + SE_DMA_TX_IRQ_STAT);
913+
dma_rx_status = readl_relaxed(se->base + SE_DMA_RX_IRQ_STAT);
914+
915+
if (!m_irq && !dma_tx_status && !dma_rx_status)
913916
return IRQ_NONE;
914917

915918
if (m_irq & (M_CMD_OVERRUN_EN | M_ILLEGAL_CMD_EN | M_CMD_FAILURE_EN |
@@ -957,8 +960,6 @@ static irqreturn_t geni_spi_isr(int irq, void *data)
957960
}
958961
} else if (mas->cur_xfer_mode == GENI_SE_DMA) {
959962
const struct spi_transfer *xfer = mas->cur_xfer;
960-
u32 dma_tx_status = readl_relaxed(se->base + SE_DMA_TX_IRQ_STAT);
961-
u32 dma_rx_status = readl_relaxed(se->base + SE_DMA_RX_IRQ_STAT);
962963

963964
if (dma_tx_status)
964965
writel(dma_tx_status, se->base + SE_DMA_TX_IRQ_CLR);

drivers/spi/spi.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3049,6 +3049,8 @@ static void spi_controller_release(struct device *dev)
30493049
struct spi_controller *ctlr;
30503050

30513051
ctlr = container_of(dev, struct spi_controller, dev);
3052+
3053+
free_percpu(ctlr->pcpu_statistics);
30523054
kfree(ctlr);
30533055
}
30543056

@@ -3192,6 +3194,12 @@ struct spi_controller *__spi_alloc_controller(struct device *dev,
31923194
if (!ctlr)
31933195
return NULL;
31943196

3197+
ctlr->pcpu_statistics = spi_alloc_pcpu_stats(NULL);
3198+
if (!ctlr->pcpu_statistics) {
3199+
kfree(ctlr);
3200+
return NULL;
3201+
}
3202+
31953203
device_initialize(&ctlr->dev);
31963204
INIT_LIST_HEAD(&ctlr->queue);
31973205
spin_lock_init(&ctlr->queue_lock);
@@ -3480,17 +3488,8 @@ int spi_register_controller(struct spi_controller *ctlr)
34803488
dev_info(dev, "controller is unqueued, this is deprecated\n");
34813489
} else if (ctlr->transfer_one || ctlr->transfer_one_message) {
34823490
status = spi_controller_initialize_queue(ctlr);
3483-
if (status) {
3484-
device_del(&ctlr->dev);
3485-
goto free_bus_id;
3486-
}
3487-
}
3488-
/* Add statistics */
3489-
ctlr->pcpu_statistics = spi_alloc_pcpu_stats(dev);
3490-
if (!ctlr->pcpu_statistics) {
3491-
dev_err(dev, "Error allocating per-cpu statistics\n");
3492-
status = -ENOMEM;
3493-
goto destroy_queue;
3491+
if (status)
3492+
goto del_ctrl;
34943493
}
34953494

34963495
mutex_lock(&board_lock);
@@ -3504,8 +3503,8 @@ int spi_register_controller(struct spi_controller *ctlr)
35043503
acpi_register_spi_devices(ctlr);
35053504
return status;
35063505

3507-
destroy_queue:
3508-
spi_destroy_queue(ctlr);
3506+
del_ctrl:
3507+
device_del(&ctlr->dev);
35093508
free_bus_id:
35103509
mutex_lock(&board_lock);
35113510
idr_remove(&spi_controller_idr, ctlr->bus_num);

0 commit comments

Comments
 (0)