From: Lee Jones <lee@kernel.org>
To: lee@kernel.org, Aaro Koskinen <aaro.koskinen@iki.fi>,
Andreas Kemnade <andreas@kemnade.info>,
Kevin Hilman <khilman@baylibre.com>,
Roger Quadros <rogerq@kernel.org>,
Tony Lindgren <tony@atomide.com>,
Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>,
Graeme Gregory <gg@slimlogic.co.uk>,
Eduardo Candelaria <jedu@slimlogic.co.uk>,
Markus Schneider-Pargmann <msp@baylibre.com>,
linux-omap@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Subject: [PATCH 4/8] regulator: tps65910: Fix OOB read and bit shift in external sleep config
Date: Fri, 27 Nov 2026 18:35:44 +0000 [thread overview]
Message-ID: <20261127183624.3341010-5-lee@kernel.org> (raw)
In-Reply-To: <20261127183624.3341010-1-lee@kernel.org>
tps65910_regs contains 14 regulators including VBB at index 13, whereas
tps65910_ext_sleep_control has only 13 elements. Both tps65910_probe()
and tps65910_shutdown() iterate up to pmic->num_regulators and index
pmic->ext_sleep_control[id] out of bounds for VBB.
In addition, unsupported rails such as VRTC use 0, which collides with
VMMC and LDO6 (offset 0, bit 0), and computing
(1 << pmic->ext_sleep_control[id] & 0xFF) shifts by more than 31 bits
whenever regs_offs is non-zero because << binds tighter than &.
Introduce EXT_CONTROL_REG_NONE as a distinct sentinel for rails without
external sleep control (VRTC and VBB), add BUILD_BUG_ON() array-size
checks, return early in tps65910_set_ext_sleep_config() for unsupported
rails, and use BIT(pmic->ext_sleep_control[id] & 0xFF) for bit_pos.
Fixes: 03746dcbde75 ("regulator: tps65910: Add backup battery regulator")
Closes: https://sashiko.dev/#/bug/linux-ed3bcc60-149e-497b-93aa-50138953c49a
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/regulator/tps65910-regulator.c | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/drivers/regulator/tps65910-regulator.c b/drivers/regulator/tps65910-regulator.c
index b99923773701..d42ffc237bf4 100644
--- a/drivers/regulator/tps65910-regulator.c
+++ b/drivers/regulator/tps65910-regulator.c
@@ -271,9 +271,10 @@ static struct tps_info tps65911_regs[] = {
},
};
+#define EXT_CONTROL_REG_NONE (~0U)
#define EXT_CONTROL_REG_BITS(id, regs_offs, bits) (((regs_offs) << 8) | (bits))
static unsigned int tps65910_ext_sleep_control[] = {
- 0,
+ EXT_CONTROL_REG_NONE,
EXT_CONTROL_REG_BITS(VIO, 1, 0),
EXT_CONTROL_REG_BITS(VDD1, 1, 1),
EXT_CONTROL_REG_BITS(VDD2, 1, 2),
@@ -286,10 +287,11 @@ static unsigned int tps65910_ext_sleep_control[] = {
EXT_CONTROL_REG_BITS(VAUX2, 0, 4),
EXT_CONTROL_REG_BITS(VAUX33, 0, 5),
EXT_CONTROL_REG_BITS(VMMC, 0, 0),
+ EXT_CONTROL_REG_NONE,
};
static unsigned int tps65911_ext_sleep_control[] = {
- 0,
+ EXT_CONTROL_REG_NONE,
EXT_CONTROL_REG_BITS(VIO, 1, 0),
EXT_CONTROL_REG_BITS(VDD1, 1, 1),
EXT_CONTROL_REG_BITS(VDD2, 1, 2),
@@ -822,10 +824,16 @@ static int tps65910_set_ext_sleep_config(struct tps65910_reg *pmic,
int id, int ext_sleep_config)
{
struct tps65910 *mfd = pmic->mfd;
- u8 regoffs = (pmic->ext_sleep_control[id] >> 8) & 0xFF;
- u8 bit_pos = (1 << pmic->ext_sleep_control[id] & 0xFF);
+ u8 regoffs;
+ u8 bit_pos;
int ret;
+ if (pmic->ext_sleep_control[id] == EXT_CONTROL_REG_NONE)
+ return 0;
+
+ regoffs = (pmic->ext_sleep_control[id] >> 8) & 0xFF;
+ bit_pos = BIT(pmic->ext_sleep_control[id] & 0xFF);
+
/*
* Regulator can not be control from multiple external input EN1, EN2
* and EN3 together.
@@ -1104,6 +1112,8 @@ static int tps65910_probe(struct platform_device *pdev)
switch (tps65910_chip_id(tps65910)) {
case TPS65910:
BUILD_BUG_ON(TPS65910_NUM_REGS < ARRAY_SIZE(tps65910_regs));
+ BUILD_BUG_ON(ARRAY_SIZE(tps65910_regs) !=
+ ARRAY_SIZE(tps65910_ext_sleep_control));
pmic->get_ctrl_reg = &tps65910_get_ctrl_register;
pmic->num_regulators = ARRAY_SIZE(tps65910_regs);
pmic->ext_sleep_control = tps65910_ext_sleep_control;
@@ -1117,6 +1127,8 @@ static int tps65910_probe(struct platform_device *pdev)
break;
case TPS65911:
BUILD_BUG_ON(TPS65910_NUM_REGS < ARRAY_SIZE(tps65911_regs));
+ BUILD_BUG_ON(ARRAY_SIZE(tps65911_regs) !=
+ ARRAY_SIZE(tps65911_ext_sleep_control));
pmic->get_ctrl_reg = &tps65911_get_ctrl_register;
pmic->num_regulators = ARRAY_SIZE(tps65911_regs);
pmic->ext_sleep_control = tps65911_ext_sleep_control;
--
2.56.1.839.g22a8290db9-goog
next prev parent reply other threads:[~2026-11-27 18:36 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 18:35 [PATCH 0/8] regulator: Fix locking, OOB read, lifetime, and global state bugs (batch 2) Lee Jones
2026-11-27 18:35 ` [PATCH 1/8] regulator: core: Defer supply cleanup and unregister event forwarding on error Lee Jones
2026-11-27 18:35 ` [PATCH 2/8] regulator: max8907: Duplicate of_regulator_match table per device Lee Jones
2026-11-27 18:35 ` [PATCH 3/8] regulator: tps6594-regulator: Use dedicated handler for external regulator IRQs Lee Jones
2026-11-27 18:35 ` Lee Jones [this message]
2026-11-27 18:35 ` [PATCH 5/8] regulator: tps6594-regulator: Bind IRQ resources to child platform device Lee Jones
2026-11-27 18:35 ` [PATCH 6/8] regulator: core: Respect is_locked when disabling supply on enable failure Lee Jones
2026-11-27 18:35 ` [PATCH 7/8] regulator: of: Guard against NULL device_node in of_regulator_bulk_get_all() Lee Jones
2026-11-27 18:35 ` [PATCH 8/8] regulator: aat2870: Duplicate regulator data per device Lee Jones
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=20261127183624.3341010-5-lee@kernel.org \
--to=lee@kernel.org \
--cc=aaro.koskinen@iki.fi \
--cc=andreas@kemnade.info \
--cc=broonie@kernel.org \
--cc=gg@slimlogic.co.uk \
--cc=jedu@slimlogic.co.uk \
--cc=khilman@baylibre.com \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-omap@vger.kernel.org \
--cc=msp@baylibre.com \
--cc=rogerq@kernel.org \
--cc=stable@vger.kernel.org \
--cc=tony@atomide.com \
/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
all inboxes | Powered by JetHome®