drivers/regulator/core.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-)
When creating the regulator object, associated with a consumer device,
the supply_name is string formatted into a statically sized buffer on
the stack, then strdup()'ed onto the heap.
Not only is the dance on the stack unnecessary, but when the device's
name is long we might not fit the constructed supply_name in the fixed
64 byte buffer on the stack.
One such case can be seen on the Qualcomm Rb3Gen2 board, where we find a
PCIe controller, with a PCIe switch, with a USB controller, with a USB
hub, consuming a regulator. In this example the dev->kobj.name itself is
62 characters long.
Drop the temporary buffer on the stack and kasprintf() the string
directly on the heap, both to simplify the code, and to remove the
length limitation.
Signed-off-by: Bjorn Andersson <bjorn.andersson@oss.qualcomm.com>
---
drivers/regulator/core.c | 12 +-----------
1 file changed, 1 insertion(+), 11 deletions(-)
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
index 8c2fd20edd50591c962454a358459e52e97c8ac0..80bb95750a207d52329273e8a780c391d2d78fda 100644
--- a/drivers/regulator/core.c
+++ b/drivers/regulator/core.c
@@ -1965,8 +1965,6 @@ static const struct file_operations constraint_flags_fops = {
#endif
};
-#define REG_STR_SIZE 64
-
static void link_and_create_debugfs(struct regulator *regulator, struct regulator_dev *rdev,
struct device *dev)
{
@@ -2014,15 +2012,7 @@ static struct regulator *create_regulator(struct regulator_dev *rdev,
lockdep_assert_held_once(&rdev->mutex.base);
if (dev) {
- char buf[REG_STR_SIZE];
- int size;
-
- size = snprintf(buf, REG_STR_SIZE, "%s-%s",
- dev->kobj.name, supply_name);
- if (size >= REG_STR_SIZE)
- return NULL;
-
- supply_name = kstrdup(buf, GFP_KERNEL);
+ supply_name = kasprintf(GFP_KERNEL, "%s-%s", dev->kobj.name, supply_name);
if (supply_name == NULL)
return NULL;
} else {
---
base-commit: fd9678829d6dd0c10fde080b536abf4b1121c346
change-id: 20260211-regulator-supply-name-length-14706722dc49
Best regards,
--
Bjorn Andersson <bjorn.andersson@oss.qualcomm.com>
On Wed, 11 Feb 2026 21:37:14 -0600, Bjorn Andersson wrote:
> When creating the regulator object, associated with a consumer device,
> the supply_name is string formatted into a statically sized buffer on
> the stack, then strdup()'ed onto the heap.
>
> Not only is the dance on the stack unnecessary, but when the device's
> name is long we might not fit the constructed supply_name in the fixed
> 64 byte buffer on the stack.
>
> [...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git for-next
Thanks!
[1/1] regulator: core: Remove regulator supply_name length limit
commit: e243cdd87b911ce9968b62e4ab2b680dfadc4341
All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying
to this mail.
Thanks,
Mark
© 2016 - 2026 Red Hat, Inc.