All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH -next 0/3] s390: use scnprintf() in show() methods
@ 2020-05-09  8:56 Chen Zhou
  2020-05-09  8:56 ` [PATCH -next 1/3] s390/crypto: use scnprintf() instead of snprintf() Chen Zhou
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Chen Zhou @ 2020-05-09  8:56 UTC (permalink / raw)
  To: heiko.carstens, gor, borntraeger; +Cc: linux-s390, linux-kernel, chenzhou10

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(-)

-- 
2.20.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH -next 1/3] s390/crypto: use scnprintf() instead of snprintf()
  2020-05-09  8:56 [PATCH -next 0/3] s390: use scnprintf() in show() methods Chen Zhou
@ 2020-05-09  8:56 ` Chen Zhou
  2020-05-09  8:56 ` [PATCH -next 2/3] s390: use scnprintf() in sys_##_prefix##_##_name##_show Chen Zhou
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Chen Zhou @ 2020-05-09  8:56 UTC (permalink / raw)
  To: heiko.carstens, gor, borntraeger; +Cc: linux-s390, linux-kernel, chenzhou10

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().

Signed-off-by: Chen Zhou <chenzhou10@huawei.com>
---
 arch/s390/crypto/prng.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/arch/s390/crypto/prng.c b/arch/s390/crypto/prng.c
index d977643fa627..e1ae23911ccd 100644
--- a/arch/s390/crypto/prng.c
+++ b/arch/s390/crypto/prng.c
@@ -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);
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH -next 2/3] s390: use scnprintf() in sys_##_prefix##_##_name##_show
  2020-05-09  8:56 [PATCH -next 0/3] s390: use scnprintf() in show() methods Chen Zhou
  2020-05-09  8:56 ` [PATCH -next 1/3] s390/crypto: use scnprintf() instead of snprintf() Chen Zhou
@ 2020-05-09  8:56 ` Chen Zhou
  2020-05-09  8:56 ` [PATCH -next 3/3] s390/protvirt: use scnprintf() instead of snprintf() Chen Zhou
  2020-06-08 14:25 ` [PATCH -next 0/3] s390: use scnprintf() in show() methods Heiko Carstens
  3 siblings, 0 replies; 5+ messages in thread
From: Chen Zhou @ 2020-05-09  8:56 UTC (permalink / raw)
  To: heiko.carstens, gor, borntraeger; +Cc: linux-s390, linux-kernel, chenzhou10

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().

Signed-off-by: Chen Zhou <chenzhou10@huawei.com>
---
 arch/s390/kernel/ipl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/s390/kernel/ipl.c b/arch/s390/kernel/ipl.c
index ccea9a245867..90a2a17239b0 100644
--- a/arch/s390/kernel/ipl.c
+++ b/arch/s390/kernel/ipl.c
@@ -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)			\
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH -next 3/3] s390/protvirt: use scnprintf() instead of snprintf()
  2020-05-09  8:56 [PATCH -next 0/3] s390: use scnprintf() in show() methods Chen Zhou
  2020-05-09  8:56 ` [PATCH -next 1/3] s390/crypto: use scnprintf() instead of snprintf() Chen Zhou
  2020-05-09  8:56 ` [PATCH -next 2/3] s390: use scnprintf() in sys_##_prefix##_##_name##_show Chen Zhou
@ 2020-05-09  8:56 ` Chen Zhou
  2020-06-08 14:25 ` [PATCH -next 0/3] s390: use scnprintf() in show() methods Heiko Carstens
  3 siblings, 0 replies; 5+ messages in thread
From: Chen Zhou @ 2020-05-09  8:56 UTC (permalink / raw)
  To: heiko.carstens, gor, borntraeger; +Cc: linux-s390, linux-kernel, chenzhou10

snprintf() 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.

Signed-off-by: Chen Zhou <chenzhou10@huawei.com>
---
 arch/s390/kernel/uv.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/arch/s390/kernel/uv.c b/arch/s390/kernel/uv.c
index 4c0677fc8904..e7ea82a2bf63 100644
--- a/arch/s390/kernel/uv.c
+++ b/arch/s390/kernel/uv.c
@@ -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);
 }
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH -next 0/3] s390: use scnprintf() in show() methods
  2020-05-09  8:56 [PATCH -next 0/3] s390: use scnprintf() in show() methods Chen Zhou
                   ` (2 preceding siblings ...)
  2020-05-09  8:56 ` [PATCH -next 3/3] s390/protvirt: use scnprintf() instead of snprintf() Chen Zhou
@ 2020-06-08 14:25 ` Heiko Carstens
  3 siblings, 0 replies; 5+ messages in thread
From: Heiko Carstens @ 2020-06-08 14:25 UTC (permalink / raw)
  To: Chen Zhou; +Cc: gor, borntraeger, linux-s390, linux-kernel

On Sat, May 09, 2020 at 04:56:05PM +0800, Chen Zhou wrote:
> 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(-)

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.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-06-08 14:28 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-09  8:56 [PATCH -next 0/3] s390: use scnprintf() in show() methods Chen Zhou
2020-05-09  8:56 ` [PATCH -next 1/3] s390/crypto: use scnprintf() instead of snprintf() Chen Zhou
2020-05-09  8:56 ` [PATCH -next 2/3] s390: use scnprintf() in sys_##_prefix##_##_name##_show Chen Zhou
2020-05-09  8:56 ` [PATCH -next 3/3] s390/protvirt: use scnprintf() instead of snprintf() Chen Zhou
2020-06-08 14:25 ` [PATCH -next 0/3] s390: use scnprintf() in show() methods Heiko Carstens

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.