Skip to content

Commit

Permalink
PCI: Cleanup dev->resource + resno to use pci_resource_n()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Ilpo Järvinen authored and Bjorn Helgaas committed Feb 14, 2025
1 parent 2014c95 commit addb30c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion drivers/pci/iov.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion drivers/pci/pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions drivers/pci/quirks.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 6 additions & 6 deletions drivers/pci/setup-res.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit addb30c

Please sign in to comment.