Re: [PATCH] kernel/ksysfs: use snprintf for sysfs show

From: Al Viro
Date: Wed Aug 11 2010 - 10:05:22 EST


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@xxxxxxx>
> ---

> 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.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/