static struct dentry *ocd_debugfs_DS;
static struct dentry *ocd_debugfs_count;
-static u64 ocd_DC_get(void *data)
+static int ocd_DC_get(void *data, u64 *val)
{
- return ocd_read(DC);
+ *val = ocd_read(DC);
+ return 0;
}
-static void ocd_DC_set(void *data, u64 val)
+static int ocd_DC_set(void *data, u64 val)
{
ocd_write(DC, val);
+ return 0;
}
DEFINE_SIMPLE_ATTRIBUTE(fops_DC, ocd_DC_get, ocd_DC_set, "0x%08llx\n");
-static u64 ocd_DS_get(void *data)
+static int ocd_DS_get(void *data, u64 *val)
{
- return ocd_read(DS);
+ *val = ocd_read(DS);
+ return 0;
}
DEFINE_SIMPLE_ATTRIBUTE(fops_DS, ocd_DS_get, NULL, "0x%08llx\n");
-static u64 ocd_count_get(void *data)
+static int ocd_count_get(void *data, u64 *val)
{
- return ocd_count;
+ *val = ocd_count;
+ return 0;
}
DEFINE_SIMPLE_ATTRIBUTE(fops_count, ocd_count_get, NULL, "%lld\n");
if (!i->i_openers++)
ctx->cntl = inode->i_mapping;
mutex_unlock(&ctx->mapping_lock);
- return spufs_attr_open(inode, file, spufs_cntl_get,
+ return simple_attr_open(inode, file, spufs_cntl_get,
spufs_cntl_set, "0x%08lx");
}
struct spufs_inode_info *i = SPUFS_I(inode);
struct spu_context *ctx = i->i_ctx;
- spufs_attr_release(inode, file);
+ simple_attr_close(inode, file);
mutex_lock(&ctx->mapping_lock);
if (!--i->i_openers)
static const struct file_operations spufs_cntl_fops = {
.open = spufs_cntl_open,
.release = spufs_cntl_release,
- .read = spufs_attr_read,
- .write = spufs_attr_write,
+ .read = simple_attr_read,
+ .write = simple_attr_write,
.mmap = spufs_cntl_mmap,
};
.follow_link = debugfs_follow_link,
};
-static void debugfs_u8_set(void *data, u64 val)
+static int debugfs_u8_set(void *data, u64 val)
{
*(u8 *)data = val;
+ return 0;
}
-static u64 debugfs_u8_get(void *data)
+static int debugfs_u8_get(void *data, u64 *val)
{
- return *(u8 *)data;
+ *val = *(u8 *)data;
+ return 0;
}
DEFINE_SIMPLE_ATTRIBUTE(fops_u8, debugfs_u8_get, debugfs_u8_set, "%llu\n");
}
EXPORT_SYMBOL_GPL(debugfs_create_u8);
-static void debugfs_u16_set(void *data, u64 val)
+static int debugfs_u16_set(void *data, u64 val)
{
*(u16 *)data = val;
+ return 0;
}
-static u64 debugfs_u16_get(void *data)
+static int debugfs_u16_get(void *data, u64 *val)
{
- return *(u16 *)data;
+ *val = *(u16 *)data;
+ return 0;
}
DEFINE_SIMPLE_ATTRIBUTE(fops_u16, debugfs_u16_get, debugfs_u16_set, "%llu\n");
}
EXPORT_SYMBOL_GPL(debugfs_create_u16);
-static void debugfs_u32_set(void *data, u64 val)
+static int debugfs_u32_set(void *data, u64 val)
{
*(u32 *)data = val;
+ return 0;
}
-static u64 debugfs_u32_get(void *data)
+static int debugfs_u32_get(void *data, u64 *val)
{
- return *(u32 *)data;
+ *val = *(u32 *)data;
+ return 0;
}
DEFINE_SIMPLE_ATTRIBUTE(fops_u32, debugfs_u32_get, debugfs_u32_set, "%llu\n");
}
EXPORT_SYMBOL_GPL(debugfs_create_u32);
-static void debugfs_u64_set(void *data, u64 val)
+static int debugfs_u64_set(void *data, u64 val)
{
*(u64 *)data = val;
+ return 0;
}
-static u64 debugfs_u64_get(void *data)
+static int debugfs_u64_get(void *data, u64 *val)
{
- return *(u64 *)data;
+ *val = *(u64 *)data;
+ return 0;
}
DEFINE_SIMPLE_ATTRIBUTE(fops_u64, debugfs_u64_get, debugfs_u64_set, "%llu\n");
/* Simple attribute files */
struct simple_attr {
- u64 (*get)(void *);
- void (*set)(void *, u64);
+ int (*get)(void *, u64 *);
+ int (*set)(void *, u64);
char get_buf[24]; /* enough to store a u64 and "\n\0" */
char set_buf[24];
void *data;
/* simple_attr_open is called by an actual attribute open file operation
* to set the attribute specific access operations. */
int simple_attr_open(struct inode *inode, struct file *file,
- u64 (*get)(void *), void (*set)(void *, u64),
+ int (*get)(void *, u64 *), int (*set)(void *, u64),
const char *fmt)
{
struct simple_attr *attr;
return -EACCES;
mutex_lock(&attr->mutex);
- if (*ppos) /* continued read */
+ if (*ppos) { /* continued read */
size = strlen(attr->get_buf);
- else /* first read */
+ } else { /* first read */
+ u64 val;
+ ret = attr->get(attr->data, &val);
+ if (ret)
+ goto out;
+
size = scnprintf(attr->get_buf, sizeof(attr->get_buf),
- attr->fmt,
- (unsigned long long)attr->get(attr->data));
+ attr->fmt, (unsigned long long)val);
+ }
ret = simple_read_from_buffer(buf, len, ppos, attr->get_buf, size);
+out:
mutex_unlock(&attr->mutex);
return ret;
}
ssize_t ret;
attr = file->private_data;
-
if (!attr->set)
return -EACCES;
}
int simple_attr_open(struct inode *inode, struct file *file,
- u64 (*get)(void *), void (*set)(void *, u64),
+ int (*get)(void *, u64 *), int (*set)(void *, u64),
const char *fmt);
int simple_attr_close(struct inode *inode, struct file *file);
ssize_t simple_attr_read(struct file *file, char __user *buf,
#ifdef CONFIG_FAULT_INJECTION_DEBUG_FS
-static void debugfs_ul_set(void *data, u64 val)
+static int debugfs_ul_set(void *data, u64 val)
{
*(unsigned long *)data = val;
+ return 0;
}
#ifdef CONFIG_FAULT_INJECTION_STACKTRACE_FILTER
-static void debugfs_ul_set_MAX_STACK_TRACE_DEPTH(void *data, u64 val)
+static int debugfs_ul_set_MAX_STACK_TRACE_DEPTH(void *data, u64 val)
{
*(unsigned long *)data =
val < MAX_STACK_TRACE_DEPTH ?
val : MAX_STACK_TRACE_DEPTH;
+ return 0;
}
#endif /* CONFIG_FAULT_INJECTION_STACKTRACE_FILTER */
-static u64 debugfs_ul_get(void *data)
+static int debugfs_ul_get(void *data, u64 *val)
{
- return *(unsigned long *)data;
+ *val = *(unsigned long *)data;
+ return 0;
}
DEFINE_SIMPLE_ATTRIBUTE(fops_ul, debugfs_ul_get, debugfs_ul_set, "%llu\n");
}
#endif /* CONFIG_FAULT_INJECTION_STACKTRACE_FILTER */
-static void debugfs_atomic_t_set(void *data, u64 val)
+static int debugfs_atomic_t_set(void *data, u64 val)
{
atomic_set((atomic_t *)data, val);
+ return 0;
}
-static u64 debugfs_atomic_t_get(void *data)
+static int debugfs_atomic_t_get(void *data, u64 *val)
{
- return atomic_read((atomic_t *)data);
+ *val = atomic_read((atomic_t *)data);
+ return 0;
}
DEFINE_SIMPLE_ATTRIBUTE(fops_atomic_t, debugfs_atomic_t_get,
.priority = 20, /* must be > scheduler priority */
};
-static u64 vm_stat_get(void *_offset)
+static int vm_stat_get(void *_offset, u64 *val)
{
unsigned offset = (long)_offset;
- u64 total = 0;
struct kvm *kvm;
+ *val = 0;
spin_lock(&kvm_lock);
list_for_each_entry(kvm, &vm_list, vm_list)
- total += *(u32 *)((void *)kvm + offset);
+ *val += *(u32 *)((void *)kvm + offset);
spin_unlock(&kvm_lock);
- return total;
+ return 0;
}
DEFINE_SIMPLE_ATTRIBUTE(vm_stat_fops, vm_stat_get, NULL, "%llu\n");
-static u64 vcpu_stat_get(void *_offset)
+static int vcpu_stat_get(void *_offset, u64 *val)
{
unsigned offset = (long)_offset;
- u64 total = 0;
struct kvm *kvm;
struct kvm_vcpu *vcpu;
int i;
+ *val = 0;
spin_lock(&kvm_lock);
list_for_each_entry(kvm, &vm_list, vm_list)
for (i = 0; i < KVM_MAX_VCPUS; ++i) {
vcpu = kvm->vcpus[i];
if (vcpu)
- total += *(u32 *)((void *)vcpu + offset);
+ *val += *(u32 *)((void *)vcpu + offset);
}
spin_unlock(&kvm_lock);
- return total;
+ return 0;
}
DEFINE_SIMPLE_ATTRIBUTE(vcpu_stat_fops, vcpu_stat_get, NULL, "%llu\n");