Re: [PATCH 1/2] libnvdimm/of_pmem: handle memory-region in DT

From: Oliver O'Halloran
Date: Sun Feb 23 2020 - 20:42:04 EST


On Mon, Feb 24, 2020 at 1:56 AM Ira Weiny <ira.weiny@xxxxxxxxx> wrote:
>
> On Sat, Feb 22, 2020 at 10:30:09AM -0800, Alistair Delva wrote:
> > From: Kenny Root <kroot@xxxxxxxxxx>
> >
> > Add support for parsing the 'memory-region' DT property in addition to
> > the 'reg' DT property. This enables use cases where the pmem region is
> > not in I/O address space or dedicated memory (e.g. a bootloader
> > carveout).
> >
> > Signed-off-by: Kenny Root <kroot@xxxxxxxxxx>
> > Signed-off-by: Alistair Delva <adelva@xxxxxxxxxx>
> > Cc: "Oliver O'Halloran" <oohall@xxxxxxxxx>
> > Cc: Rob Herring <robh+dt@xxxxxxxxxx>
> > Cc: Dan Williams <dan.j.williams@xxxxxxxxx>
> > Cc: Vishal Verma <vishal.l.verma@xxxxxxxxx>
> > Cc: Dave Jiang <dave.jiang@xxxxxxxxx>
> > Cc: Ira Weiny <ira.weiny@xxxxxxxxx>
> > Cc: devicetree@xxxxxxxxxxxxxxx
> > Cc: linux-nvdimm@xxxxxxxxxxxx
> > Cc: kernel-team@xxxxxxxxxxx
> > ---
> > drivers/nvdimm/of_pmem.c | 75 ++++++++++++++++++++++++++--------------
> > 1 file changed, 50 insertions(+), 25 deletions(-)
> >
> > diff --git a/drivers/nvdimm/of_pmem.c b/drivers/nvdimm/of_pmem.c
> > index 8224d1431ea9..a68e44fb0041 100644
> > --- a/drivers/nvdimm/of_pmem.c
> > +++ b/drivers/nvdimm/of_pmem.c
> > @@ -14,13 +14,47 @@ struct of_pmem_private {
> > struct nvdimm_bus *bus;
> > };
> >
> > +static void of_pmem_register_region(struct platform_device *pdev,
> > + struct nvdimm_bus *bus,
> > + struct device_node *np,
> > + struct resource *res, bool is_volatile)
>
> FWIW it would be easier to review if this was splut into a patch which created
> the helper of_pmem_register_region() without the new logic. Then added the new
> logic here.

Yeah, that wouldn't hurt.

*snip*

> > + i = 0;
> > + while ((mr_np = of_parse_phandle(np, "memory-region", i++))) {
> > + ret = of_address_to_resource(mr_np, 0, &res);
> > + if (ret)
> > + dev_warn(
> > + &pdev->dev,
> > + "Unable to acquire memory-region from %pOF: %d\n",
> > + mr_np, ret);
> > else
> > - dev_dbg(&pdev->dev, "Registered region %pR from %pOF\n",
> > - ndr_desc.res, np);
> > + of_pmem_register_region(pdev, bus, np, &res,
> > + is_volatile);
> > + of_node_put(mr_np);
>
> Why of_node_put()?

"memory-region" is an array of pointers to nodes in /reserved-memory/
which describe the actual memory region. of_parse_phandle() elevates
the refcount of the returned node and we need to balance that.

>
> Ira
> > }
> >
> > return 0;
> > --
> > 2.25.0.265.gbab2e86ba0-goog
> >