diff options
Diffstat (limited to 'fs')
-rw-r--r-- | fs/debugfs/file.c | 32 | ||||
-rw-r--r-- | fs/libfs.c | 21 |
2 files changed, 33 insertions, 20 deletions
diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c index fa6b7f7ff914..fddffe4851f5 100644 --- a/fs/debugfs/file.c +++ b/fs/debugfs/file.c | |||
@@ -56,13 +56,15 @@ const struct inode_operations debugfs_link_operations = { | |||
56 | .follow_link = debugfs_follow_link, | 56 | .follow_link = debugfs_follow_link, |
57 | }; | 57 | }; |
58 | 58 | ||
59 | static void debugfs_u8_set(void *data, u64 val) | 59 | static int debugfs_u8_set(void *data, u64 val) |
60 | { | 60 | { |
61 | *(u8 *)data = val; | 61 | *(u8 *)data = val; |
62 | return 0; | ||
62 | } | 63 | } |
63 | static u64 debugfs_u8_get(void *data) | 64 | static int debugfs_u8_get(void *data, u64 *val) |
64 | { | 65 | { |
65 | return *(u8 *)data; | 66 | *val = *(u8 *)data; |
67 | return 0; | ||
66 | } | 68 | } |
67 | DEFINE_SIMPLE_ATTRIBUTE(fops_u8, debugfs_u8_get, debugfs_u8_set, "%llu\n"); | 69 | DEFINE_SIMPLE_ATTRIBUTE(fops_u8, debugfs_u8_get, debugfs_u8_set, "%llu\n"); |
68 | 70 | ||
@@ -97,13 +99,15 @@ struct dentry *debugfs_create_u8(const char *name, mode_t mode, | |||
97 | } | 99 | } |
98 | EXPORT_SYMBOL_GPL(debugfs_create_u8); | 100 | EXPORT_SYMBOL_GPL(debugfs_create_u8); |
99 | 101 | ||
100 | static void debugfs_u16_set(void *data, u64 val) | 102 | static int debugfs_u16_set(void *data, u64 val) |
101 | { | 103 | { |
102 | *(u16 *)data = val; | 104 | *(u16 *)data = val; |
105 | return 0; | ||
103 | } | 106 | } |
104 | static u64 debugfs_u16_get(void *data) | 107 | static int debugfs_u16_get(void *data, u64 *val) |
105 | { | 108 | { |
106 | return *(u16 *)data; | 109 | *val = *(u16 *)data; |
110 | return 0; | ||
107 | } | 111 | } |
108 | DEFINE_SIMPLE_ATTRIBUTE(fops_u16, debugfs_u16_get, debugfs_u16_set, "%llu\n"); | 112 | DEFINE_SIMPLE_ATTRIBUTE(fops_u16, debugfs_u16_get, debugfs_u16_set, "%llu\n"); |
109 | 113 | ||
@@ -138,13 +142,15 @@ struct dentry *debugfs_create_u16(const char *name, mode_t mode, | |||
138 | } | 142 | } |
139 | EXPORT_SYMBOL_GPL(debugfs_create_u16); | 143 | EXPORT_SYMBOL_GPL(debugfs_create_u16); |
140 | 144 | ||
141 | static void debugfs_u32_set(void *data, u64 val) | 145 | static int debugfs_u32_set(void *data, u64 val) |
142 | { | 146 | { |
143 | *(u32 *)data = val; | 147 | *(u32 *)data = val; |
148 | return 0; | ||
144 | } | 149 | } |
145 | static u64 debugfs_u32_get(void *data) | 150 | static int debugfs_u32_get(void *data, u64 *val) |
146 | { | 151 | { |
147 | return *(u32 *)data; | 152 | *val = *(u32 *)data; |
153 | return 0; | ||
148 | } | 154 | } |
149 | DEFINE_SIMPLE_ATTRIBUTE(fops_u32, debugfs_u32_get, debugfs_u32_set, "%llu\n"); | 155 | DEFINE_SIMPLE_ATTRIBUTE(fops_u32, debugfs_u32_get, debugfs_u32_set, "%llu\n"); |
150 | 156 | ||
@@ -179,14 +185,16 @@ struct dentry *debugfs_create_u32(const char *name, mode_t mode, | |||
179 | } | 185 | } |
180 | EXPORT_SYMBOL_GPL(debugfs_create_u32); | 186 | EXPORT_SYMBOL_GPL(debugfs_create_u32); |
181 | 187 | ||
182 | static void debugfs_u64_set(void *data, u64 val) | 188 | static int debugfs_u64_set(void *data, u64 val) |
183 | { | 189 | { |
184 | *(u64 *)data = val; | 190 | *(u64 *)data = val; |
191 | return 0; | ||
185 | } | 192 | } |
186 | 193 | ||
187 | static u64 debugfs_u64_get(void *data) | 194 | static int debugfs_u64_get(void *data, u64 *val) |
188 | { | 195 | { |
189 | return *(u64 *)data; | 196 | *val = *(u64 *)data; |
197 | return 0; | ||
190 | } | 198 | } |
191 | DEFINE_SIMPLE_ATTRIBUTE(fops_u64, debugfs_u64_get, debugfs_u64_set, "%llu\n"); | 199 | DEFINE_SIMPLE_ATTRIBUTE(fops_u64, debugfs_u64_get, debugfs_u64_set, "%llu\n"); |
192 | 200 | ||
diff --git a/fs/libfs.c b/fs/libfs.c index 5523bde96387..2319415ddb5e 100644 --- a/fs/libfs.c +++ b/fs/libfs.c | |||
@@ -583,8 +583,8 @@ int simple_transaction_release(struct inode *inode, struct file *file) | |||
583 | /* Simple attribute files */ | 583 | /* Simple attribute files */ |
584 | 584 | ||
585 | struct simple_attr { | 585 | struct simple_attr { |
586 | u64 (*get)(void *); | 586 | int (*get)(void *, u64 *); |
587 | void (*set)(void *, u64); | 587 | int (*set)(void *, u64); |
588 | char get_buf[24]; /* enough to store a u64 and "\n\0" */ | 588 | char get_buf[24]; /* enough to store a u64 and "\n\0" */ |
589 | char set_buf[24]; | 589 | char set_buf[24]; |
590 | void *data; | 590 | void *data; |
@@ -595,7 +595,7 @@ struct simple_attr { | |||
595 | /* simple_attr_open is called by an actual attribute open file operation | 595 | /* simple_attr_open is called by an actual attribute open file operation |
596 | * to set the attribute specific access operations. */ | 596 | * to set the attribute specific access operations. */ |
597 | int simple_attr_open(struct inode *inode, struct file *file, | 597 | int simple_attr_open(struct inode *inode, struct file *file, |
598 | u64 (*get)(void *), void (*set)(void *, u64), | 598 | int (*get)(void *, u64 *), int (*set)(void *, u64), |
599 | const char *fmt) | 599 | const char *fmt) |
600 | { | 600 | { |
601 | struct simple_attr *attr; | 601 | struct simple_attr *attr; |
@@ -635,14 +635,20 @@ ssize_t simple_attr_read(struct file *file, char __user *buf, | |||
635 | return -EACCES; | 635 | return -EACCES; |
636 | 636 | ||
637 | mutex_lock(&attr->mutex); | 637 | mutex_lock(&attr->mutex); |
638 | if (*ppos) /* continued read */ | 638 | if (*ppos) { /* continued read */ |
639 | size = strlen(attr->get_buf); | 639 | size = strlen(attr->get_buf); |
640 | else /* first read */ | 640 | } else { /* first read */ |
641 | u64 val; | ||
642 | ret = attr->get(attr->data, &val); | ||
643 | if (ret) | ||
644 | goto out; | ||
645 | |||
641 | size = scnprintf(attr->get_buf, sizeof(attr->get_buf), | 646 | size = scnprintf(attr->get_buf, sizeof(attr->get_buf), |
642 | attr->fmt, | 647 | attr->fmt, (unsigned long long)val); |
643 | (unsigned long long)attr->get(attr->data)); | 648 | } |
644 | 649 | ||
645 | ret = simple_read_from_buffer(buf, len, ppos, attr->get_buf, size); | 650 | ret = simple_read_from_buffer(buf, len, ppos, attr->get_buf, size); |
651 | out: | ||
646 | mutex_unlock(&attr->mutex); | 652 | mutex_unlock(&attr->mutex); |
647 | return ret; | 653 | return ret; |
648 | } | 654 | } |
@@ -657,7 +663,6 @@ ssize_t simple_attr_write(struct file *file, const char __user *buf, | |||
657 | ssize_t ret; | 663 | ssize_t ret; |
658 | 664 | ||
659 | attr = file->private_data; | 665 | attr = file->private_data; |
660 | |||
661 | if (!attr->set) | 666 | if (!attr->set) |
662 | return -EACCES; | 667 | return -EACCES; |
663 | 668 | ||