Skip to content

Commit b4ba76f

Browse files
lukaszluba-armrafaeljw
authored andcommitted
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 <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 8a9d881 commit b4ba76f

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

drivers/powercap/powercap_sys.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,8 @@ static ssize_t show_constraint_name(struct device *dev,
170170
if (pconst && pconst->ops && pconst->ops->get_name) {
171171
name = pconst->ops->get_name(power_zone, id);
172172
if (name) {
173-
snprintf(buf, POWERCAP_CONSTRAINT_NAME_LEN,
174-
"%s\n", name);
175-
buf[POWERCAP_CONSTRAINT_NAME_LEN] = '\0';
173+
sprintf(buf, "%.*s\n", POWERCAP_CONSTRAINT_NAME_LEN - 1,
174+
name);
176175
len = strlen(buf);
177176
}
178177
}

0 commit comments

Comments
 (0)