All of lore.kernel.org
 help / color / mirror / Atom feed
* [KJ] [PATCH] Driver core: Documentation: use snprintf and strnlen
@ 2005-07-21 20:49 Jan Veldeman
  2005-07-21 21:54 ` [KJ] [PATCH] Driver core: Documentation: fix whitespace between Jan Veldeman
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Jan Veldeman @ 2005-07-21 20:49 UTC (permalink / raw)
  To: kernel-janitors

[-- Attachment #1: Type: text/plain, Size: 903 bytes --]


Documentation should give the good example of using snprintf and
strnlen in stead of sprintf and strlen.

PAGE_SIZE is used as the maximal length to reflect the behaviour of
show/store.


Signed-off-by: Jan Veldeman <Jan.Veldeman@advalvas.be>


diff --git a/Documentation/filesystems/sysfs.txt b/Documentation/filesystems/sysfs.txt
--- a/Documentation/filesystems/sysfs.txt
+++ b/Documentation/filesystems/sysfs.txt
@@ -216,13 +216,13 @@ A very simple (and naive) implementation
 
 static ssize_t show_name(struct device *dev, struct device_attribute *attr, char *buf)
 {
-        return sprintf(buf,"%s\n",dev->name);
+        return snprintf(buf,PAGE_SIZE,"%s\n",dev->name);
 }
 
 static ssize_t store_name(struct device * dev, const char * buf)
 {
 	sscanf(buf,"%20s",dev->name);
-	return strlen(buf);
+	return strnlen(buf,PAGE_SIZE);
 }
 
 static DEVICE_ATTR(name,S_IRUGO,show_name,store_name);




[-- Attachment #2: Type: text/plain, Size: 168 bytes --]

_______________________________________________
Kernel-janitors mailing list
Kernel-janitors@lists.osdl.org
https://lists.osdl.org/mailman/listinfo/kernel-janitors

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

end of thread, other threads:[~2005-07-22  9:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-07-21 20:49 [KJ] [PATCH] Driver core: Documentation: use snprintf and strnlen Jan Veldeman
2005-07-21 21:54 ` [KJ] [PATCH] Driver core: Documentation: fix whitespace between Jan Veldeman
2005-07-22  8:19 ` [KJ] [PATCH] Driver core: Documentation: use S_IRUSR | ... in stead Jan Veldeman
2005-07-22  9:41 ` Jan Veldeman

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.