Re: [PATCH v7 1/4] resource: Move reparent_resources() to kernel/resource.c and make it public
From: Andy Shevchenko <hidden>
Date: 2018-07-18 16:36:17
Also in:
linux-devicetree, linuxppc-dev, nvdimm
On Wed, Jul 18, 2018 at 5:49 AM, Baoquan He [off-list ref] wrote:
reparent_resources() is duplicated in arch/microblaze/pci/pci-common.c and arch/powerpc/kernel/pci-common.c, so move it to kernel/resource.c so that it's shared.
Some minor stuff.
+/** + * reparent_resources - reparent resource children of parent that res covers + * @parent: parent resource descriptor + * @res: resource descriptor desired by caller + * + * Returns 0 on success, -ENOTSUPP if child resource is not completely + * contained by 'res', -ECANCELED if no any conflicting entry found.
'res' -> @res
+ * + * Reparent resource children of 'parent' that conflict with 'res'
Ditto + 'parent' -> @parent
+ * under 'res', and make 'res' replace those children.
Ditto.
+ */
+int reparent_resources(struct resource *parent, struct resource *res)
+{
+ struct resource *p, **pp;
+ struct resource **firstpp = NULL;
+
+ for (pp = &parent->child; (p = *pp) != NULL; pp = &p->sibling) {
+ if (p->end < res->start)
+ continue;
+ if (res->end < p->start)
+ break;
+ if (p->start < res->start || p->end > res->end)
+ return -ENOTSUPP; /* not completely contained */
+ if (firstpp == NULL)
+ firstpp = pp;
+ }
+ if (firstpp == NULL)
+ return -ECANCELED; /* didn't find any conflicting entries? */
+ res->parent = parent;
+ res->child = *firstpp;
+ res->sibling = *pp;
+ *firstpp = res;
+ *pp = NULL;
+ for (p = res->child; p != NULL; p = p->sibling) {
+ p->parent = res;+ pr_debug("PCI: Reparented %s %pR under %s\n",
+ p->name, p, res->name);Now, PCI is a bit confusing here.
+ }
+ return 0;
+}
+EXPORT_SYMBOL(reparent_resources);
+
static void __init __reserve_region_with_split(struct resource *root,
resource_size_t start, resource_size_t end,
const char *name)
--
2.13.6-- With Best Regards, Andy Shevchenko