Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

regulator: core: Remove regulator supply_name length limit

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>
Link: https://patch.msgid.link/20260211-regulator-supply-name-length-v1-1-3875541c1576@oss.qualcomm.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Bjorn Andersson and committed by
Mark Brown
e243cdd8 1a4b0c99

+1 -11
+1 -11
drivers/regulator/core.c
··· 1965 1965 #endif 1966 1966 }; 1967 1967 1968 - #define REG_STR_SIZE 64 1969 - 1970 1968 static void link_and_create_debugfs(struct regulator *regulator, struct regulator_dev *rdev, 1971 1969 struct device *dev) 1972 1970 { ··· 2012 2014 lockdep_assert_held_once(&rdev->mutex.base); 2013 2015 2014 2016 if (dev) { 2015 - char buf[REG_STR_SIZE]; 2016 - int size; 2017 - 2018 - size = snprintf(buf, REG_STR_SIZE, "%s-%s", 2019 - dev->kobj.name, supply_name); 2020 - if (size >= REG_STR_SIZE) 2021 - return NULL; 2022 - 2023 - supply_name = kstrdup(buf, GFP_KERNEL); 2017 + supply_name = kasprintf(GFP_KERNEL, "%s-%s", dev->kobj.name, supply_name); 2024 2018 if (supply_name == NULL) 2025 2019 return NULL; 2026 2020 } else {