From: Thierry Reding <thierry.reding@gmail.com>
To: Peter Rosin <peda@axentia.se>
Cc: LKML <linux-kernel@vger.kernel.org>,
"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
linux-pwm@vger.kernel.org,
"Thorsten Leemhuis" <regressions@leemhuis.info>,
"Conor Dooley" <conor.dooley@microchip.com>,
"Claudiu Beznea" <claudiu.beznea@microchip.com>
Subject: Re: PWM regression causing failures with the pwm-atmel driver
Date: Mon, 22 May 2023 18:25:23 +0200 [thread overview]
Message-ID: <ZGuXc13mRhqDAVu_@orome> (raw)
In-Reply-To: <7e2cfb55-e39f-2e5c-7f43-e1d275428bb5@axentia.se>
[-- Attachment #1: Type: text/plain, Size: 2262 bytes --]
On Mon, May 22, 2023 at 05:19:43PM +0200, Peter Rosin wrote:
> Hi!
>
> I have a device with a "sound card" that has an amplifier that needs
> an extra boost when high amplification is requested. This extra
> boost is controlled with a pwm-regulator.
>
> As of commit c73a3107624d ("pwm: Handle .get_state() failures") this
> device no longer works. I have tracked the problem to an unfortunate
> interaction between the underlying PWM driver and the PWM core.
>
> The driver is drivers/pwm/pwm-atmel.c which has difficulties getting
> the period and/or duty_cycle from the HW when the PWM is not enabled.
> Because of this, I think, the driver does not fill in .period and
> .duty_cycle at all in atmel_pwm_get_state() unless the PWM is enabled.
>
> However, the PWM core is not expecting these fields to be left as-is,
> at least not in pwm_adjust_config(), and its local state variable on
> the stack ends up with whatever crap was on the stack on entry for
> these fields. That fails spectacularly when the function continues to
> do math on these uninitialized values.
>
> In particular, I find this in the kernel log when a bad kernel runs:
> pwm-regulator: probe of reg-ana failed with error -22
>
> Before commit c73a3107624d this was a silent failure, and the situation
> "repaired itself" when the PWM was later reprogrammed, at least for my
> case. After that commit, the failure is fatal and the "sound card"
> fails to come up at all.
>
>
> I see a couple of adjustments that could be made.
>
> 1. Zero out some fields in the driver:
>
> @@ -390,4 +390,6 @@ static int atmel_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm,
> state->enabled = true;
> } else {
> + state->period = 0;
> + state->duty_cycle = 0;
> state->enabled = false;
> }
I prefer this version. Drivers are supposed to set the state as
accurately as they can. If they can't say anything about the hardware
state because it's in an undetermined state, clearing out all the state
fields seems like the best option.
We could probably do this within the core to avoid any such bugs, but it
doesn't really hurt for drivers to be explicit either. Maybe Uwe has
additional thoughts on this.
Thierry
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2023-05-22 16:25 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-22 15:19 PWM regression causing failures with the pwm-atmel driver Peter Rosin
2023-05-22 16:25 ` Thierry Reding [this message]
2023-05-22 17:23 ` Uwe Kleine-König
2023-05-22 19:28 ` Peter Rosin
2023-05-22 20:43 ` Uwe Kleine-König
2023-05-22 23:34 ` Peter Rosin
2023-05-23 20:31 ` Thierry Reding
2023-05-24 6:37 ` Uwe Kleine-König
2023-06-20 14:24 ` Thorsten Leemhuis
2023-06-20 15:43 ` Peter Rosin
2023-06-20 16:30 ` Linux regression tracking #update (Thorsten Leemhuis)
-- strict thread matches above, loose matches on Subject: below --
2023-05-23 20:42 Peter Rosin
2023-05-24 6:07 ` Uwe Kleine-König
2023-05-24 7:45 Peter Rosin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZGuXc13mRhqDAVu_@orome \
--to=thierry.reding@gmail.com \
--cc=claudiu.beznea@microchip.com \
--cc=conor.dooley@microchip.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=peda@axentia.se \
--cc=regressions@leemhuis.info \
--cc=u.kleine-koenig@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox