From: Munehisa Kamata <kamatam@amazon.com>
To: <u.kleine-koenig@pengutronix.de>
Cc: <kamatam@amazon.com>, <kernel@pengutronix.de>,
<linux-kernel@vger.kernel.org>, <linux-pwm@vger.kernel.org>,
<stable@vger.kernel.org>, <thierry.reding@gmail.com>,
<tobetter@gmail.com>
Subject: Re: [PATCH] pwm: Zero-initialize the pwm_state passed to driver's .get_state()
Date: Tue, 28 Feb 2023 11:43:27 -0800 [thread overview]
Message-ID: <20230228194327.1237008-1-kamatam@amazon.com> (raw)
In-Reply-To: <20230228101558.b4dosk54jojfqkgi@pengutronix.de>
On Tue, 2023-02-28 10:15:58 +0000, Uwe Kleine-König wrote:
>
> This is just to ensure that .usage_power is properly initialized and
> doesn't contain random stack data. The other members of struct pwm_state
> should get a value assigned in a successful call to .get_state(). So in
> the absence of bugs in driver implementations, this is only a safe-guard
> and no fix.
>
> Reported-by: Munehisa Kamata <kamatam@amazon.com>
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
> drivers/pwm/core.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> Hello,
>
> On Sat, Feb 25, 2023 at 05:37:21PM -0800, Munehisa Kamata wrote:
> > Zero-initialize the on-stack structure to avoid unexpected behaviors. Some
> > drivers may not set or initialize all the values in pwm_state through their
> > .get_state() callback and therefore some random values may remain there and
> > be set into pwm->state eventually.
> >
> > This actually caused regression on ODROID-N2+ as reported in [1]; kernel
> > fails to boot due to random panic or hang-up.
> >
> > [1] https://forum.odroid.com/viewtopic.php?f=177&t=46360
> >
> > Fixes: c73a3107624d ("pwm: Handle .get_state() failures")
> > Cc: stable@vger.kernel.org # 6.2
> > Signed-off-by: Munehisa Kamata <kamatam@amazon.com>
>
> My patch is essentially the same as Munehisa's, just written a bit
> differently (to maybe make it easier for the compiler to optimize it?)
> and with an explaining comment. The actual motivation is different so
> the commit log is considerably different, too.
>
> I was unsure how to honor Munehisa's effort, I went with a
> "Reported-by". Please tell me if you want this to be different.
I'm okay with that, thank you.
Perhaps, you should also add Cc tag for the stable tree? I did that in my
patch and we're actually CCing to the stable list, but I'm not sure if it
can pick up your patch without the tag. This should be fixed in linux-6.2.y.
Regards,
Munehisa
> Best regards
> Uwe
>
> diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
> index e01147f66e15..533ef5bd3add 100644
> --- a/drivers/pwm/core.c
> +++ b/drivers/pwm/core.c
> @@ -115,7 +115,14 @@ static int pwm_device_request(struct pwm_device *pwm, const char *label)
> }
>
> if (pwm->chip->ops->get_state) {
> - struct pwm_state state;
> + /*
> + * Zero-initialize state because most drivers are unaware of
> + * .usage_power. The other members of state are supposed to be
> + * set by lowlevel drivers. We still initialize the whole
> + * structure for simplicity even though this might paper over
> + * faulty implementations of .get_state().
> + */
> + struct pwm_state state = { 0, };
>
> err = pwm->chip->ops->get_state(pwm->chip, pwm, &state);
> trace_pwm_get(pwm, &state, err);
> --
> 2.39.1
>
>
> --
> Pengutronix e.K. | Uwe Kleine-König |
> Industrial Linux Solutions | https://www.pengutronix.de/ |
>
next prev parent reply other threads:[~2023-02-28 19:45 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-26 1:37 [PATCH] pwm: core: Zero-initialize the temp state Munehisa Kamata
2023-02-26 9:17 ` Uwe Kleine-König
2023-02-27 2:48 ` Munehisa Kamata
2023-02-27 9:16 ` Uwe Kleine-König
2023-02-28 8:53 ` Munehisa Kamata
2023-02-28 9:39 ` Uwe Kleine-König
2023-02-28 10:15 ` [PATCH] pwm: Zero-initialize the pwm_state passed to driver's .get_state() Uwe Kleine-König
2023-02-28 19:43 ` Munehisa Kamata [this message]
2023-02-28 21:48 ` Uwe Kleine-König
2023-03-10 19:15 ` Uwe Kleine-König
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=20230228194327.1237008-1-kamatam@amazon.com \
--to=kamatam@amazon.com \
--cc=kernel@pengutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=thierry.reding@gmail.com \
--cc=tobetter@gmail.com \
--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