All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <greg@kroah.com>
To: Mohana Datta Yelugoti <ymdatta.work@gmail.com>
Cc: kernelnewbies@kernelnewbies.org
Subject: Re: Doubt on show() function of sysfs attribute
Date: Wed, 27 Jan 2021 09:10:20 +0100	[thread overview]
Message-ID: <YBEf7EYr3t/cFvEt@kroah.com> (raw)
In-Reply-To: <98fe87f5-19ac-dfa7-41eb-2e00d7415021@gmail.com>

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 :)

thanks,

greg k-h

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

  parent reply	other threads:[~2021-01-27  8:10 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-26 17:37 Doubt on show() function of sysfs attribute Mohana Datta Yelugoti
2021-01-27  3:51 ` Valdis Klētnieks
2021-01-27  8:10 ` Greg KH [this message]
2021-01-27  9:39   ` Lukas Bulwahn
2021-01-27 16:21   ` Mohana Datta Yelugoti

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YBEf7EYr3t/cFvEt@kroah.com \
    --to=greg@kroah.com \
    --cc=kernelnewbies@kernelnewbies.org \
    --cc=ymdatta.work@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.