.. | .. |
---|
101 | 101 | int length; |
---|
102 | 102 | size_t linelen; |
---|
103 | 103 | |
---|
104 | | - if (!capable(CAP_SYS_ADMIN)) |
---|
105 | | - return -EPERM; |
---|
106 | | - |
---|
107 | 104 | memset(line, 0, LINE_SIZE); |
---|
108 | 105 | |
---|
109 | 106 | len = min_t(size_t, len, LINE_SIZE - 1); |
---|
.. | .. |
---|
176 | 173 | case MTRRIOC_SET_PAGE_ENTRY: |
---|
177 | 174 | case MTRRIOC_DEL_PAGE_ENTRY: |
---|
178 | 175 | case MTRRIOC_KILL_PAGE_ENTRY: |
---|
179 | | - if (copy_from_user(&sentry, arg, sizeof sentry)) |
---|
| 176 | + if (copy_from_user(&sentry, arg, sizeof(sentry))) |
---|
180 | 177 | return -EFAULT; |
---|
181 | 178 | break; |
---|
182 | 179 | case MTRRIOC_GET_ENTRY: |
---|
183 | 180 | case MTRRIOC_GET_PAGE_ENTRY: |
---|
184 | | - if (copy_from_user(&gentry, arg, sizeof gentry)) |
---|
| 181 | + if (copy_from_user(&gentry, arg, sizeof(gentry))) |
---|
185 | 182 | return -EFAULT; |
---|
186 | 183 | break; |
---|
187 | 184 | #ifdef CONFIG_COMPAT |
---|
.. | .. |
---|
226 | 223 | #ifdef CONFIG_COMPAT |
---|
227 | 224 | case MTRRIOC32_ADD_ENTRY: |
---|
228 | 225 | #endif |
---|
229 | | - if (!capable(CAP_SYS_ADMIN)) |
---|
230 | | - return -EPERM; |
---|
231 | 226 | err = |
---|
232 | 227 | mtrr_file_add(sentry.base, sentry.size, sentry.type, true, |
---|
233 | 228 | file, 0); |
---|
.. | .. |
---|
236 | 231 | #ifdef CONFIG_COMPAT |
---|
237 | 232 | case MTRRIOC32_SET_ENTRY: |
---|
238 | 233 | #endif |
---|
239 | | - if (!capable(CAP_SYS_ADMIN)) |
---|
240 | | - return -EPERM; |
---|
241 | 234 | err = mtrr_add(sentry.base, sentry.size, sentry.type, false); |
---|
242 | 235 | break; |
---|
243 | 236 | case MTRRIOC_DEL_ENTRY: |
---|
244 | 237 | #ifdef CONFIG_COMPAT |
---|
245 | 238 | case MTRRIOC32_DEL_ENTRY: |
---|
246 | 239 | #endif |
---|
247 | | - if (!capable(CAP_SYS_ADMIN)) |
---|
248 | | - return -EPERM; |
---|
249 | 240 | err = mtrr_file_del(sentry.base, sentry.size, file, 0); |
---|
250 | 241 | break; |
---|
251 | 242 | case MTRRIOC_KILL_ENTRY: |
---|
252 | 243 | #ifdef CONFIG_COMPAT |
---|
253 | 244 | case MTRRIOC32_KILL_ENTRY: |
---|
254 | 245 | #endif |
---|
255 | | - if (!capable(CAP_SYS_ADMIN)) |
---|
256 | | - return -EPERM; |
---|
257 | 246 | err = mtrr_del(-1, sentry.base, sentry.size); |
---|
258 | 247 | break; |
---|
259 | 248 | case MTRRIOC_GET_ENTRY: |
---|
.. | .. |
---|
279 | 268 | #ifdef CONFIG_COMPAT |
---|
280 | 269 | case MTRRIOC32_ADD_PAGE_ENTRY: |
---|
281 | 270 | #endif |
---|
282 | | - if (!capable(CAP_SYS_ADMIN)) |
---|
283 | | - return -EPERM; |
---|
284 | 271 | err = |
---|
285 | 272 | mtrr_file_add(sentry.base, sentry.size, sentry.type, true, |
---|
286 | 273 | file, 1); |
---|
.. | .. |
---|
289 | 276 | #ifdef CONFIG_COMPAT |
---|
290 | 277 | case MTRRIOC32_SET_PAGE_ENTRY: |
---|
291 | 278 | #endif |
---|
292 | | - if (!capable(CAP_SYS_ADMIN)) |
---|
293 | | - return -EPERM; |
---|
294 | 279 | err = |
---|
295 | 280 | mtrr_add_page(sentry.base, sentry.size, sentry.type, false); |
---|
296 | 281 | break; |
---|
.. | .. |
---|
298 | 283 | #ifdef CONFIG_COMPAT |
---|
299 | 284 | case MTRRIOC32_DEL_PAGE_ENTRY: |
---|
300 | 285 | #endif |
---|
301 | | - if (!capable(CAP_SYS_ADMIN)) |
---|
302 | | - return -EPERM; |
---|
303 | 286 | err = mtrr_file_del(sentry.base, sentry.size, file, 1); |
---|
304 | 287 | break; |
---|
305 | 288 | case MTRRIOC_KILL_PAGE_ENTRY: |
---|
306 | 289 | #ifdef CONFIG_COMPAT |
---|
307 | 290 | case MTRRIOC32_KILL_PAGE_ENTRY: |
---|
308 | 291 | #endif |
---|
309 | | - if (!capable(CAP_SYS_ADMIN)) |
---|
310 | | - return -EPERM; |
---|
311 | 292 | err = mtrr_del_page(-1, sentry.base, sentry.size); |
---|
312 | 293 | break; |
---|
313 | 294 | case MTRRIOC_GET_PAGE_ENTRY: |
---|
.. | .. |
---|
334 | 315 | switch (cmd) { |
---|
335 | 316 | case MTRRIOC_GET_ENTRY: |
---|
336 | 317 | case MTRRIOC_GET_PAGE_ENTRY: |
---|
337 | | - if (copy_to_user(arg, &gentry, sizeof gentry)) |
---|
| 318 | + if (copy_to_user(arg, &gentry, sizeof(gentry))) |
---|
338 | 319 | err = -EFAULT; |
---|
339 | 320 | break; |
---|
340 | 321 | #ifdef CONFIG_COMPAT |
---|
.. | .. |
---|
373 | 354 | return single_release(ino, file); |
---|
374 | 355 | } |
---|
375 | 356 | |
---|
376 | | -static int mtrr_seq_show(struct seq_file *seq, void *offset); |
---|
377 | | - |
---|
378 | | -static int mtrr_open(struct inode *inode, struct file *file) |
---|
379 | | -{ |
---|
380 | | - if (!mtrr_if) |
---|
381 | | - return -EIO; |
---|
382 | | - if (!mtrr_if->get) |
---|
383 | | - return -ENXIO; |
---|
384 | | - return single_open(file, mtrr_seq_show, NULL); |
---|
385 | | -} |
---|
386 | | - |
---|
387 | | -static const struct file_operations mtrr_fops = { |
---|
388 | | - .owner = THIS_MODULE, |
---|
389 | | - .open = mtrr_open, |
---|
390 | | - .read = seq_read, |
---|
391 | | - .llseek = seq_lseek, |
---|
392 | | - .write = mtrr_write, |
---|
393 | | - .unlocked_ioctl = mtrr_ioctl, |
---|
394 | | - .compat_ioctl = mtrr_ioctl, |
---|
395 | | - .release = mtrr_close, |
---|
396 | | -}; |
---|
397 | | - |
---|
398 | 357 | static int mtrr_seq_show(struct seq_file *seq, void *offset) |
---|
399 | 358 | { |
---|
400 | 359 | char factor; |
---|
.. | .. |
---|
426 | 385 | return 0; |
---|
427 | 386 | } |
---|
428 | 387 | |
---|
| 388 | +static int mtrr_open(struct inode *inode, struct file *file) |
---|
| 389 | +{ |
---|
| 390 | + if (!mtrr_if) |
---|
| 391 | + return -EIO; |
---|
| 392 | + if (!mtrr_if->get) |
---|
| 393 | + return -ENXIO; |
---|
| 394 | + if (!capable(CAP_SYS_ADMIN)) |
---|
| 395 | + return -EPERM; |
---|
| 396 | + return single_open(file, mtrr_seq_show, NULL); |
---|
| 397 | +} |
---|
| 398 | + |
---|
| 399 | +static const struct proc_ops mtrr_proc_ops = { |
---|
| 400 | + .proc_open = mtrr_open, |
---|
| 401 | + .proc_read = seq_read, |
---|
| 402 | + .proc_lseek = seq_lseek, |
---|
| 403 | + .proc_write = mtrr_write, |
---|
| 404 | + .proc_ioctl = mtrr_ioctl, |
---|
| 405 | +#ifdef CONFIG_COMPAT |
---|
| 406 | + .proc_compat_ioctl = mtrr_ioctl, |
---|
| 407 | +#endif |
---|
| 408 | + .proc_release = mtrr_close, |
---|
| 409 | +}; |
---|
| 410 | + |
---|
429 | 411 | static int __init mtrr_if_init(void) |
---|
430 | 412 | { |
---|
431 | 413 | struct cpuinfo_x86 *c = &boot_cpu_data; |
---|
.. | .. |
---|
436 | 418 | (!cpu_has(c, X86_FEATURE_CENTAUR_MCR))) |
---|
437 | 419 | return -ENODEV; |
---|
438 | 420 | |
---|
439 | | - proc_create("mtrr", S_IWUSR | S_IRUGO, NULL, &mtrr_fops); |
---|
| 421 | + proc_create("mtrr", S_IWUSR | S_IRUGO, NULL, &mtrr_proc_ops); |
---|
440 | 422 | return 0; |
---|
441 | 423 | } |
---|
442 | 424 | arch_initcall(mtrr_if_init); |
---|