kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: greg@kroah.com (Greg KH)
To: kernelnewbies@lists.kernelnewbies.org
Subject: More info about kobj_attribute store and show functions
Date: Wed, 3 Sep 2014 19:22:44 -0700	[thread overview]
Message-ID: <20140904022244.GB552@kroah.com> (raw)
In-Reply-To: <CAJyon0vO16ggtw10FpbimEzYd8u0sqim9s0p2SW_zb--WYQm9A@mail.gmail.com>

On Wed, Sep 03, 2014 at 10:39:06PM -0300, Lucas Tanure wrote:
> Greg,?
> 
> I was looking again to?documentation, but didn't find a explanation about the
> show and store functions. I'm missing something ??
> 
> Yes, everything work if I simple use the buffer from store function, but I was
> looking for where it came from.?
> Like, It was from user space? So, I need to take care like?
> simple_write_to_buffer does with user space memory ??

If it came from userspace, it would have been marked with a __user
marking, so it's a kernel pointer.

> static ssize_t id_store(struct kobject *kobj, struct kobj_attribute *attr,
> const char *buf, size_t count)
> {
> char *buffer;
> buffer = kcalloc(cnt, sizeof(char), GFP_KERNEL);
> if (buffer) {
> if (copy_from_user(buffer, buf, cnt) == cnt) {
> if (strcmp(buffer, "Tanure") == 0)
> return cnt;
> }
> }
> }
> return -EINVAL;
> }

Just work with the buffer directly, sysfs is supposed to be "easy" to
use.

greg k-h

  reply	other threads:[~2014-09-04  2:22 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-09-04  0:04 More info about kobj_attribute store and show functions Lucas Tanure
2014-09-04  0:10 ` Lucas Tanure
2014-09-04  0:23   ` Greg KH
2014-09-04  0:39     ` Lucas Tanure
2014-09-04  0:56       ` Greg KH
2014-09-04  1:39         ` Lucas Tanure
2014-09-04  2:22           ` Greg KH [this message]
2014-09-04  1:30   ` Jeff Haran
  -- strict thread matches above, loose matches on Subject: below --
2014-09-04  0:03 Lucas Tanure

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=20140904022244.GB552@kroah.com \
    --to=greg@kroah.com \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).