Doubt on show() function of sysfs attribute

Greg KH greg at
Wed Jan 27 03:10:20 EST 2021

On Tue, Jan 26, 2021 at 11:07:24PM +0530, Mohana Datta Yelugoti wrote:
> Hello everyone,
> I am going through Documentation/filesystems/sysfs.rst.
> It says that sysfs allocates a buffer of size PAGE_SIZE and
> passes it to the show/store functions of the attribute. On
> read(), the show() method should fill the entire buffer[0].

No, that's not the case.  Please only fill in what you need sent back to
userspace and return the number of bytes you used.  A simple call to
sprintf() or better yet, sysfs_emit(), as a return statement is all you
need to do.

See the thousands of examples in the kernel of this if you need proof :)


greg k-h

More information about the Kernelnewbies mailing list