aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/oprofile/oprofilefs.c
diff options
context:
space:
mode:
authorRobert Richter <robert.richter@amd.com>2010-08-19 04:50:26 -0400
committerRobert Richter <robert.richter@amd.com>2010-10-04 04:55:24 -0400
commit4fdaa7b682b413dfb7ca9fa74ff45b1e0cb3dade (patch)
treedbd363d92dde1eca2da778e50c03b7c49159dc4d /drivers/oprofile/oprofilefs.c
parentdc0c22b878a60373762495b8e5628a32c1b80ac4 (diff)
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: Robert Richter <robert.richter@amd.com>
Diffstat (limited to 'drivers/oprofile/oprofilefs.c')
-rw-r--r--drivers/oprofile/oprofilefs.c46
1 files changed, 14 insertions, 32 deletions
diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
index 2766a6d3c2e9..789a1a857ddf 100644
--- a/drivers/oprofile/oprofilefs.c
+++ b/drivers/oprofile/oprofilefs.c
@@ -126,50 +126,41 @@ static const struct file_operations ulong_ro_fops = {
126}; 126};
127 127
128 128
129static struct dentry *__oprofilefs_create_file(struct super_block *sb, 129static int __oprofilefs_create_file(struct super_block *sb,
130 struct dentry *root, char const *name, const struct file_operations *fops, 130 struct dentry *root, char const *name, const struct file_operations *fops,
131 int perm) 131 int perm, void *priv)
132{ 132{
133 struct dentry *dentry; 133 struct dentry *dentry;
134 struct inode *inode; 134 struct inode *inode;
135 135
136 dentry = d_alloc_name(root, name); 136 dentry = d_alloc_name(root, name);
137 if (!dentry) 137 if (!dentry)
138 return NULL; 138 return -ENOMEM;
139 inode = oprofilefs_get_inode(sb, S_IFREG | perm); 139 inode = oprofilefs_get_inode(sb, S_IFREG | perm);
140 if (!inode) { 140 if (!inode) {
141 dput(dentry); 141 dput(dentry);
142 return NULL; 142 return -ENOMEM;
143 } 143 }
144 inode->i_fop = fops; 144 inode->i_fop = fops;
145 d_add(dentry, inode); 145 d_add(dentry, inode);
146 return dentry; 146 dentry->d_inode->i_private = priv;
147 return 0;
147} 148}
148 149
149 150
150int oprofilefs_create_ulong(struct super_block *sb, struct dentry *root, 151int oprofilefs_create_ulong(struct super_block *sb, struct dentry *root,
151 char const *name, unsigned long *val) 152 char const *name, unsigned long *val)
152{ 153{
153 struct dentry *d = __oprofilefs_create_file(sb, root, name, 154 return __oprofilefs_create_file(sb, root, name,
154 &ulong_fops, 0644); 155 &ulong_fops, 0644, val);
155 if (!d)
156 return -EFAULT;
157
158 d->d_inode->i_private = val;
159 return 0;
160} 156}
161 157
162 158
163int oprofilefs_create_ro_ulong(struct super_block *sb, struct dentry *root, 159int oprofilefs_create_ro_ulong(struct super_block *sb, struct dentry *root,
164 char const *name, unsigned long *val) 160 char const *name, unsigned long *val)
165{ 161{
166 struct dentry *d = __oprofilefs_create_file(sb, root, name, 162 return __oprofilefs_create_file(sb, root, name,
167 &ulong_ro_fops, 0444); 163 &ulong_ro_fops, 0444, val);
168 if (!d)
169 return -EFAULT;
170
171 d->d_inode->i_private = val;
172 return 0;
173} 164}
174 165
175 166
@@ -189,31 +180,22 @@ static const struct file_operations atomic_ro_fops = {
189int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root, 180int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
190 char const *name, atomic_t *val) 181 char const *name, atomic_t *val)
191{ 182{
192 struct dentry *d = __oprofilefs_create_file(sb, root, name, 183 return __oprofilefs_create_file(sb, root, name,
193 &atomic_ro_fops, 0444); 184 &atomic_ro_fops, 0444, val);
194 if (!d)
195 return -EFAULT;
196
197 d->d_inode->i_private = val;
198 return 0;
199} 185}
200 186
201 187
202int oprofilefs_create_file(struct super_block *sb, struct dentry *root, 188int oprofilefs_create_file(struct super_block *sb, struct dentry *root,
203 char const *name, const struct file_operations *fops) 189 char const *name, const struct file_operations *fops)
204{ 190{
205 if (!__oprofilefs_create_file(sb, root, name, fops, 0644)) 191 return __oprofilefs_create_file(sb, root, name, fops, 0644, NULL);
206 return -EFAULT;
207 return 0;
208} 192}
209 193
210 194
211int oprofilefs_create_file_perm(struct super_block *sb, struct dentry *root, 195int oprofilefs_create_file_perm(struct super_block *sb, struct dentry *root,
212 char const *name, const struct file_operations *fops, int perm) 196 char const *name, const struct file_operations *fops, int perm)
213{ 197{
214 if (!__oprofilefs_create_file(sb, root, name, fops, perm)) 198 return __oprofilefs_create_file(sb, root, name, fops, perm, NULL);
215 return -EFAULT;
216 return 0;
217} 199}
218 200
219 201