Re: [PATCH 09/15] gpio: support ROHM BD71815 GPOs

From: Vaittinen, Matti
Date: Mon Jan 11 2021 - 02:29:44 EST



On Mon, 2021-01-11 at 08:15 +0200, Matti Vaittinen wrote:
> On Sat, 2021-01-09 at 01:45 +0100, Linus Walleij wrote:
> > On Fri, Jan 8, 2021 at 2:39 PM Matti Vaittinen
> > <matti.vaittinen@xxxxxxxxxxxxxxxxx> wrote:
> >
> > > Support GPO(s) found from ROHM BD71815 power management IC. The
> > > IC
> > > has two
> > > GPO pins but only one is properly documented in data-sheet. The
> > > driver
> > > exposes by default only the documented GPO. The second GPO is
> > > connected to
> > > E5 pin and is marked as GND in data-sheet. Control for this
> > > undocumented
> > > pin can be enabled using a special DT property.
> > >
> > > This driver is derived from work by Peter Yang <
> > > yanglsh@xxxxxxxxxxxxxxx>
> > > although not so much of original is left.
> > >
> > > Signed-off-by: Matti Vaittinen <matti.vaittinen@xxxxxxxxxxxxxxxxx
> > > >

// Snip

> > > + g->chip.parent = pdev->dev.parent;
> > > + g->chip.of_node = pdev->dev.parent->of_node;
> > > + g->regmap = dev_get_regmap(pdev->dev.parent, NULL);
> > > + g->dev = &pdev->dev;
> > > +
> > > + ret = devm_gpiochip_add_data(&pdev->dev, &g->chip, g);
> > > + if (ret < 0) {
> > > + dev_err(&pdev->dev, "could not register gpiochip,
> > > %d\n", ret);
> > > + return ret;
> > > + }
> >
> > It's a bit confusing how you use pdev->dev.parent for some stuff
> > and &pdev->dev for some.
> >
> > What about assinging
> >
> > struct device *dev = pdev->dev.parent;
> >
> > and use dev for all the calls, it looks like it'd work fine.
>
> I wouldn't bind the lifetime of devm functions to the parent device.
> I
> am not sure if it would work - what happens we bind lifetime of XX to
> parent device - and next call at probe fails (for example with
> DEFERRED?) I _assume_ the XX bound to parent is not released?
> (Please,
> do correct me if I am wrong!)

/*
* Bind devm lifetime to this platform device => use dev for devm.
* also the prints should originate from this device.
*/
dev = &pdev->dev;
/* The device-tree and regmap come from MFD => use parent for that */
parent = dev->parent;

Maybe adding dev and parent variables + comments would clear it up?


Br,
Matti Vaittinen