kobject-example.c (5e2aa2ed08e2e280121dc7cf5609c87d464f12ef) | kobject-example.c (5fd637e7a75fb2a4c0b62683c08dae959160fedf) |
---|---|
1/* 2 * Sample kobject implementation 3 * 4 * Copyright (C) 2004-2007 Greg Kroah-Hartman <greg@kroah.com> 5 * Copyright (C) 2007 Novell Inc. 6 * 7 * Released under the GPL version 2 only. 8 * --- 22 unchanged lines hidden (view full) --- 31 char *buf) 32{ 33 return sprintf(buf, "%d\n", foo); 34} 35 36static ssize_t foo_store(struct kobject *kobj, struct kobj_attribute *attr, 37 const char *buf, size_t count) 38{ | 1/* 2 * Sample kobject implementation 3 * 4 * Copyright (C) 2004-2007 Greg Kroah-Hartman <greg@kroah.com> 5 * Copyright (C) 2007 Novell Inc. 6 * 7 * Released under the GPL version 2 only. 8 * --- 22 unchanged lines hidden (view full) --- 31 char *buf) 32{ 33 return sprintf(buf, "%d\n", foo); 34} 35 36static ssize_t foo_store(struct kobject *kobj, struct kobj_attribute *attr, 37 const char *buf, size_t count) 38{ |
39 sscanf(buf, "%du", &foo); | 39 int ret; 40 41 ret = kstrtoint(buf, 10, &foo); 42 if (ret < 0) 43 return ret; 44 |
40 return count; 41} 42 43/* Sysfs attributes cannot be world-writable. */ 44static struct kobj_attribute foo_attribute = 45 __ATTR(foo, 0664, foo_show, foo_store); 46 47/* --- 10 unchanged lines hidden (view full) --- 58 else 59 var = bar; 60 return sprintf(buf, "%d\n", var); 61} 62 63static ssize_t b_store(struct kobject *kobj, struct kobj_attribute *attr, 64 const char *buf, size_t count) 65{ | 45 return count; 46} 47 48/* Sysfs attributes cannot be world-writable. */ 49static struct kobj_attribute foo_attribute = 50 __ATTR(foo, 0664, foo_show, foo_store); 51 52/* --- 10 unchanged lines hidden (view full) --- 63 else 64 var = bar; 65 return sprintf(buf, "%d\n", var); 66} 67 68static ssize_t b_store(struct kobject *kobj, struct kobj_attribute *attr, 69 const char *buf, size_t count) 70{ |
66 int var; | 71 int var, ret; |
67 | 72 |
68 sscanf(buf, "%du", &var); | 73 ret = kstrtoint(buf, 10, &var); 74 if (ret < 0) 75 return ret; 76 |
69 if (strcmp(attr->attr.name, "baz") == 0) 70 baz = var; 71 else 72 bar = var; 73 return count; 74} 75 76static struct kobj_attribute baz_attribute = --- 62 unchanged lines hidden --- | 77 if (strcmp(attr->attr.name, "baz") == 0) 78 baz = var; 79 else 80 bar = var; 81 return count; 82} 83 84static struct kobj_attribute baz_attribute = --- 62 unchanged lines hidden --- |