Commit 4fdaa7b6 authored by Robert Richter's avatar Robert Richter

oprofile: Remove duplicate code around __oprofilefs_create_file()

Removing duplicate code by assigning the inodes private data pointer
in __oprofilefs_create_file(). Extending the function interface to
pass the pointer.
Signed-off-by: default avatarRobert Richter <robert.richter@amd.com>
parent dc0c22b8
...@@ -126,50 +126,41 @@ static const struct file_operations ulong_ro_fops = { ...@@ -126,50 +126,41 @@ static const struct file_operations ulong_ro_fops = {
}; };
static struct dentry *__oprofilefs_create_file(struct super_block *sb, static int __oprofilefs_create_file(struct super_block *sb,
struct dentry *root, char const *name, const struct file_operations *fops, struct dentry *root, char const *name, const struct file_operations *fops,
int perm) int perm, void *priv)
{ {
struct dentry *dentry; struct dentry *dentry;
struct inode *inode; struct inode *inode;
dentry = d_alloc_name(root, name); dentry = d_alloc_name(root, name);
if (!dentry) if (!dentry)
return NULL; return -ENOMEM;
inode = oprofilefs_get_inode(sb, S_IFREG | perm); inode = oprofilefs_get_inode(sb, S_IFREG | perm);
if (!inode) { if (!inode) {
dput(dentry); dput(dentry);
return NULL; return -ENOMEM;
} }
inode->i_fop = fops; inode->i_fop = fops;
d_add(dentry, inode); d_add(dentry, inode);
return dentry; dentry->d_inode->i_private = priv;
return 0;
} }
int oprofilefs_create_ulong(struct super_block *sb, struct dentry *root, int oprofilefs_create_ulong(struct super_block *sb, struct dentry *root,
char const *name, unsigned long *val) char const *name, unsigned long *val)
{ {
struct dentry *d = __oprofilefs_create_file(sb, root, name, return __oprofilefs_create_file(sb, root, name,
&ulong_fops, 0644); &ulong_fops, 0644, val);
if (!d)
return -EFAULT;
d->d_inode->i_private = val;
return 0;
} }
int oprofilefs_create_ro_ulong(struct super_block *sb, struct dentry *root, int oprofilefs_create_ro_ulong(struct super_block *sb, struct dentry *root,
char const *name, unsigned long *val) char const *name, unsigned long *val)
{ {
struct dentry *d = __oprofilefs_create_file(sb, root, name, return __oprofilefs_create_file(sb, root, name,
&ulong_ro_fops, 0444); &ulong_ro_fops, 0444, val);
if (!d)
return -EFAULT;
d->d_inode->i_private = val;
return 0;
} }
...@@ -189,31 +180,22 @@ static const struct file_operations atomic_ro_fops = { ...@@ -189,31 +180,22 @@ static const struct file_operations atomic_ro_fops = {
int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root, int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
char const *name, atomic_t *val) char const *name, atomic_t *val)
{ {
struct dentry *d = __oprofilefs_create_file(sb, root, name, return __oprofilefs_create_file(sb, root, name,
&atomic_ro_fops, 0444); &atomic_ro_fops, 0444, val);
if (!d)
return -EFAULT;
d->d_inode->i_private = val;
return 0;
} }
int oprofilefs_create_file(struct super_block *sb, struct dentry *root, int oprofilefs_create_file(struct super_block *sb, struct dentry *root,
char const *name, const struct file_operations *fops) char const *name, const struct file_operations *fops)
{ {
if (!__oprofilefs_create_file(sb, root, name, fops, 0644)) return __oprofilefs_create_file(sb, root, name, fops, 0644, NULL);
return -EFAULT;
return 0;
} }
int oprofilefs_create_file_perm(struct super_block *sb, struct dentry *root, int oprofilefs_create_file_perm(struct super_block *sb, struct dentry *root,
char const *name, const struct file_operations *fops, int perm) char const *name, const struct file_operations *fops, int perm)
{ {
if (!__oprofilefs_create_file(sb, root, name, fops, perm)) return __oprofilefs_create_file(sb, root, name, fops, perm, NULL);
return -EFAULT;
return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment