Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d3f70bef authored by Bart Van Assche's avatar Bart Van Assche Committed by Greg Kroah-Hartman
Browse files

docs/sysfs: show() methods should use scnprintf().



Since snprintf() may return a value that exceeds its second argument,
show() methods should use scnprintf() instead of snprintf(). This patch
updates the example in the sysfs documentation accordingly.

Signed-off-by: default avatarBart Van Assche <bvanassche@acm.org>
Cc: Tejun Heo <tj@kernel.org>
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 5480bcdd
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -210,9 +210,9 @@ Other notes:
  is 4096. 

- show() methods should return the number of bytes printed into the
  buffer. This is the return value of snprintf().
  buffer. This is the return value of scnprintf().

- show() should always use snprintf(). 
- show() should always use scnprintf().

- store() should return the number of bytes used from the buffer. If the
  entire buffer has been used, just return the count argument.
@@ -231,7 +231,7 @@ A very simple (and naive) implementation of a device attribute is:
static ssize_t show_name(struct device *dev, struct device_attribute *attr,
                         char *buf)
{
	return snprintf(buf, PAGE_SIZE, "%s\n", dev->name);
	return scnprintf(buf, PAGE_SIZE, "%s\n", dev->name);
}

static ssize_t store_name(struct device *dev, struct device_attribute *attr,