diff mbox series

[1/6] cpuidle: sysfs: Fix the overlap for showing available governors

Message ID 1589869525-29893-2-git-send-email-guohanjun@huawei.com (mailing list archive)
State Mainlined, archived
Headers show
Series cpuidle: Make cpuidle governor switchable to be the default behaviour | expand

Commit Message

Hanjun Guo May 19, 2020, 6:25 a.m. UTC
When showing the available governors, it's "%s " in scnprintf(),
not "%s", so if the governor name has 15 characters, it will
overlap with the later one, fix it by adding one more for the
size.

While we are at it, fix the minor coding style issue and remove
the "/sizeof(char)" since sizeof(char) always equals 1.

Signed-off-by: Hanjun Guo <guohanjun@huawei.com>
Reviewed-by: Doug Smythies <dsmythies@telus.net>
Tested-by: Doug Smythies <dsmythies@telus.net>
---
 drivers/cpuidle/sysfs.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Rafael J. Wysocki May 19, 2020, 3:43 p.m. UTC | #1
On Tue, May 19, 2020 at 8:32 AM Hanjun Guo <guohanjun@huawei.com> wrote:
>
> When showing the available governors, it's "%s " in scnprintf(),
> not "%s", so if the governor name has 15 characters, it will
> overlap with the later one, fix it by adding one more for the
> size.
>
> While we are at it, fix the minor coding style issue and remove
> the "/sizeof(char)" since sizeof(char) always equals 1.
>
> Signed-off-by: Hanjun Guo <guohanjun@huawei.com>
> Reviewed-by: Doug Smythies <dsmythies@telus.net>
> Tested-by: Doug Smythies <dsmythies@telus.net>

All patches in this series applied as 5.8 material, thanks!
diff mbox series

Patch

diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
index d3ef1d7..477b05a 100644
--- a/drivers/cpuidle/sysfs.c
+++ b/drivers/cpuidle/sysfs.c
@@ -35,10 +35,10 @@  static ssize_t show_available_governors(struct device *dev,
 
 	mutex_lock(&cpuidle_lock);
 	list_for_each_entry(tmp, &cpuidle_governors, governor_list) {
-		if (i >= (ssize_t) ((PAGE_SIZE/sizeof(char)) -
-				    CPUIDLE_NAME_LEN - 2))
+		if (i >= (ssize_t) (PAGE_SIZE - (CPUIDLE_NAME_LEN + 2)))
 			goto out;
-		i += scnprintf(&buf[i], CPUIDLE_NAME_LEN, "%s ", tmp->name);
+
+		i += scnprintf(&buf[i], CPUIDLE_NAME_LEN + 1, "%s ", tmp->name);
 	}
 
 out: