Skip to content

Commit

Permalink
powercap: Adjust printing the constraint name with new line
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
lukaszluba-arm authored and rafaeljw committed Nov 23, 2020
1 parent 8a9d881 commit b4ba76f
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions drivers/powercap/powercap_sys.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit b4ba76f

Please sign in to comment.