Skip to content
Snippets Groups Projects
Commit 968212e0 authored by James Morse's avatar James Morse
Browse files

debugfs: Add helpers for creating cpumask entries in debugfs


debugfs has handy helpers to make a bool, integer or string available
through debugfs. Add helpers to do the same for cpumasks. These are
read only.

Signed-off-by: default avatarJames Morse <james.morse@arm.com>
parent 611d9a95
No related branches found
No related tags found
No related merge requests found
...@@ -957,6 +957,89 @@ void debugfs_create_str(const char *name, umode_t mode, ...@@ -957,6 +957,89 @@ void debugfs_create_str(const char *name, umode_t mode,
&fops_str_ro, &fops_str_wo); &fops_str_ro, &fops_str_wo);
} }
ssize_t debugfs_read_file_cpumask(struct file *file, char __user *user_buf,
size_t count, loff_t *ppos)
{
struct dentry *dentry = F_DENTRY(file);
struct cpumask *cpumask;
char *kernel_buf;
ssize_t ret;
int len;
ret = debugfs_file_get(dentry);
if (unlikely(ret))
return ret;
/* How long is a piece of string? */
kernel_buf = kmalloc(PAGE_SIZE, GFP_KERNEL);
if (!kernel_buf) {
debugfs_file_put(dentry);
return -ENOMEM;
}
cpumask = (struct cpumask *)file->private_data;
len = scnprintf(kernel_buf, PAGE_SIZE,
"%*pb\n", cpumask_pr_args(cpumask));
debugfs_file_put(dentry);
if (len + 1 >= PAGE_SIZE) {
kfree(kernel_buf);
return -EIO;
}
ret = simple_read_from_buffer(user_buf, count, ppos, kernel_buf, len);
kfree(kernel_buf);
return ret;
}
static const struct file_operations fops_cpumask = {
.read = debugfs_read_file_cpumask,
.write = debugfs_write_file_str,
.open = simple_open,
.llseek = default_llseek,
};
static const struct file_operations fops_cpumask_ro = {
.read = debugfs_read_file_cpumask,
.open = simple_open,
.llseek = default_llseek,
};
static const struct file_operations fops_cpumask_wo = {
.write = debugfs_write_file_str,
.open = simple_open,
.llseek = default_llseek,
};
/**
* debugfs_create_cpumask - create a debugfs file that is used to read a cpumask
* @name: a pointer to a string containing the name of the file to create.
* @mode: the permission that the file should have
* @parent: a pointer to the parent dentry for this file. This should be a
* directory dentry if set. If this parameter is %NULL, then the
* file will be created in the root of the debugfs filesystem.
* @value: a pointer to the variable that the file should read from.
*
* This function creates a file in debugfs with the given name that
* contains the value of the variable @value. If the @mode variable is so
* set, it can be read from, and written to.
*
* This function will return a pointer to a dentry if it succeeds. This
* pointer must be passed to the debugfs_remove() function when the file is
* to be removed (no automatic cleanup happens if your module is unloaded,
* you are responsible here.) If an error occurs, ERR_PTR(-ERROR) will be
* returned.
*
* If debugfs is not enabled in the kernel, the value ERR_PTR(-ENODEV) will
* be returned.
*/
void debugfs_create_cpumask(const char *name, umode_t mode,
struct dentry *parent, struct cpumask *value)
{
debugfs_create_mode_unsafe(name, mode, parent, value, &fops_cpumask,
&fops_cpumask_ro, &fops_cpumask_wo);
}
static ssize_t read_file_blob(struct file *file, char __user *user_buf, static ssize_t read_file_blob(struct file *file, char __user *user_buf,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
......
...@@ -140,6 +140,8 @@ void debugfs_create_bool(const char *name, umode_t mode, struct dentry *parent, ...@@ -140,6 +140,8 @@ void debugfs_create_bool(const char *name, umode_t mode, struct dentry *parent,
bool *value); bool *value);
void debugfs_create_str(const char *name, umode_t mode, void debugfs_create_str(const char *name, umode_t mode,
struct dentry *parent, char **value); struct dentry *parent, char **value);
void debugfs_create_cpumask(const char *name, umode_t mode,
struct dentry *parent, struct cpumask *value);
struct dentry *debugfs_create_blob(const char *name, umode_t mode, struct dentry *debugfs_create_blob(const char *name, umode_t mode,
struct dentry *parent, struct dentry *parent,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment