summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorBjorn Helgaas <bhelgaas@google.com>2024-01-15 12:10:35 -0600
committerBjorn Helgaas <bhelgaas@google.com>2024-01-15 12:10:35 -0600
commit5a4af2ca48b877c8214722f338bdce702892e269 (patch)
tree6131ef3577c2fcbd39de2dd5c25773258b063790 /include
parent18c3850f313e1646a05fb016c9f6d5b7ad47e751 (diff)
parent3171e46d677a668eed3086da78671f1e4f5b8405 (diff)
downloadlwn-5a4af2ca48b877c8214722f338bdce702892e269.tar.gz
lwn-5a4af2ca48b877c8214722f338bdce702892e269.zip
Merge branch 'pci/resource'
- Restructure pci_dev_for_each_resource() to avoid computing the address of an out-of-bounds array element (the bounds check was performed later so the element was never actually *read*, but it's nicer to avoid even computing an out-of-bounds address) (Andy Shevchenko) * pci/resource: PCI: Avoid potential out-of-bounds read in pci_dev_for_each_resource()
Diffstat (limited to 'include')
-rw-r--r--include/linux/pci.h12
1 files changed, 6 insertions, 6 deletions
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 60ca768bc867..4ebecc7896ef 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -2127,14 +2127,14 @@ int pci_iobar_pfn(struct pci_dev *pdev, int bar, struct vm_area_struct *vma);
(pci_resource_end((dev), (bar)) ? \
resource_size(pci_resource_n((dev), (bar))) : 0)
-#define __pci_dev_for_each_res0(dev, res, ...) \
- for (unsigned int __b = 0; \
- res = pci_resource_n(dev, __b), __b < PCI_NUM_RESOURCES; \
+#define __pci_dev_for_each_res0(dev, res, ...) \
+ for (unsigned int __b = 0; \
+ __b < PCI_NUM_RESOURCES && (res = pci_resource_n(dev, __b)); \
__b++)
-#define __pci_dev_for_each_res1(dev, res, __b) \
- for (__b = 0; \
- res = pci_resource_n(dev, __b), __b < PCI_NUM_RESOURCES; \
+#define __pci_dev_for_each_res1(dev, res, __b) \
+ for (__b = 0; \
+ __b < PCI_NUM_RESOURCES && (res = pci_resource_n(dev, __b)); \
__b++)
#define pci_dev_for_each_resource(dev, res, ...) \