More info about kobj_attribute store and show functions

Lucas Tanure tanure at linux.com
Wed Sep 3 21:39:06 EDT 2014


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 ?

I said that because of file file_operations read and write, that I know
that comes from user space. But kobj_attribute  I didn't understand yet.

What I meant posting one piece of my code was just show what I doing in
high level.
But, for some reason gmail sent in the middle of my writing.



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;
}

The copy_from_user returns 6 when I write my name in the file. So, 6 means
that copy_from_user fails to copy 6 bytes from buf.
So there is my question, buf is a user pointer ? Or Can I just copy without
problems ?

All this e-mails got me in trouble here. I got kicked from eudyptula
challenge, what I still begging to be able to finish.

Thanks Greg for all the help.



--
Lucas Tanure
+55 (19) 988176559


On Wed, Sep 3, 2014 at 9:56 PM, Greg KH <greg at kroah.com> wrote:

>
> A: No.
> Q: Should I include quotations after my reply?
>
> http://daringfireball.net/2007/07/on_top
>
> On Wed, Sep 03, 2014 at 09:39:50PM -0300, Lucas Tanure wrote:
> > Greg,
> >
> > I'm still trying to understand the sysfs.
>
> Why?  What are you using "raw kobjects" for?  You should almost never
> need them.
>
> > I indeed read the documentation, I was using your "Sample kobject
> > implementation" as base of my code.
>
> Great, then it should "just work", right?  :)
>
> Care to post your non-working code?
>
> thanks,
>
> greg k-h
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20140903/a9a72f83/attachment.html 


More information about the Kernelnewbies mailing list