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