Skip to content

Commit 919a7a1

Browse files
author
Al Viro
committed
timerfd: switch to CLASS(fd)
Fold timerfd_fget() into both callers to have fdget() and fdput() in the same scope. Could be done in different ways, but this is probably the smallest solution. Reviewed-by: Christian Brauner <[email protected]> Signed-off-by: Al Viro <[email protected]>
1 parent 05e5556 commit 919a7a1

File tree

1 file changed

+14
-26
lines changed

1 file changed

+14
-26
lines changed

fs/timerfd.c

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -394,19 +394,6 @@ static const struct file_operations timerfd_fops = {
394394
.unlocked_ioctl = timerfd_ioctl,
395395
};
396396

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-
410397
SYSCALL_DEFINE2(timerfd_create, int, clockid, int, flags)
411398
{
412399
int ufd;
@@ -471,23 +458,24 @@ static int do_timerfd_settime(int ufd, int flags,
471458
const struct itimerspec64 *new,
472459
struct itimerspec64 *old)
473460
{
474-
struct fd f;
475461
struct timerfd_ctx *ctx;
476462
int ret;
477463

478464
if ((flags & ~TFD_SETTIME_FLAGS) ||
479465
!itimerspec64_valid(new))
480466
return -EINVAL;
481467

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+
485475
ctx = fd_file(f)->private_data;
486476

487-
if (isalarm(ctx) && !capable(CAP_WAKE_ALARM)) {
488-
fdput(f);
477+
if (isalarm(ctx) && !capable(CAP_WAKE_ALARM))
489478
return -EPERM;
490-
}
491479

492480
timerfd_setup_cancel(ctx, flags);
493481

@@ -535,17 +523,18 @@ static int do_timerfd_settime(int ufd, int flags,
535523
ret = timerfd_setup(ctx, flags, new);
536524

537525
spin_unlock_irq(&ctx->wqh.lock);
538-
fdput(f);
539526
return ret;
540527
}
541528

542529
static int do_timerfd_gettime(int ufd, struct itimerspec64 *t)
543530
{
544-
struct fd f;
545531
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;
549538
ctx = fd_file(f)->private_data;
550539

551540
spin_lock_irq(&ctx->wqh.lock);
@@ -567,7 +556,6 @@ static int do_timerfd_gettime(int ufd, struct itimerspec64 *t)
567556
t->it_value = ktime_to_timespec64(timerfd_get_remaining(ctx));
568557
t->it_interval = ktime_to_timespec64(ctx->tintv);
569558
spin_unlock_irq(&ctx->wqh.lock);
570-
fdput(f);
571559
return 0;
572560
}
573561

0 commit comments

Comments
 (0)