summaryrefslogtreecommitdiffstats
path: root/drivers/powercap
diff options
context:
space:
mode:
authorLukasz Luba <lukasz.luba@arm.com>2020-11-17 14:47:59 +0100
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2020-11-23 18:27:58 +0100
commitb4ba76fb1c999384c1b0840d216d42abcd611024 (patch)
tree70ea8ad7e4b8df995150a54862f1496b6a8a662e /drivers/powercap
parentpowercap: RAPL: Add AMD Fam19h RAPL support (diff)
downloadlinux-b4ba76fb1c999384c1b0840d216d42abcd611024.tar.xz
linux-b4ba76fb1c999384c1b0840d216d42abcd611024.zip
powercap: Adjust printing the constraint name with new line
The constrain name has limit of size 30, which sometimes might be hit. When this happens the new line might get lost. Prevent this and set the max limit for name string length equal 29. This would result is proper string clamping (when needed) and storing '\n' at index 29 and '\0' at 30, so similarly as desired originally. Signed-off-by: Lukasz Luba <lukasz.luba@arm.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Diffstat (limited to 'drivers/powercap')
-rw-r--r--drivers/powercap/powercap_sys.c5
1 files changed, 2 insertions, 3 deletions
diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
index f808c5fa9838..602c55287e7d 100644
--- a/drivers/powercap/powercap_sys.c
+++ b/drivers/powercap/powercap_sys.c
@@ -170,9 +170,8 @@ static ssize_t show_constraint_name(struct device *dev,
if (pconst && pconst->ops && pconst->ops->get_name) {
name = pconst->ops->get_name(power_zone, id);
if (name) {
- snprintf(buf, POWERCAP_CONSTRAINT_NAME_LEN,
- "%s\n", name);
- buf[POWERCAP_CONSTRAINT_NAME_LEN] = '\0';
+ sprintf(buf, "%.*s\n", POWERCAP_CONSTRAINT_NAME_LEN - 1,
+ name);
len = strlen(buf);
}
}