On Tue, Sep 13, 2016 at 05:11:49PM +0300, Andy Shevchenko wrote: > On Tue, 2016-09-13 at 15:19 +0300, Mika Westerberg wrote: > > Add a new helper function pci_find_resource() that can be used to find > > out > > whether a given resource (for example from a child device) is > > contained > > within given PCI device's standard resources. > > > > Signed-off-by: Mika Westerberg <mika.westerberg@xxxxxxxxxxxxxxx> > > --- > > drivers/pci/pci.c | 27 +++++++++++++++++++++++++++ > > include/linux/pci.h | 4 ++++ > > 2 files changed, 31 insertions(+) > > > > diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c > > index aab9d5115a5f..491f879f34cb 100644 > > --- a/drivers/pci/pci.c > > +++ b/drivers/pci/pci.c > > @@ -480,6 +480,33 @@ struct resource *pci_find_parent_resource(const > > struct pci_dev *dev, > > EXPORT_SYMBOL(pci_find_parent_resource); > > > > /** > > + * pci_find_resource - Return matching PCI device resource > > + * @dev: PCI device to query > > + * @res: Resource to look for > > + * > > + * Goes over standard PCI resources (BARs) and checks if the given > > resource > > + * is partially or fully contained in any of them. In that case the > > + * matching resource is returned, %NULL otherwise. > > + */ > > +struct resource *pci_find_resource(struct pci_dev *dev, struct > > resource *res) > > +{ > > + int i; > > + > > > + if (!res) > > + return NULL; > > Shouldn't it be a problem of caller to supply valid pointer? > Seems other function(s) has(ve) this assumption. No, I can drop the check. > > + > > + for (i = 0; i < PCI_ROM_RESOURCE; i++) { > > + struct resource *r = &dev->resource[i]; > > + > > + if (r->start && resource_contains(r, res)) > > + return r; > > I'm not sure what we have to return in case of > 1) r->start == 0, r->end > 0 > 2) r->start > 0, r->end == 0 > > assuming that all previous checks are positive. These are PCI BARs so if they are not populated (r->start == 0) we skip them. PCI core should have filled those already with correct values (and resource_contains() should deal with everything that does not match anyway). -- To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html