diff options
Diffstat (limited to 'drivers/oprofile/oprofilefs.c')
| -rw-r--r-- | drivers/oprofile/oprofilefs.c | 54 |
1 files changed, 20 insertions, 34 deletions
diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c index 2766a6d3c2e9..1944621930d9 100644 --- a/drivers/oprofile/oprofilefs.c +++ b/drivers/oprofile/oprofilefs.c | |||
| @@ -91,16 +91,20 @@ static ssize_t ulong_read_file(struct file *file, char __user *buf, size_t count | |||
| 91 | 91 | ||
| 92 | static ssize_t ulong_write_file(struct file *file, char const __user *buf, size_t count, loff_t *offset) | 92 | static ssize_t ulong_write_file(struct file *file, char const __user *buf, size_t count, loff_t *offset) |
| 93 | { | 93 | { |
| 94 | unsigned long *value = file->private_data; | 94 | unsigned long value; |
| 95 | int retval; | 95 | int retval; |
| 96 | 96 | ||
| 97 | if (*offset) | 97 | if (*offset) |
| 98 | return -EINVAL; | 98 | return -EINVAL; |
| 99 | 99 | ||
| 100 | retval = oprofilefs_ulong_from_user(value, buf, count); | 100 | retval = oprofilefs_ulong_from_user(&value, buf, count); |
| 101 | if (retval) | ||
| 102 | return retval; | ||
| 101 | 103 | ||
| 104 | retval = oprofile_set_ulong(file->private_data, value); | ||
| 102 | if (retval) | 105 | if (retval) |
| 103 | return retval; | 106 | return retval; |
| 107 | |||
| 104 | return count; | 108 | return count; |
| 105 | } | 109 | } |
| 106 | 110 | ||
| @@ -126,50 +130,41 @@ static const struct file_operations ulong_ro_fops = { | |||
| 126 | }; | 130 | }; |
| 127 | 131 | ||
| 128 | 132 | ||
| 129 | static struct dentry *__oprofilefs_create_file(struct super_block *sb, | 133 | static int __oprofilefs_create_file(struct super_block *sb, |
| 130 | struct dentry *root, char const *name, const struct file_operations *fops, | 134 | struct dentry *root, char const *name, const struct file_operations *fops, |
| 131 | int perm) | 135 | int perm, void *priv) |
| 132 | { | 136 | { |
| 133 | struct dentry *dentry; | 137 | struct dentry *dentry; |
| 134 | struct inode *inode; | 138 | struct inode *inode; |
| 135 | 139 | ||
| 136 | dentry = d_alloc_name(root, name); | 140 | dentry = d_alloc_name(root, name); |
| 137 | if (!dentry) | 141 | if (!dentry) |
| 138 | return NULL; | 142 | return -ENOMEM; |
| 139 | inode = oprofilefs_get_inode(sb, S_IFREG | perm); | 143 | inode = oprofilefs_get_inode(sb, S_IFREG | perm); |
| 140 | if (!inode) { | 144 | if (!inode) { |
| 141 | dput(dentry); | 145 | dput(dentry); |
| 142 | return NULL; | 146 | return -ENOMEM; |
| 143 | } | 147 | } |
| 144 | inode->i_fop = fops; | 148 | inode->i_fop = fops; |
| 145 | d_add(dentry, inode); | 149 | d_add(dentry, inode); |
| 146 | return dentry; | 150 | dentry->d_inode->i_private = priv; |
| 151 | return 0; | ||
| 147 | } | 152 | } |
| 148 | 153 | ||
| 149 | 154 | ||
| 150 | int oprofilefs_create_ulong(struct super_block *sb, struct dentry *root, | 155 | int oprofilefs_create_ulong(struct super_block *sb, struct dentry *root, |
| 151 | char const *name, unsigned long *val) | 156 | char const *name, unsigned long *val) |
| 152 | { | 157 | { |
| 153 | struct dentry *d = __oprofilefs_create_file(sb, root, name, | 158 | return __oprofilefs_create_file(sb, root, name, |
| 154 | &ulong_fops, 0644); | 159 | &ulong_fops, 0644, val); |
| 155 | if (!d) | ||
| 156 | return -EFAULT; | ||
| 157 | |||
| 158 | d->d_inode->i_private = val; | ||
| 159 | return 0; | ||
| 160 | } | 160 | } |
| 161 | 161 | ||
| 162 | 162 | ||
| 163 | int oprofilefs_create_ro_ulong(struct super_block *sb, struct dentry *root, | 163 | int oprofilefs_create_ro_ulong(struct super_block *sb, struct dentry *root, |
| 164 | char const *name, unsigned long *val) | 164 | char const *name, unsigned long *val) |
| 165 | { | 165 | { |
| 166 | struct dentry *d = __oprofilefs_create_file(sb, root, name, | 166 | return __oprofilefs_create_file(sb, root, name, |
| 167 | &ulong_ro_fops, 0444); | 167 | &ulong_ro_fops, 0444, val); |
| 168 | if (!d) | ||
| 169 | return -EFAULT; | ||
| 170 | |||
| 171 | d->d_inode->i_private = val; | ||
| 172 | return 0; | ||
| 173 | } | 168 | } |
| 174 | 169 | ||
| 175 | 170 | ||
| @@ -189,31 +184,22 @@ static const struct file_operations atomic_ro_fops = { | |||
| 189 | int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root, | 184 | int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root, |
| 190 | char const *name, atomic_t *val) | 185 | char const *name, atomic_t *val) |
| 191 | { | 186 | { |
| 192 | struct dentry *d = __oprofilefs_create_file(sb, root, name, | 187 | return __oprofilefs_create_file(sb, root, name, |
| 193 | &atomic_ro_fops, 0444); | 188 | &atomic_ro_fops, 0444, val); |
| 194 | if (!d) | ||
| 195 | return -EFAULT; | ||
| 196 | |||
| 197 | d->d_inode->i_private = val; | ||
| 198 | return 0; | ||
| 199 | } | 189 | } |
| 200 | 190 | ||
| 201 | 191 | ||
| 202 | int oprofilefs_create_file(struct super_block *sb, struct dentry *root, | 192 | int oprofilefs_create_file(struct super_block *sb, struct dentry *root, |
| 203 | char const *name, const struct file_operations *fops) | 193 | char const *name, const struct file_operations *fops) |
| 204 | { | 194 | { |
| 205 | if (!__oprofilefs_create_file(sb, root, name, fops, 0644)) | 195 | return __oprofilefs_create_file(sb, root, name, fops, 0644, NULL); |
| 206 | return -EFAULT; | ||
| 207 | return 0; | ||
| 208 | } | 196 | } |
| 209 | 197 | ||
| 210 | 198 | ||
| 211 | int oprofilefs_create_file_perm(struct super_block *sb, struct dentry *root, | 199 | int oprofilefs_create_file_perm(struct super_block *sb, struct dentry *root, |
| 212 | char const *name, const struct file_operations *fops, int perm) | 200 | char const *name, const struct file_operations *fops, int perm) |
| 213 | { | 201 | { |
| 214 | if (!__oprofilefs_create_file(sb, root, name, fops, perm)) | 202 | return __oprofilefs_create_file(sb, root, name, fops, perm, NULL); |
| 215 | return -EFAULT; | ||
| 216 | return 0; | ||
| 217 | } | 203 | } |
| 218 | 204 | ||
| 219 | 205 | ||
