s390: use scnprintf() in show() methods
Subsystems (4)
cover s390: use scnprintf() in show() methods
snprintf() returns the number of bytes that would be written, which may be greater than the the actual length to be written.
show() methods should return the number of bytes printed into the buffer. This is the return value of scnprintf().
Chen Zhou (3):
s390/crypto: use scnprintf() instead of snprintf()
s390: use scnprintf() in sys_##_prefix##_##_name##_show s390/protvirt: use scnprintf() instead of snprintf()
arch/s390/crypto/prng.c | 14 +++++++------- arch/s390/kernel/ipl.c | 2 +- arch/s390/kernel/uv.c | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-)
Signature · 1 line
2.20.1
PATCH 1/3 s390/crypto: use scnprintf() instead of snprintf()
snprintf() returns the number of bytes that would be written, which may be greater than the the actual length to be written.
show() methods should return the number of bytes printed into the buffer. This is the return value of scnprintf().
--- arch/s390/crypto/prng.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
arch/s390/crypto/prng.c +7 -7
@@ -693,7 +693,7 @@ static ssize_t prng_chunksize_show(struct device *dev,struct device_attribute *attr, char *buf) { - return snprintf(buf, PAGE_SIZE, "%u\n", prng_chunk_size); + return scnprintf(buf, PAGE_SIZE, "%u\n", prng_chunk_size); } static DEVICE_ATTR(chunksize, 0444, prng_chunksize_show, NULL);
@@ -712,7 +712,7 @@ static ssize_t prng_counter_show(struct device *dev, counter = prng_data->prngws.byte_counter;mutex_unlock (&prng_data->mutex); -return snprintf (buf,PAGE_SIZE ,"%llu\n" , counter); +return scnprintf (buf,PAGE_SIZE ,"%llu\n" , counter); } static DEVICE_ATTR(byte_counter, 0444, prng_counter_show, NULL);
@@ -721,7 +721,7 @@ static ssize_t prng_errorflag_show(struct device *dev,struct device_attribute *attr, char *buf) { - return snprintf(buf, PAGE_SIZE, "%d\n", prng_errorflag); + return scnprintf(buf, PAGE_SIZE, "%d\n", prng_errorflag); } static DEVICE_ATTR(errorflag, 0444, prng_errorflag_show, NULL);
@@ -731,9 +731,9 @@ static ssize_t prng_mode_show(struct device *dev, char *buf) {if (prng_mode ==PRNG_MODE_TDES ) -return snprintf (buf,PAGE_SIZE ,"TDES\n" ); +return scnprintf (buf,PAGE_SIZE ,"TDES\n" );else -return snprintf (buf,PAGE_SIZE ,"SHA512\n" ); +return scnprintf (buf,PAGE_SIZE ,"SHA512\n" ); } static DEVICE_ATTR(mode, 0444, prng_mode_show, NULL);
@@ -756,7 +756,7 @@ static ssize_t prng_reseed_limit_show(struct device *dev,struct device_attribute *attr, char *buf) { - return snprintf(buf, PAGE_SIZE, "%u\n", prng_reseed_limit); + return scnprintf(buf, PAGE_SIZE, "%u\n", prng_reseed_limit); } static ssize_t prng_reseed_limit_store(struct device *dev, struct device_attribute *attr,
@@ -787,7 +787,7 @@ static ssize_t prng_strength_show(struct device *dev,struct device_attribute *attr, char *buf) { - return snprintf(buf, PAGE_SIZE, "256\n"); + return scnprintf(buf, PAGE_SIZE, "256\n"); } static DEVICE_ATTR(strength, 0444, prng_strength_show, NULL);
Signature · 1 line
2.20.1
PATCH 2/3 s390: use scnprintf() in sys_##_prefix##_##_name##_show
In reply to Chen Zhousnprintf() returns the number of bytes that would be written, which may be greater than the the actual length to be written.
show() methods should return the number of bytes printed into the buffer. This is the return value of scnprintf().
--- arch/s390/kernel/ipl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/s390/kernel/ipl.c +1 -1
@@ -181,7 +181,7 @@ static ssize_t sys_##_prefix##_##_name##_show(struct kobject *kobj, \struct kobj_attribute *attr, \ char *page) \ { \ - return snprintf(page, PAGE_SIZE, _format, ##args); \ + return scnprintf(page, PAGE_SIZE, _format, ##args); \ }#define IPL_ATTR_CCW_STORE_FN (_prefix, _name, _ipl_blk) \
Signature · 1 line
2.20.1
PATCH 3/3 s390/protvirt: use scnprintf() instead of snprintf()
In reply to Chen Zhousnprintf() returns the number of bytes that would be written, which may be greater than the the actual length to be written.
uv_query_facilities() should return the number of bytes printed into the buffer. This is the return value of scnprintf(). The other functions are the same.
--- arch/s390/kernel/uv.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
arch/s390/kernel/uv.c +4 -4
@@ -331,7 +331,7 @@ EXPORT_SYMBOL_GPL(arch_make_page_accessible);static ssize_t uv_query_facilities (struct kobject *kobj,struct kobj_attribute *attr,char *page) { - return snprintf(page, PAGE_SIZE, "%lx\n%lx\n%lx\n%lx\n", + return scnprintf(page, PAGE_SIZE, "%lx\n%lx\n%lx\n%lx\n", uv_info.inst_calls_list[0], uv_info.inst_calls_list[1], uv_info.inst_calls_list[2],
@@ -344,7 +344,7 @@ static struct kobj_attribute uv_query_facilities_attr =static ssize_t uv_query_max_guest_cpus (struct kobject *kobj,struct kobj_attribute *attr,char *page) { -return snprintf (page,PAGE_SIZE ,"%d\n" , +return scnprintf (page,PAGE_SIZE ,"%d\n" , uv_info.max_guest_cpus); }
@@ -354,7 +354,7 @@ static struct kobj_attribute uv_query_max_guest_cpus_attr =static ssize_t uv_query_max_guest_vms (struct kobject *kobj,struct kobj_attribute *attr,char *page) { -return snprintf (page,PAGE_SIZE ,"%d\n" , +return scnprintf (page,PAGE_SIZE ,"%d\n" , uv_info.max_num_sec_conf); }
@@ -364,7 +364,7 @@ static struct kobj_attribute uv_query_max_guest_vms_attr =static ssize_t uv_query_max_guest_addr (struct kobject *kobj,struct kobj_attribute *attr,char *page) { -return snprintf (page,PAGE_SIZE ,"%lx\n" , +return scnprintf (page,PAGE_SIZE ,"%lx\n" , uv_info.max_sec_stor_addr); }
Signature · 1 line
2.20.1
Quoted 11 lines · Chen Zhou
snprintf()returns the number of bytes that would be written, which may be greater than the the actual length to be written.
show()methods should return the number of bytes printed into the buffer. This is the return value ofscnprintf().Chen Zhou (3):
s390/crypto: usescnprintf()instead ofsnprintf()
s390: usescnprintf()in sys_##_prefix##_##_name##_show s390/protvirt: usescnprintf()instead ofsnprintf()
Quoted 4 lines
arch/s390/crypto/prng.c | 14 +++++++------- arch/s390/kernel/ipl.c | 2 +- arch/s390/kernel/uv.c | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-)
All applied, even though the buffer has a size of 4k in all cases. So this doesn't fix anything; but it doesn't hurt as well.