Message ID | 1588235987-12300-2-git-send-email-guohanjun@huawei.com (mailing list archive) |
---|---|
State | Superseded, archived |
Headers | show |
Series | cpuidle: Make cpuidle governor switchable to be the default behaviour | expand |
On 30/04/2020 10:39, Hanjun Guo 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 sytle as well. > > Signed-off-by: Hanjun Guo <guohanjun@huawei.com> > --- > drivers/cpuidle/sysfs.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c > index d3ef1d7..3485210 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)) - > + if (i >= (ssize_t) ((PAGE_SIZE / sizeof(char)) - Is is possible to have a sizeof(char) != 1 ? > 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: >
On 2020/5/18 22:20, Daniel Lezcano wrote: > On 30/04/2020 10:39, Hanjun Guo 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 sytle as well. I got a typo here, s/sytle/style... >> >> Signed-off-by: Hanjun Guo <guohanjun@huawei.com> >> --- >> drivers/cpuidle/sysfs.c | 4 ++-- >> 1 file changed, 2 insertions(+), 2 deletions(-) >> >> diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c >> index d3ef1d7..3485210 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)) - >> + if (i >= (ssize_t) ((PAGE_SIZE / sizeof(char)) - > > Is is possible to have a sizeof(char) != 1 ? Not from my knowledge, I even didn't notice it, I'd happy to update this patch set to remove the sizeof(char), and adding ack and review/test tags from you and Doug. Thanks Hanjun
diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c index d3ef1d7..3485210 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)) - + if (i >= (ssize_t) ((PAGE_SIZE / sizeof(char)) - 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:
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 sytle as well. Signed-off-by: Hanjun Guo <guohanjun@huawei.com> --- drivers/cpuidle/sysfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)