kobject-example.c (552c69b36ebd966186573b9c7a286b390935cce1) | kobject-example.c (5a242d8547bdc5802d1e1200a85e69afc3c2d74e) |
---|---|
1// SPDX-License-Identifier: GPL-2.0 2/* 3 * Sample kobject implementation 4 * 5 * Copyright (C) 2004-2007 Greg Kroah-Hartman <greg@kroah.com> 6 * Copyright (C) 2007 Novell Inc. 7 */ 8#include <linux/kobject.h> --- 14 unchanged lines hidden (view full) --- 23static int bar; 24 25/* 26 * The "foo" file where a static variable is read from and written to. 27 */ 28static ssize_t foo_show(struct kobject *kobj, struct kobj_attribute *attr, 29 char *buf) 30{ | 1// SPDX-License-Identifier: GPL-2.0 2/* 3 * Sample kobject implementation 4 * 5 * Copyright (C) 2004-2007 Greg Kroah-Hartman <greg@kroah.com> 6 * Copyright (C) 2007 Novell Inc. 7 */ 8#include <linux/kobject.h> --- 14 unchanged lines hidden (view full) --- 23static int bar; 24 25/* 26 * The "foo" file where a static variable is read from and written to. 27 */ 28static ssize_t foo_show(struct kobject *kobj, struct kobj_attribute *attr, 29 char *buf) 30{ |
31 return sprintf(buf, "%d\n", foo); | 31 return sysfs_emit(buf, "%d\n", foo); |
32} 33 34static ssize_t foo_store(struct kobject *kobj, struct kobj_attribute *attr, 35 const char *buf, size_t count) 36{ 37 int ret; 38 39 ret = kstrtoint(buf, 10, &foo); --- 15 unchanged lines hidden (view full) --- 55 char *buf) 56{ 57 int var; 58 59 if (strcmp(attr->attr.name, "baz") == 0) 60 var = baz; 61 else 62 var = bar; | 32} 33 34static ssize_t foo_store(struct kobject *kobj, struct kobj_attribute *attr, 35 const char *buf, size_t count) 36{ 37 int ret; 38 39 ret = kstrtoint(buf, 10, &foo); --- 15 unchanged lines hidden (view full) --- 55 char *buf) 56{ 57 int var; 58 59 if (strcmp(attr->attr.name, "baz") == 0) 60 var = baz; 61 else 62 var = bar; |
63 return sprintf(buf, "%d\n", var); | 63 return sysfs_emit(buf, "%d\n", var); |
64} 65 66static ssize_t b_store(struct kobject *kobj, struct kobj_attribute *attr, 67 const char *buf, size_t count) 68{ 69 int var, ret; 70 71 ret = kstrtoint(buf, 10, &var); --- 73 unchanged lines hidden --- | 64} 65 66static ssize_t b_store(struct kobject *kobj, struct kobj_attribute *attr, 67 const char *buf, size_t count) 68{ 69 int var, ret; 70 71 ret = kstrtoint(buf, 10, &var); --- 73 unchanged lines hidden --- |