PCI: Cleanup dev->resource + resno to use pci_resource_n()
authorIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Fri, 7 Feb 2025 16:23:01 +0000 (18:23 +0200)
committerBjorn Helgaas <bhelgaas@google.com>
Fri, 14 Feb 2025 20:39:31 +0000 (14:39 -0600)
Replace pointer arithmetic in finding the correct resource entry with the
pci_resource_n() helper.

Link: https://lore.kernel.org/r/20250207162301.2842-1-ilpo.jarvinen@linux.intel.com
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
drivers/pci/iov.c
drivers/pci/pci.c
drivers/pci/quirks.c
drivers/pci/setup-res.c

index 9e4770cdd4d5aecd88a5e75e28bc969116895fde..121540f57d4bff562effb98dab8f75e7e63e5228 100644 (file)
@@ -952,7 +952,7 @@ void pci_iov_remove(struct pci_dev *dev)
 void pci_iov_update_resource(struct pci_dev *dev, int resno)
 {
        struct pci_sriov *iov = dev->is_physfn ? dev->sriov : NULL;
-       struct resource *res = dev->resource + resno;
+       struct resource *res = pci_resource_n(dev, resno);
        int vf_bar = resno - PCI_IOV_RESOURCES;
        struct pci_bus_region region;
        u16 cmd;
index 869d204a70a372d240b1a6988a2159a79999e1ca..c4f710f782f6ab7d6ef058ed17e1a3ae872a721e 100644 (file)
@@ -1884,7 +1884,7 @@ static void pci_restore_rebar_state(struct pci_dev *pdev)
 
                pci_read_config_dword(pdev, pos + PCI_REBAR_CTRL, &ctrl);
                bar_idx = ctrl & PCI_REBAR_CTRL_BAR_IDX;
-               res = pdev->resource + bar_idx;
+               res = pci_resource_n(pdev, bar_idx);
                size = pci_rebar_bytes_to_size(resource_size(res));
                ctrl &= ~PCI_REBAR_CTRL_BAR_SIZE;
                ctrl |= FIELD_PREP(PCI_REBAR_CTRL_BAR_SIZE, size);
index b84ff7bade822979ea6f32560d07d629f48bbeda..5cc4610201b788743785596369cb0509c19dd3c7 100644 (file)
@@ -621,7 +621,7 @@ static void quirk_io(struct pci_dev *dev, int pos, unsigned int size,
 {
        u32 region;
        struct pci_bus_region bus_region;
-       struct resource *res = dev->resource + pos;
+       struct resource *res = pci_resource_n(dev, pos);
        const char *res_name = pci_resource_name(dev, pos);
 
        pci_read_config_dword(dev, PCI_BASE_ADDRESS_0 + (pos << 2), &region);
@@ -671,7 +671,7 @@ static void quirk_io_region(struct pci_dev *dev, int port,
 {
        u16 region;
        struct pci_bus_region bus_region;
-       struct resource *res = dev->resource + nr;
+       struct resource *res = pci_resource_n(dev, nr);
 
        pci_read_config_word(dev, port, &region);
        region &= ~(size - 1);
index ca14576bf2bf29735aaa6671735e03c5643780c0..ad64360071486c4c4b08a78b563af2ce876bc7c5 100644 (file)
@@ -29,7 +29,7 @@ static void pci_std_update_resource(struct pci_dev *dev, int resno)
        u16 cmd;
        u32 new, check, mask;
        int reg;
-       struct resource *res = dev->resource + resno;
+       struct resource *res = pci_resource_n(dev, resno);
        const char *res_name = pci_resource_name(dev, resno);
 
        /* Per SR-IOV spec 3.4.1.11, VF BARs are RO zero */
@@ -262,7 +262,7 @@ resource_size_t __weak pcibios_align_resource(void *data,
 static int __pci_assign_resource(struct pci_bus *bus, struct pci_dev *dev,
                int resno, resource_size_t size, resource_size_t align)
 {
-       struct resource *res = dev->resource + resno;
+       struct resource *res = pci_resource_n(dev, resno);
        resource_size_t min;
        int ret;
 
@@ -325,7 +325,7 @@ static int _pci_assign_resource(struct pci_dev *dev, int resno,
 
 int pci_assign_resource(struct pci_dev *dev, int resno)
 {
-       struct resource *res = dev->resource + resno;
+       struct resource *res = pci_resource_n(dev, resno);
        const char *res_name = pci_resource_name(dev, resno);
        resource_size_t align, size;
        int ret;
@@ -372,7 +372,7 @@ EXPORT_SYMBOL(pci_assign_resource);
 int pci_reassign_resource(struct pci_dev *dev, int resno,
                          resource_size_t addsize, resource_size_t min_align)
 {
-       struct resource *res = dev->resource + resno;
+       struct resource *res = pci_resource_n(dev, resno);
        const char *res_name = pci_resource_name(dev, resno);
        unsigned long flags;
        resource_size_t new_size;
@@ -411,7 +411,7 @@ int pci_reassign_resource(struct pci_dev *dev, int resno,
 
 void pci_release_resource(struct pci_dev *dev, int resno)
 {
-       struct resource *res = dev->resource + resno;
+       struct resource *res = pci_resource_n(dev, resno);
        const char *res_name = pci_resource_name(dev, resno);
 
        pci_info(dev, "%s %pR: releasing\n", res_name, res);
@@ -428,7 +428,7 @@ EXPORT_SYMBOL(pci_release_resource);
 
 int pci_resize_resource(struct pci_dev *dev, int resno, int size)
 {
-       struct resource *res = dev->resource + resno;
+       struct resource *res = pci_resource_n(dev, resno);
        struct pci_host_bridge *host;
        int old, ret;
        u32 sizes;