Skip to content

Commit 7fbcb5d

Browse files
repkLorenzo Pieralisi
authored andcommitted
PCI: aardvark: Don't rely on jiffies while holding spinlock
advk_pcie_wait_pio() can be called while holding a spinlock (from pci_bus_read_config_dword()), then depends on jiffies in order to timeout while polling on PIO state registers. In the case the PIO transaction failed, the timeout will never happen and will also cause the cpu to stall. This decrements a variable and wait instead of using jiffies. Signed-off-by: Remi Pommarel <[email protected]> Signed-off-by: Lorenzo Pieralisi <[email protected]> Reviewed-by: Andrew Murray <[email protected]> Acked-by: Thomas Petazzoni <[email protected]>
1 parent c0f05a6 commit 7fbcb5d

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

drivers/pci/controller/pci-aardvark.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@
175175
(PCIE_CONF_BUS(bus) | PCIE_CONF_DEV(PCI_SLOT(devfn)) | \
176176
PCIE_CONF_FUNC(PCI_FUNC(devfn)) | PCIE_CONF_REG(where))
177177

178-
#define PIO_TIMEOUT_MS 1
178+
#define PIO_RETRY_CNT 500
179+
#define PIO_RETRY_DELAY 2 /* 2 us*/
179180

180181
#define LINK_WAIT_MAX_RETRIES 10
181182
#define LINK_WAIT_USLEEP_MIN 90000
@@ -404,17 +405,16 @@ static void advk_pcie_check_pio_status(struct advk_pcie *pcie)
404405
static int advk_pcie_wait_pio(struct advk_pcie *pcie)
405406
{
406407
struct device *dev = &pcie->pdev->dev;
407-
unsigned long timeout;
408+
int i;
408409

409-
timeout = jiffies + msecs_to_jiffies(PIO_TIMEOUT_MS);
410-
411-
while (time_before(jiffies, timeout)) {
410+
for (i = 0; i < PIO_RETRY_CNT; i++) {
412411
u32 start, isr;
413412

414413
start = advk_readl(pcie, PIO_START);
415414
isr = advk_readl(pcie, PIO_ISR);
416415
if (!start && isr)
417416
return 0;
417+
udelay(PIO_RETRY_DELAY);
418418
}
419419

420420
dev_err(dev, "config read/write timed out\n");

0 commit comments

Comments
 (0)