More info about kobj_attribute store and show functions
Jeff Haran
Jeff.Haran at citrix.com
Wed Sep 3 21:30:38 EDT 2014
From: kernelnewbies-bounces+jharan=bytemobile.com at kernelnewbies.org [mailto:kernelnewbies-bounces+jharan=bytemobile.com at kernelnewbies.org] On Behalf Of Lucas Tanure
Sent: Wednesday, September 03, 2014 5:11 PM
To: kernelnewbies
Subject: Re: More info about kobj_attribute store and show functions
(Forget the last e-mail, please, stupid Gmail)
Hi,
I'm looking for some information about :
struct kobj_attribute {
struct attribute attr;
ssize_t (*show)(struct kobject *kobj, struct kobj_attribute *attr, char *buf);
ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count);
};
My function to handle the operation:
static ssize_t my_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count) {
char *buffer;
buffer = (char*) kcalloc(count, sizeof(char), GFP_KERNEL);
copy_from_user(buffer, buf, count);
.....
.....
etc....
}
So, this const char *buf, where ti come from ? Kernel space?
My copy_from_user it's not working. Should return zero.
There any Macro or function to test if the pointer buf is a kernel pointer ?
Thanks
Lucas Tanure
I haven’t written too many of these things, but the last time I wrote a store function I didn’t need to do the copy_to_user().
buf seemed to point to directly accessible kernel memory. I would think a simple memcpy above would do the trick.
Jeff
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20140904/77a444f4/attachment-0001.html
More information about the Kernelnewbies
mailing list