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

Mathieu Dubois-Briand
2025-03-25T14:29:21Z

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:
> > From: Kamel Bouhara <kamel.bouhara@bootlin.com>
> >
> > Add driver for Maxim Integrated MAX7360 PWM controller, supporting up to
> > 8 independent PWM outputs.
>
> ...
>
>
> > +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).

>
> ...
>
> > +static int max7360_pwm_read_waveform(struct pwm_chip *chip,
> > + struct pwm_device *pwm,
> > + void *_wfhw)
> > +{
> > + struct max7360_pwm_waveform *wfhw = _wfhw;
> > + struct regmap *regmap;
> > + unsigned int val;
> > + int ret;
> > +
> > + regmap = pwmchip_get_drvdata(chip);
> > +
> > + ret = regmap_read(regmap, MAX7360_REG_GPIOCTRL, &val);
> > + if (ret)
> > + return ret;
> > +
> > + if (val & BIT(pwm->hwpwm)) {
> > + wfhw->enabled = true;
>
> Also can be (but up to you)
>
> wfhw->enabled = val & BIT(pwm->hwpwm);
> if (wfhw->enabled) {
>
> And also see below. Perhaps it is not a good suggestion after all.
>
> > + ret = regmap_read(regmap, MAX7360_REG_PWM(pwm->hwpwm), &val);
> > + wfhw->duty_steps = val;
>
> Set to a garbage in case of error, why?
>

Ok, I'm fixing the whole block of code.

> > + } else {
> > + wfhw->enabled = false;
> > + wfhw->duty_steps = 0;
> > + }
> > +
> > + return ret;
> > +}
>
> ...
>
> > +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.

Thanks for your review!
Mathieu

--
Mathieu Dubois-Briand, Bootlin
Embedded Linux and Kernel engineering