@@ -101,9 +101,6 @@ mtrr_write(struct file *file, const char __user *buf, size_t len, loff_t * ppos)
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 );
@@ -226,8 +223,6 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg)
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,24 +231,18 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg)
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,8 +268,6 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg)
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,25 +276,19 @@ mtrr_ioctl(struct file *file, unsigned int cmd, unsigned long __arg)
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 ;
297
282
case MTRRIOC_DEL_PAGE_ENTRY :
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 :
@@ -373,28 +354,6 @@ static int mtrr_close(struct inode *ino, struct file *file)
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,6 +385,28 @@ static int mtrr_seq_show(struct seq_file *seq, void *offset)
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 file_operations mtrr_fops = {
400
+ .owner = THIS_MODULE ,
401
+ .open = mtrr_open ,
402
+ .read = seq_read ,
403
+ .llseek = seq_lseek ,
404
+ .write = mtrr_write ,
405
+ .unlocked_ioctl = mtrr_ioctl ,
406
+ .compat_ioctl = mtrr_ioctl ,
407
+ .release = mtrr_close ,
408
+ };
409
+
429
410
static int __init mtrr_if_init (void )
430
411
{
431
412
struct cpuinfo_x86 * c = & boot_cpu_data ;
0 commit comments