From: Lee Jones <lee@kernel.org>
To: lee@kernel.org, Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>, Jin Park <jinyoungp@nvidia.com>,
Samuel Ortiz <sameo@linux.intel.com>,
linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Subject: [PATCH 8/8] regulator: aat2870: Duplicate regulator data per device
Date: Fri, 27 Nov 2026 18:35:48 +0000 [thread overview]
Message-ID: <20261127183624.3341010-9-lee@kernel.org> (raw)
In-Reply-To: <20261127183624.3341010-1-lee@kernel.org>
aat2870_get_regulator() returns a pointer into the static global
aat2870_regulators array and mutates its fields in place, after which
aat2870_regulator_probe() stores the parent MFD pointer into that shared
entry. Probing a second AAT2870 device overwrites the first device's
state and leads to misrouted operations or use-after-free on removal.
Mark aat2870_regulators const and duplicate the matching entry per
device with devm_kmemdup() before registering the regulator.
Fixes: f7eb6c5e8e5e ("regulator: aat2870: Add AAT2870 regulator driver")
Closes: https://sashiko.dev/#/bug/linux-6f356dcb-fbbc-487c-8fb3-0f765ac5a4d6
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
drivers/regulator/aat2870-regulator.c | 30 +++++++++++++++++----------
1 file changed, 19 insertions(+), 11 deletions(-)
diff --git a/drivers/regulator/aat2870-regulator.c b/drivers/regulator/aat2870-regulator.c
index 52c08e6c4803..326886371e85 100644
--- a/drivers/regulator/aat2870-regulator.c
+++ b/drivers/regulator/aat2870-regulator.c
@@ -114,26 +114,33 @@ static const unsigned int aat2870_ldo_voltages[] = {
}, \
}
-static struct aat2870_regulator aat2870_regulators[] = {
+static const struct aat2870_regulator aat2870_regulators[] = {
AAT2870_LDO(LDOA),
AAT2870_LDO(LDOB),
AAT2870_LDO(LDOC),
AAT2870_LDO(LDOD),
};
-static struct aat2870_regulator *aat2870_get_regulator(int id)
+static struct aat2870_regulator *aat2870_get_regulator(struct device *dev,
+ int id)
{
- struct aat2870_regulator *ri = NULL;
+ const struct aat2870_regulator *template = NULL;
+ struct aat2870_regulator *ri;
int i;
for (i = 0; i < ARRAY_SIZE(aat2870_regulators); i++) {
- ri = &aat2870_regulators[i];
- if (ri->desc.id == id)
+ if (aat2870_regulators[i].desc.id == id) {
+ template = &aat2870_regulators[i];
break;
+ }
}
- if (i == ARRAY_SIZE(aat2870_regulators))
- return NULL;
+ if (!template)
+ return ERR_PTR(-EINVAL);
+
+ ri = devm_kmemdup(dev, template, sizeof(*ri), GFP_KERNEL);
+ if (!ri)
+ return ERR_PTR(-ENOMEM);
ri->enable_addr = AAT2870_LDO_EN;
ri->enable_shift = id - AAT2870_ID_LDOA;
@@ -153,10 +160,11 @@ static int aat2870_regulator_probe(struct platform_device *pdev)
struct regulator_config config = { };
struct regulator_dev *rdev;
- ri = aat2870_get_regulator(pdev->id);
- if (!ri) {
- dev_err(&pdev->dev, "Invalid device ID, %d\n", pdev->id);
- return -EINVAL;
+ ri = aat2870_get_regulator(&pdev->dev, pdev->id);
+ if (IS_ERR(ri)) {
+ if (PTR_ERR(ri) == -EINVAL)
+ dev_err(&pdev->dev, "Invalid device ID, %d\n", pdev->id);
+ return PTR_ERR(ri);
}
ri->aat2870 = dev_get_drvdata(pdev->dev.parent);
--
2.56.1.839.g22a8290db9-goog
prev parent reply other threads:[~2026-11-27 18:37 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 ` [PATCH 4/8] regulator: tps65910: Fix OOB read and bit shift in external sleep config Lee Jones
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 ` Lee Jones [this message]
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-9-lee@kernel.org \
--to=lee@kernel.org \
--cc=broonie@kernel.org \
--cc=jinyoungp@nvidia.com \
--cc=lgirdwood@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=sameo@linux.intel.com \
--cc=stable@vger.kernel.org \
/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®