[PATCH v1] LoongArch: pci: add NULL check for map_bus return value in loongson_gpu_fixup_dma_hang
From: Xuewen Wang
Date: Mon Jul 20 2026 - 23:01:26 EST
The map_bus() callback can return NULL when the target device does not
exist (e.g. non-existent device hidden by FLAG_DEV_HIDDEN, or device > 0
on internal bridges). All other callers in the kernel check the return
value, but loongson_gpu_fixup_dma_hang() uses it directly, leading to a
null pointer dereference via readw(base + PCI_DEVICE_ID).
Add the missing NULL check to prevent the crash.
Fixes: 95db0c9f526d ("LoongArch: Workaround LS2K/LS7A GPU DMA hang bug")
Signed-off-by: Xuewen Wang <wangxuewen@xxxxxxxxxx>
---
arch/loongarch/pci/pci.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/arch/loongarch/pci/pci.c b/arch/loongarch/pci/pci.c
index f33c7ea1443d..3cd89b0224e3 100644
--- a/arch/loongarch/pci/pci.c
+++ b/arch/loongarch/pci/pci.c
@@ -115,6 +115,11 @@ static void loongson_gpu_fixup_dma_hang(struct pci_dev *pdev, bool on)
static u32 crtc_status[CRTC_NUM_MAX] = { 0 };
base = pdev->bus->ops->map_bus(pdev->bus, pdev->devfn + 1, 0);
+ if (!base) {
+ pci_dbg(pdev, "cannot map config space for devfn %02x.%d\n",
+ PCI_SLOT(pdev->devfn + 1), PCI_FUNC(pdev->devfn + 1));
+ return;
+ }
device = readw(base + PCI_DEVICE_ID);
regbase = ioremap(readq(base + PCI_BASE_ADDRESS_0) & ~0xffull, SZ_64K);
--
2.25.1