lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <D74EQQNADWDP.FQ5XFK8TB5XH@bootlin.com>
Date: Fri, 17 Jan 2025 15:11:29 +0100
From: "Mathieu Dubois-Briand" <mathieu.dubois-briand@...tlin.com>
To: Uwe Kleine-König <ukleinek@...nel.org>
Cc: "Lee Jones" <lee@...nel.org>, "Rob Herring" <robh@...nel.org>,
 "Krzysztof Kozlowski" <krzk+dt@...nel.org>, "Conor Dooley"
 <conor+dt@...nel.org>, "Kamel Bouhara" <kamel.bouhara@...tlin.com>, "Linus
 Walleij" <linus.walleij@...aro.org>, "Bartosz Golaszewski" <brgl@...ev.pl>,
 "Dmitry Torokhov" <dmitry.torokhov@...il.com>,
 <devicetree@...r.kernel.org>, <linux-kernel@...r.kernel.org>,
 <linux-gpio@...r.kernel.org>, <linux-input@...r.kernel.org>,
 <linux-pwm@...r.kernel.org>, Grégory Clement
 <gregory.clement@...tlin.com>, "Thomas Petazzoni"
 <thomas.petazzoni@...tlin.com>
Subject: Re: [PATCH v3 3/7] pwm: max7360: Add MAX7360 PWM support

On Fri Jan 17, 2025 at 10:33 AM CET, Uwe Kleine-König wrote:
> Hello Mathieu,
>
> On Mon, Jan 13, 2025 at 01:42:27PM +0100, mathieu.dubois-briand@...tlin.com wrote:
> > From: Kamel Bouhara <kamel.bouhara@...tlin.com>
...
> > +static int max7360_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
> > +			     const struct pwm_state *state)
> > +{
> > +	struct max7360_pwm *max7360_pwm;
> > +	u64 duty_steps;
> > +	int ret;
> > +
> > +	if (state->polarity != PWM_POLARITY_NORMAL)
> > +		return -EINVAL;
> > +
> > +	if (state->period != MAX7360_PWM_PERIOD_NS) {
> > +		dev_warn(&chip->dev,
> > +			 "unsupported pwm period: %llu, should be %u\n",
> > +			 state->period, MAX7360_PWM_PERIOD_NS);
> > +		return -EINVAL;
>
> Please don't emit error messages in .apply(). Also a driver is supposed
> to round down .period, so any value >= MAX7360_PWM_PERIOD_NS should be
> accepted.
>
> Also note that you might want to implement the waveform callbacks
> instead of .apply() and .get_state() for the more modern abstraction
> (with slightly different rounding rules).
>

Sure, I just switched to the waveform callbacks, it was quite
straightforward.

> > +static int max7360_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
> > +				 struct pwm_state *state)
> > +{
...
> > +	state->duty_cycle = mul_u64_u64_div_u64(val, MAX7360_PWM_PERIOD_NS,
> > +						MAX7360_PWM_MAX_RES);
>
> You have to round up here. I would expect that the checks in the core
> (with PWM_DEBUG=1) help you catching this type of error. In your case
> changing the configuration to
>
> 	.period = 2000000,
> 	.duty_cycle = 234379,
>
> should yield some hint in the kernel log.
>

Thanks for the reproduce steps: I saw the bug and fixed it. Also
MAX7360_PWM_MAX_RES had to be set to 255 and not 256...

> > +	return 0;
> > +}
>
> Best regards
> Uwe

I also fixed all other points mentioned in your mail. Thanks again for your review.

-- 
Mathieu Dubois-Briand, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ