From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
"Munehisa Kamata" <kamatam@amazon.com>,
"Thierry Reding" <thierry.reding@gmail.com>,
"Sasha Levin" <sashal@kernel.org>,
linux-pwm@vger.kernel.org
Subject: [PATCH AUTOSEL 6.2 08/17] pwm: Zero-initialize the pwm_state passed to driver's .get_state()
Date: Thu, 20 Apr 2023 07:01:37 -0400 [thread overview]
Message-ID: <20230420110148.505779-8-sashal@kernel.org> (raw)
In-Reply-To: <20230420110148.505779-1-sashal@kernel.org>
From: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
[ Upstream commit 1271a7b98e7989ba6bb978e14403fc84efe16e13 ]
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>
Link: https://lore.kernel.org/r/20230310214004.2619480-1-u.kleine-koenig@pengutronix.de
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/pwm/core.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index e01147f66e15a..474725714a05b 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);
@@ -448,7 +455,7 @@ static void pwm_apply_state_debug(struct pwm_device *pwm,
{
struct pwm_state *last = &pwm->last;
struct pwm_chip *chip = pwm->chip;
- struct pwm_state s1, s2;
+ struct pwm_state s1 = { 0 }, s2 = { 0 };
int err;
if (!IS_ENABLED(CONFIG_PWM_DEBUG))
@@ -530,6 +537,7 @@ static void pwm_apply_state_debug(struct pwm_device *pwm,
return;
}
+ *last = (struct pwm_state){ 0 };
err = chip->ops->get_state(chip, pwm, last);
trace_pwm_get(pwm, last, err);
if (err)
--
2.39.2
next prev parent reply other threads:[~2023-04-20 11:05 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-20 11:01 [PATCH AUTOSEL 6.2 01/17] ASOC: Intel: sof_sdw: add quirk for Intel 'Rooks County' NUC M15 Sasha Levin
2023-04-20 11:01 ` [PATCH AUTOSEL 6.2 02/17] ASoC: Intel: soc-acpi: add table " Sasha Levin
2023-04-20 11:01 ` [PATCH AUTOSEL 6.2 03/17] ASoC: soc-pcm: fix hw->formats cleared by soc_pcm_hw_init() for dpcm Sasha Levin
2023-04-20 11:01 ` [PATCH AUTOSEL 6.2 04/17] x86/hyperv: Block root partition functionality in a Confidential VM Sasha Levin
2023-04-20 11:01 ` [PATCH AUTOSEL 6.2 05/17] ASoC: amd: yc: Add DMI entries to support Victus by HP Laptop 16-e1xxx (8A22) Sasha Levin
2023-04-20 11:01 ` [PATCH AUTOSEL 6.2 06/17] iio: adc: palmas_gpadc: fix NULL dereference on rmmod Sasha Levin
2023-04-20 11:01 ` [PATCH AUTOSEL 6.2 07/17] ASoC: Intel: bytcr_rt5640: Add quirk for the Acer Iconia One 7 B1-750 Sasha Levin
2023-04-20 11:01 ` Sasha Levin [this message]
2023-04-20 11:01 ` [PATCH AUTOSEL 6.2 09/17] ASoC: da7213.c: add missing pm_runtime_disable() Sasha Levin
2023-04-20 11:01 ` [PATCH AUTOSEL 6.2 10/17] net: wwan: t7xx: do not compile with -Werror Sasha Levin
2023-04-20 11:01 ` [PATCH AUTOSEL 6.2 11/17] wifi: mt76: mt7921: Fix use-after-free in fw features query Sasha Levin
2023-04-20 11:01 ` [PATCH AUTOSEL 6.2 12/17] selftests mount: Fix mount_setattr_test builds failed Sasha Levin
2023-04-20 11:01 ` [PATCH AUTOSEL 6.2 13/17] scsi: mpi3mr: Handle soft reset in progress fault code (0xF002) Sasha Levin
2023-04-20 11:01 ` [PATCH AUTOSEL 6.2 14/17] net: sfp: add quirk enabling 2500Base-x for HG MXPD-483II Sasha Levin
2023-04-20 11:01 ` [PATCH AUTOSEL 6.2 15/17] platform/x86: thinkpad_acpi: Add missing T14s Gen1 type to s2idle quirk list Sasha Levin
2023-04-20 11:01 ` [PATCH AUTOSEL 6.2 16/17] wifi: ath11k: reduce the MHI timeout to 20s Sasha Levin
2023-04-20 11:01 ` [PATCH AUTOSEL 6.2 17/17] x86/cpu: Add model number for Intel Arrow Lake processor Sasha Levin
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=20230420110148.505779-8-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=kamatam@amazon.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=stable@vger.kernel.org \
--cc=thierry.reding@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;
as well as URLs for NNTP newsgroup(s).