Re: [PATCH v5 04/11] pwm: max7360: Add MAX7360 PWM support

Andy Shevchenko
2025-03-25T15:41:30Z

On Tue, Mar 25, 2025 at 03:29:18PM +0100, Mathieu Dubois-Briand wrote:
> On Wed Mar 19, 2025 at 12:18 PM CET, Andy Shevchenko wrote:
> > On Tue, Mar 18, 2025 at 05:26:20PM +0100, mathieu.dubois-briand@bootlin.com wrote:

...

> > > +static int max7360_pwm_round_waveform_tohw(struct pwm_chip *chip,
> > > + struct pwm_device *pwm,
> > > + const struct pwm_waveform *wf,
> > > + void *_wfhw)
> >
> > I would expect other way around, i.e. naming with leading underscore(s) to be
> > private / local. Ditto for all similar cases.
>
> I get the point, but the 2 existing drivers based on pwm_ops structure
> name it that way: drivers/pwm/pwm-axi-pwmgen.c and
> drivers/pwm/pwm-stm32.c.
>
> Also, the parameter is mostly unusable as-is, as it is a void*, so I
> believe it also makes sense to have no underscore for the correctly
> casted one, that we will be using in the function body (wfhw).

It's all up to PWM maintainers, but I find this style a bit weird, sorry.
I only saw this in the macros, where it's kinda okay. In functions it's
something that needs an additional thinking and understanding the semantics
of the underscore.

...

> > > +static int max7360_pwm_probe(struct platform_device *pdev)
> > > +{
> > > + struct device *dev = &pdev->dev;
> > > + struct pwm_chip *chip;
> > > + struct regmap *regmap;
> > > + int ret;
> > > +
> > > + if (!dev->parent)
> > > + return dev_err_probe(dev, -ENODEV, "no parent device\n");
> >
> > Why? Code most likely will fail on the regmap retrieval. Just do that first.
> >
> > > + chip = devm_pwmchip_alloc(dev->parent, MAX7360_NUM_PWMS, 0);
> >
> > This is quite worrying. The devm_ to parent makes a lot of assumptions that may
> > not be realised. If you really need this, it has to have a very good comment
> > explaining why and object lifetimes.
>
> Thanks, I'm fixing this in this driver and similar code in keypad,
> rotary and pinctrl. More details in the child mail.

Sure, thanks!

--
With Best Regards,
Andy Shevchenko