aboutsummaryrefslogtreecommitdiffstats
path: root/fs/debugfs
diff options
context:
space:
mode:
authorStephen Boyd <sboyd@codeaurora.org>2015-10-12 21:09:09 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2015-10-18 01:09:03 -0400
commitb97f679954b7771183f3c0a6a47b17e185e64a8a (patch)
tree0b91b510adba6a9c2016e603ea1fb624164a3eac /fs/debugfs
parent8346aa765e14348b7b436825b3c4740895a2fe1a (diff)
debugfs: Consolidate file mode checks in debugfs_create_*()
The code that creates debugfs file with different file ops based on the file mode is duplicated in each debugfs_create_*() API. Consolidate that code into debugfs_create_mode(), that takes three file ops structures so that we don't have to keep copy/pasting that logic. Signed-off-by: Stephen Boyd <sboyd@codeaurora.org> Reviewed-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'fs/debugfs')
-rw-r--r--fs/debugfs/file.c98
1 files changed, 32 insertions, 66 deletions
diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c
index b70c20fae502..5d594efa7c93 100644
--- a/fs/debugfs/file.c
+++ b/fs/debugfs/file.c
@@ -42,6 +42,22 @@ const struct file_operations debugfs_file_operations = {
42 .llseek = noop_llseek, 42 .llseek = noop_llseek,
43}; 43};
44 44
45static struct dentry *debugfs_create_mode(const char *name, umode_t mode,
46 struct dentry *parent, void *value,
47 const struct file_operations *fops,
48 const struct file_operations *fops_ro,
49 const struct file_operations *fops_wo)
50{
51 /* if there are no write bits set, make read only */
52 if (!(mode & S_IWUGO))
53 return debugfs_create_file(name, mode, parent, value, fops_ro);
54 /* if there are no read bits set, make write only */
55 if (!(mode & S_IRUGO))
56 return debugfs_create_file(name, mode, parent, value, fops_wo);
57
58 return debugfs_create_file(name, mode, parent, value, fops);
59}
60
45static int debugfs_u8_set(void *data, u64 val) 61static int debugfs_u8_set(void *data, u64 val)
46{ 62{
47 *(u8 *)data = val; 63 *(u8 *)data = val;
@@ -83,14 +99,8 @@ DEFINE_SIMPLE_ATTRIBUTE(fops_u8_wo, NULL, debugfs_u8_set, "%llu\n");
83struct dentry *debugfs_create_u8(const char *name, umode_t mode, 99struct dentry *debugfs_create_u8(const char *name, umode_t mode,
84 struct dentry *parent, u8 *value) 100 struct dentry *parent, u8 *value)
85{ 101{
86 /* if there are no write bits set, make read only */ 102 return debugfs_create_mode(name, mode, parent, value, &fops_u8,
87 if (!(mode & S_IWUGO)) 103 &fops_u8_ro, &fops_u8_wo);
88 return debugfs_create_file(name, mode, parent, value, &fops_u8_ro);
89 /* if there are no read bits set, make write only */
90 if (!(mode & S_IRUGO))
91 return debugfs_create_file(name, mode, parent, value, &fops_u8_wo);
92
93 return debugfs_create_file(name, mode, parent, value, &fops_u8);
94} 104}
95EXPORT_SYMBOL_GPL(debugfs_create_u8); 105EXPORT_SYMBOL_GPL(debugfs_create_u8);
96 106
@@ -135,14 +145,8 @@ DEFINE_SIMPLE_ATTRIBUTE(fops_u16_wo, NULL, debugfs_u16_set, "%llu\n");
135struct dentry *debugfs_create_u16(const char *name, umode_t mode, 145struct dentry *debugfs_create_u16(const char *name, umode_t mode,
136 struct dentry *parent, u16 *value) 146 struct dentry *parent, u16 *value)
137{ 147{
138 /* if there are no write bits set, make read only */ 148 return debugfs_create_mode(name, mode, parent, value, &fops_u16,
139 if (!(mode & S_IWUGO)) 149 &fops_u16_ro, &fops_u16_wo);
140 return debugfs_create_file(name, mode, parent, value, &fops_u16_ro);
141 /* if there are no read bits set, make write only */
142 if (!(mode & S_IRUGO))
143 return debugfs_create_file(name, mode, parent, value, &fops_u16_wo);
144
145 return debugfs_create_file(name, mode, parent, value, &fops_u16);
146} 150}
147EXPORT_SYMBOL_GPL(debugfs_create_u16); 151EXPORT_SYMBOL_GPL(debugfs_create_u16);
148 152
@@ -187,14 +191,8 @@ DEFINE_SIMPLE_ATTRIBUTE(fops_u32_wo, NULL, debugfs_u32_set, "%llu\n");
187struct dentry *debugfs_create_u32(const char *name, umode_t mode, 191struct dentry *debugfs_create_u32(const char *name, umode_t mode,
188 struct dentry *parent, u32 *value) 192 struct dentry *parent, u32 *value)
189{ 193{
190 /* if there are no write bits set, make read only */ 194 return debugfs_create_mode(name, mode, parent, value, &fops_u32,
191 if (!(mode & S_IWUGO)) 195 &fops_u32_ro, &fops_u32_wo);
192 return debugfs_create_file(name, mode, parent, value, &fops_u32_ro);
193 /* if there are no read bits set, make write only */
194 if (!(mode & S_IRUGO))
195 return debugfs_create_file(name, mode, parent, value, &fops_u32_wo);
196
197 return debugfs_create_file(name, mode, parent, value, &fops_u32);
198} 196}
199EXPORT_SYMBOL_GPL(debugfs_create_u32); 197EXPORT_SYMBOL_GPL(debugfs_create_u32);
200 198
@@ -240,14 +238,8 @@ DEFINE_SIMPLE_ATTRIBUTE(fops_u64_wo, NULL, debugfs_u64_set, "%llu\n");
240struct dentry *debugfs_create_u64(const char *name, umode_t mode, 238struct dentry *debugfs_create_u64(const char *name, umode_t mode,
241 struct dentry *parent, u64 *value) 239 struct dentry *parent, u64 *value)
242{ 240{
243 /* if there are no write bits set, make read only */ 241 return debugfs_create_mode(name, mode, parent, value, &fops_u64,
244 if (!(mode & S_IWUGO)) 242 &fops_u64_ro, &fops_u64_wo);
245 return debugfs_create_file(name, mode, parent, value, &fops_u64_ro);
246 /* if there are no read bits set, make write only */
247 if (!(mode & S_IRUGO))
248 return debugfs_create_file(name, mode, parent, value, &fops_u64_wo);
249
250 return debugfs_create_file(name, mode, parent, value, &fops_u64);
251} 243}
252EXPORT_SYMBOL_GPL(debugfs_create_u64); 244EXPORT_SYMBOL_GPL(debugfs_create_u64);
253 245
@@ -286,14 +278,8 @@ DEFINE_SIMPLE_ATTRIBUTE(fops_x64, debugfs_u64_get, debugfs_u64_set, "0x%016llx\n
286struct dentry *debugfs_create_x8(const char *name, umode_t mode, 278struct dentry *debugfs_create_x8(const char *name, umode_t mode,
287 struct dentry *parent, u8 *value) 279 struct dentry *parent, u8 *value)
288{ 280{
289 /* if there are no write bits set, make read only */ 281 return debugfs_create_mode(name, mode, parent, value, &fops_x8,
290 if (!(mode & S_IWUGO)) 282 &fops_x8_ro, &fops_x8_wo);
291 return debugfs_create_file(name, mode, parent, value, &fops_x8_ro);
292 /* if there are no read bits set, make write only */
293 if (!(mode & S_IRUGO))
294 return debugfs_create_file(name, mode, parent, value, &fops_x8_wo);
295
296 return debugfs_create_file(name, mode, parent, value, &fops_x8);
297} 283}
298EXPORT_SYMBOL_GPL(debugfs_create_x8); 284EXPORT_SYMBOL_GPL(debugfs_create_x8);
299 285
@@ -310,14 +296,8 @@ EXPORT_SYMBOL_GPL(debugfs_create_x8);
310struct dentry *debugfs_create_x16(const char *name, umode_t mode, 296struct dentry *debugfs_create_x16(const char *name, umode_t mode,
311 struct dentry *parent, u16 *value) 297 struct dentry *parent, u16 *value)
312{ 298{
313 /* if there are no write bits set, make read only */ 299 return debugfs_create_mode(name, mode, parent, value, &fops_x16,
314 if (!(mode & S_IWUGO)) 300 &fops_x16_ro, &fops_x16_wo);
315 return debugfs_create_file(name, mode, parent, value, &fops_x16_ro);
316 /* if there are no read bits set, make write only */
317 if (!(mode & S_IRUGO))
318 return debugfs_create_file(name, mode, parent, value, &fops_x16_wo);
319
320 return debugfs_create_file(name, mode, parent, value, &fops_x16);
321} 301}
322EXPORT_SYMBOL_GPL(debugfs_create_x16); 302EXPORT_SYMBOL_GPL(debugfs_create_x16);
323 303
@@ -334,14 +314,8 @@ EXPORT_SYMBOL_GPL(debugfs_create_x16);
334struct dentry *debugfs_create_x32(const char *name, umode_t mode, 314struct dentry *debugfs_create_x32(const char *name, umode_t mode,
335 struct dentry *parent, u32 *value) 315 struct dentry *parent, u32 *value)
336{ 316{
337 /* if there are no write bits set, make read only */ 317 return debugfs_create_mode(name, mode, parent, value, &fops_x32,
338 if (!(mode & S_IWUGO)) 318 &fops_x32_ro, &fops_x32_wo);
339 return debugfs_create_file(name, mode, parent, value, &fops_x32_ro);
340 /* if there are no read bits set, make write only */
341 if (!(mode & S_IRUGO))
342 return debugfs_create_file(name, mode, parent, value, &fops_x32_wo);
343
344 return debugfs_create_file(name, mode, parent, value, &fops_x32);
345} 319}
346EXPORT_SYMBOL_GPL(debugfs_create_x32); 320EXPORT_SYMBOL_GPL(debugfs_create_x32);
347 321
@@ -422,16 +396,8 @@ DEFINE_SIMPLE_ATTRIBUTE(fops_atomic_t_wo, NULL, debugfs_atomic_t_set, "%lld\n");
422struct dentry *debugfs_create_atomic_t(const char *name, umode_t mode, 396struct dentry *debugfs_create_atomic_t(const char *name, umode_t mode,
423 struct dentry *parent, atomic_t *value) 397 struct dentry *parent, atomic_t *value)
424{ 398{
425 /* if there are no write bits set, make read only */ 399 return debugfs_create_mode(name, mode, parent, value, &fops_atomic_t,
426 if (!(mode & S_IWUGO)) 400 &fops_atomic_t_ro, &fops_atomic_t_wo);
427 return debugfs_create_file(name, mode, parent, value,
428 &fops_atomic_t_ro);
429 /* if there are no read bits set, make write only */
430 if (!(mode & S_IRUGO))
431 return debugfs_create_file(name, mode, parent, value,
432 &fops_atomic_t_wo);
433
434 return debugfs_create_file(name, mode, parent, value, &fops_atomic_t);
435} 401}
436EXPORT_SYMBOL_GPL(debugfs_create_atomic_t); 402EXPORT_SYMBOL_GPL(debugfs_create_atomic_t);
437 403