]> Git Repo - linux.git/commitdiff
powercap: Adjust printing the constraint name with new line
authorLukasz Luba <[email protected]>
Tue, 17 Nov 2020 13:47:59 +0000 (13:47 +0000)
committerRafael J. Wysocki <[email protected]>
Mon, 23 Nov 2020 17:27:58 +0000 (18:27 +0100)
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]>
drivers/powercap/powercap_sys.c

index f808c5fa9838ce3b7cd8272b27c1aa38841c9f90..602c55287e7de67fb6202ddb73ae6e4ddf994322 100644 (file)
@@ -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);
                }
        }
This page took 0.059768 seconds and 4 git commands to generate.