Commit 8447891fe845851738439788c74b3c811578e3f9

Authored by Michael Ellerman
Committed by Greg Kroah-Hartman
1 parent 3106d46f51

debugfs: Add debugfs_create_u64()

I went to use this the other day, only to find it didn't exist.

It's a straight copy of the debugfs u32 code, then s/u32/u64/. A quick
test shows it seems to be working.

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

Showing 2 changed files with 51 additions and 0 deletions Side-by-side Diff

... ... @@ -179,6 +179,48 @@
179 179 }
180 180 EXPORT_SYMBOL_GPL(debugfs_create_u32);
181 181  
  182 +static void debugfs_u64_set(void *data, u64 val)
  183 +{
  184 + *(u64 *)data = val;
  185 +}
  186 +
  187 +static u64 debugfs_u64_get(void *data)
  188 +{
  189 + return *(u64 *)data;
  190 +}
  191 +DEFINE_SIMPLE_ATTRIBUTE(fops_u64, debugfs_u64_get, debugfs_u64_set, "%llu\n");
  192 +
  193 +/**
  194 + * debugfs_create_u64 - create a debugfs file that is used to read and write an unsigned 64-bit value
  195 + * @name: a pointer to a string containing the name of the file to create.
  196 + * @mode: the permission that the file should have
  197 + * @parent: a pointer to the parent dentry for this file. This should be a
  198 + * directory dentry if set. If this parameter is %NULL, then the
  199 + * file will be created in the root of the debugfs filesystem.
  200 + * @value: a pointer to the variable that the file should read to and write
  201 + * from.
  202 + *
  203 + * This function creates a file in debugfs with the given name that
  204 + * contains the value of the variable @value. If the @mode variable is so
  205 + * set, it can be read from, and written to.
  206 + *
  207 + * This function will return a pointer to a dentry if it succeeds. This
  208 + * pointer must be passed to the debugfs_remove() function when the file is
  209 + * to be removed (no automatic cleanup happens if your module is unloaded,
  210 + * you are responsible here.) If an error occurs, %NULL will be returned.
  211 + *
  212 + * If debugfs is not enabled in the kernel, the value -%ENODEV will be
  213 + * returned. It is not wise to check for this value, but rather, check for
  214 + * %NULL or !%NULL instead as to eliminate the need for #ifdef in the calling
  215 + * code.
  216 + */
  217 +struct dentry *debugfs_create_u64(const char *name, mode_t mode,
  218 + struct dentry *parent, u64 *value)
  219 +{
  220 + return debugfs_create_file(name, mode, parent, value, &fops_u64);
  221 +}
  222 +EXPORT_SYMBOL_GPL(debugfs_create_u64);
  223 +
182 224 static ssize_t read_file_bool(struct file *file, char __user *user_buf,
183 225 size_t count, loff_t *ppos)
184 226 {
include/linux/debugfs.h
... ... @@ -44,6 +44,8 @@
44 44 struct dentry *parent, u16 *value);
45 45 struct dentry *debugfs_create_u32(const char *name, mode_t mode,
46 46 struct dentry *parent, u32 *value);
  47 +struct dentry *debugfs_create_u64(const char *name, mode_t mode,
  48 + struct dentry *parent, u64 *value);
47 49 struct dentry *debugfs_create_bool(const char *name, mode_t mode,
48 50 struct dentry *parent, u32 *value);
49 51  
... ... @@ -100,6 +102,13 @@
100 102 static inline struct dentry *debugfs_create_u32(const char *name, mode_t mode,
101 103 struct dentry *parent,
102 104 u32 *value)
  105 +{
  106 + return ERR_PTR(-ENODEV);
  107 +}
  108 +
  109 +static inline struct dentry *debugfs_create_u64(const char *name, mode_t mode,
  110 + struct dentry *parent,
  111 + u64 *value)
103 112 {
104 113 return ERR_PTR(-ENODEV);
105 114 }