@@ -394,19 +394,6 @@ static const struct file_operations timerfd_fops = {
394
394
.unlocked_ioctl = timerfd_ioctl ,
395
395
};
396
396
397
- static int timerfd_fget (int fd , struct fd * p )
398
- {
399
- struct fd f = fdget (fd );
400
- if (!fd_file (f ))
401
- return - EBADF ;
402
- if (fd_file (f )-> f_op != & timerfd_fops ) {
403
- fdput (f );
404
- return - EINVAL ;
405
- }
406
- * p = f ;
407
- return 0 ;
408
- }
409
-
410
397
SYSCALL_DEFINE2 (timerfd_create , int , clockid , int , flags )
411
398
{
412
399
int ufd ;
@@ -471,23 +458,24 @@ static int do_timerfd_settime(int ufd, int flags,
471
458
const struct itimerspec64 * new ,
472
459
struct itimerspec64 * old )
473
460
{
474
- struct fd f ;
475
461
struct timerfd_ctx * ctx ;
476
462
int ret ;
477
463
478
464
if ((flags & ~TFD_SETTIME_FLAGS ) ||
479
465
!itimerspec64_valid (new ))
480
466
return - EINVAL ;
481
467
482
- ret = timerfd_fget (ufd , & f );
483
- if (ret )
484
- return ret ;
468
+ CLASS (fd , f )(ufd );
469
+ if (fd_empty (f ))
470
+ return - EBADF ;
471
+
472
+ if (fd_file (f )-> f_op != & timerfd_fops )
473
+ return - EINVAL ;
474
+
485
475
ctx = fd_file (f )-> private_data ;
486
476
487
- if (isalarm (ctx ) && !capable (CAP_WAKE_ALARM )) {
488
- fdput (f );
477
+ if (isalarm (ctx ) && !capable (CAP_WAKE_ALARM ))
489
478
return - EPERM ;
490
- }
491
479
492
480
timerfd_setup_cancel (ctx , flags );
493
481
@@ -535,17 +523,18 @@ static int do_timerfd_settime(int ufd, int flags,
535
523
ret = timerfd_setup (ctx , flags , new );
536
524
537
525
spin_unlock_irq (& ctx -> wqh .lock );
538
- fdput (f );
539
526
return ret ;
540
527
}
541
528
542
529
static int do_timerfd_gettime (int ufd , struct itimerspec64 * t )
543
530
{
544
- struct fd f ;
545
531
struct timerfd_ctx * ctx ;
546
- int ret = timerfd_fget (ufd , & f );
547
- if (ret )
548
- return ret ;
532
+ CLASS (fd , f )(ufd );
533
+
534
+ if (fd_empty (f ))
535
+ return - EBADF ;
536
+ if (fd_file (f )-> f_op != & timerfd_fops )
537
+ return - EINVAL ;
549
538
ctx = fd_file (f )-> private_data ;
550
539
551
540
spin_lock_irq (& ctx -> wqh .lock );
@@ -567,7 +556,6 @@ static int do_timerfd_gettime(int ufd, struct itimerspec64 *t)
567
556
t -> it_value = ktime_to_timespec64 (timerfd_get_remaining (ctx ));
568
557
t -> it_interval = ktime_to_timespec64 (ctx -> tintv );
569
558
spin_unlock_irq (& ctx -> wqh .lock );
570
- fdput (f );
571
559
return 0 ;
572
560
}
573
561
0 commit comments