Skip to content

Commit c45c1e8

Browse files
tachicialexbroonie
authored andcommitted
spi: spi-bcm2835: Fix deadlock
The bcm2835_spi_transfer_one function can create a deadlock if it is called while another thread already has the CCF lock. Signed-off-by: Alexandru Tachici <alexandru.tachici@analog.com> Fixes: f804387 ("spi: add driver for BCM2835") Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Link: https://lore.kernel.org/r/20210716210245.13240-2-alexandru.tachici@analog.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 56912da commit c45c1e8

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

drivers/spi/spi-bcm2835.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ MODULE_PARM_DESC(polling_limit_us,
8383
* struct bcm2835_spi - BCM2835 SPI controller
8484
* @regs: base address of register map
8585
* @clk: core clock, divided to calculate serial clock
86+
* @clk_hz: core clock cached speed
8687
* @irq: interrupt, signals TX FIFO empty or RX FIFO ¾ full
8788
* @tfr: SPI transfer currently processed
8889
* @ctlr: SPI controller reverse lookup
@@ -116,6 +117,7 @@ MODULE_PARM_DESC(polling_limit_us,
116117
struct bcm2835_spi {
117118
void __iomem *regs;
118119
struct clk *clk;
120+
unsigned long clk_hz;
119121
int irq;
120122
struct spi_transfer *tfr;
121123
struct spi_controller *ctlr;
@@ -1045,27 +1047,26 @@ static int bcm2835_spi_transfer_one(struct spi_controller *ctlr,
10451047
{
10461048
struct bcm2835_spi *bs = spi_controller_get_devdata(ctlr);
10471049
struct bcm2835_spidev *slv = spi_get_ctldata(spi);
1048-
unsigned long spi_hz, clk_hz, cdiv;
1050+
unsigned long spi_hz, cdiv;
10491051
unsigned long hz_per_byte, byte_limit;
10501052
u32 cs = slv->prepare_cs;
10511053

10521054
/* set clock */
10531055
spi_hz = tfr->speed_hz;
1054-
clk_hz = clk_get_rate(bs->clk);
10551056

1056-
if (spi_hz >= clk_hz / 2) {
1057+
if (spi_hz >= bs->clk_hz / 2) {
10571058
cdiv = 2; /* clk_hz/2 is the fastest we can go */
10581059
} else if (spi_hz) {
10591060
/* CDIV must be a multiple of two */
1060-
cdiv = DIV_ROUND_UP(clk_hz, spi_hz);
1061+
cdiv = DIV_ROUND_UP(bs->clk_hz, spi_hz);
10611062
cdiv += (cdiv % 2);
10621063

10631064
if (cdiv >= 65536)
10641065
cdiv = 0; /* 0 is the slowest we can go */
10651066
} else {
10661067
cdiv = 0; /* 0 is the slowest we can go */
10671068
}
1068-
tfr->effective_speed_hz = cdiv ? (clk_hz / cdiv) : (clk_hz / 65536);
1069+
tfr->effective_speed_hz = cdiv ? (bs->clk_hz / cdiv) : (bs->clk_hz / 65536);
10691070
bcm2835_wr(bs, BCM2835_SPI_CLK, cdiv);
10701071

10711072
/* handle all the 3-wire mode */
@@ -1354,6 +1355,7 @@ static int bcm2835_spi_probe(struct platform_device *pdev)
13541355
return bs->irq ? bs->irq : -ENODEV;
13551356

13561357
clk_prepare_enable(bs->clk);
1358+
bs->clk_hz = clk_get_rate(bs->clk);
13571359

13581360
err = bcm2835_dma_init(ctlr, &pdev->dev, bs);
13591361
if (err)

0 commit comments

Comments
 (0)