All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] kernel/ksysfs: use snprintf for sysfs show
@ 2010-08-11 13:44 Davidlohr Bueso
  2010-08-11 14:05 ` Al Viro
  2010-08-11 15:21 ` Greg KH
  0 siblings, 2 replies; 3+ messages in thread
From: Davidlohr Bueso @ 2010-08-11 13:44 UTC (permalink / raw)
  To: LKML, kay.sievers, gregkh

Use snprintf(buf, PAGE_SIZE, ...) instead of sprintf for sysfs show
methods.  This is suggested in Documentation/filesystems/sysfs.txt

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
---
 kernel/ksysfs.c |   20 +++++++++++---------
 1 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
index 0b624e7..d7cef25 100644
--- a/kernel/ksysfs.c
+++ b/kernel/ksysfs.c
@@ -29,7 +29,9 @@ static struct kobj_attribute _name##_attr = \
 static ssize_t uevent_seqnum_show(struct kobject *kobj,
 				  struct kobj_attribute *attr, char *buf)
 {
-	return sprintf(buf, "%llu\n", (unsigned long long)uevent_seqnum);
+	return snprintf(buf, PAGE_SIZE, "%llu\n", 
+			(unsigned long long)uevent_seqnum); 
+
 }
 KERNEL_ATTR_RO(uevent_seqnum);
 
@@ -37,7 +39,7 @@ KERNEL_ATTR_RO(uevent_seqnum);
 static ssize_t uevent_helper_show(struct kobject *kobj,
 				  struct kobj_attribute *attr, char *buf)
 {
-	return sprintf(buf, "%s\n", uevent_helper);
+	return snprintf(buf, PAGE_SIZE, "%s\n", uevent_helper);
 }
 static ssize_t uevent_helper_store(struct kobject *kobj,
 				   struct kobj_attribute *attr,
@@ -58,7 +60,7 @@ KERNEL_ATTR_RW(uevent_helper);
 static ssize_t profiling_show(struct kobject *kobj,
 				  struct kobj_attribute *attr, char *buf)
 {
-	return sprintf(buf, "%d\n", prof_on);
+	return snprintf(buf, PAGE_SIZE, "%d\n", prof_on);
 }
 static ssize_t profiling_store(struct kobject *kobj,
 				   struct kobj_attribute *attr,
@@ -89,21 +91,21 @@ KERNEL_ATTR_RW(profiling);
 static ssize_t kexec_loaded_show(struct kobject *kobj,
 				 struct kobj_attribute *attr, char *buf)
 {
-	return sprintf(buf, "%d\n", !!kexec_image);
+	return snprintf(buf, PAGE_SIZE, "%d\n", !!kexec_image);
 }
 KERNEL_ATTR_RO(kexec_loaded);
 
 static ssize_t kexec_crash_loaded_show(struct kobject *kobj,
 				       struct kobj_attribute *attr, char *buf)
 {
-	return sprintf(buf, "%d\n", !!kexec_crash_image);
+	return snprintf(buf, PAGE_SIZE, "%d\n", !!kexec_crash_image);
 }
 KERNEL_ATTR_RO(kexec_crash_loaded);
 
 static ssize_t kexec_crash_size_show(struct kobject *kobj,
 				       struct kobj_attribute *attr, char *buf)
 {
-	return sprintf(buf, "%zu\n", crash_get_memory_size());
+	return snprintf(buf, PAGE_SIZE, "%zu\n", crash_get_memory_size());
 }
 static ssize_t kexec_crash_size_store(struct kobject *kobj,
 				   struct kobj_attribute *attr,
@@ -123,9 +125,9 @@ KERNEL_ATTR_RW(kexec_crash_size);
 static ssize_t vmcoreinfo_show(struct kobject *kobj,
 			       struct kobj_attribute *attr, char *buf)
 {
-	return sprintf(buf, "%lx %x\n",
-		       paddr_vmcoreinfo_note(),
-		       (unsigned int)vmcoreinfo_max_size);
+	return snprintf(buf, PAGE_SIZE, "%lx %x\n",
+			paddr_vmcoreinfo_note(),
+			(unsigned int)vmcoreinfo_max_size);
 }
 KERNEL_ATTR_RO(vmcoreinfo);
 
-- 
1.7.0.4


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

* Re: [PATCH] kernel/ksysfs: use snprintf for sysfs show
  2010-08-11 13:44 [PATCH] kernel/ksysfs: use snprintf for sysfs show Davidlohr Bueso
@ 2010-08-11 14:05 ` Al Viro
  2010-08-11 15:21 ` Greg KH
  1 sibling, 0 replies; 3+ messages in thread
From: Al Viro @ 2010-08-11 14:05 UTC (permalink / raw)
  To: Davidlohr Bueso; +Cc: LKML, kay.sievers, gregkh

On Wed, Aug 11, 2010 at 09:44:10AM -0400, Davidlohr Bueso wrote:
> Use snprintf(buf, PAGE_SIZE, ...) instead of sprintf for sysfs show
> methods.  This is suggested in Documentation/filesystems/sysfs.txt

... therefore it must be done, the common sense be damned.

> Signed-off-by: Davidlohr Bueso <dave@gnu.org>
> ---

>  static ssize_t uevent_seqnum_show(struct kobject *kobj,
>  				  struct kobj_attribute *attr, char *buf)
>  {
> -	return sprintf(buf, "%llu\n", (unsigned long long)uevent_seqnum);
> +	return snprintf(buf, PAGE_SIZE, "%llu\n", 
> +			(unsigned long long)uevent_seqnum); 

A-yup - that's an improvement, all right, on them evil boxen that got
long long so huge that its decimal representation won't fit into a page.

NAK.  Cargo-cult programming is bad.

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

* Re: [PATCH] kernel/ksysfs: use snprintf for sysfs show
  2010-08-11 13:44 [PATCH] kernel/ksysfs: use snprintf for sysfs show Davidlohr Bueso
  2010-08-11 14:05 ` Al Viro
@ 2010-08-11 15:21 ` Greg KH
  1 sibling, 0 replies; 3+ messages in thread
From: Greg KH @ 2010-08-11 15:21 UTC (permalink / raw)
  To: Davidlohr Bueso; +Cc: LKML, kay.sievers

On Wed, Aug 11, 2010 at 09:44:10AM -0400, Davidlohr Bueso wrote:
> Use snprintf(buf, PAGE_SIZE, ...) instead of sprintf for sysfs show
> methods.  This is suggested in Documentation/filesystems/sysfs.txt

As Al pointed out, none of these will ever overflow so it makes no sense
to change them.

thanks,

greg k-h

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

end of thread, other threads:[~2010-08-11 15:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-11 13:44 [PATCH] kernel/ksysfs: use snprintf for sysfs show Davidlohr Bueso
2010-08-11 14:05 ` Al Viro
2010-08-11 15:21 ` Greg KH

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.