Skip to content

Commit 1e1d0f0

Browse files
author
Christian Brauner
committed
pid: use pid_has_task() in pidfd_open()
Use the new pid_has_task() helper in pidfd_open(). This simplifies the code and avoids taking rcu_read_{lock,unlock}() and leads to overall nicer code. Signed-off-by: Christian Brauner <[email protected]> Reviewed-by: Oleg Nesterov <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent 1722c14 commit 1e1d0f0

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

kernel/pid.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ static int pidfd_create(struct pid *pid)
497497
*/
498498
SYSCALL_DEFINE2(pidfd_open, pid_t, pid, unsigned int, flags)
499499
{
500-
int fd, ret;
500+
int fd;
501501
struct pid *p;
502502

503503
if (flags)
@@ -510,13 +510,11 @@ SYSCALL_DEFINE2(pidfd_open, pid_t, pid, unsigned int, flags)
510510
if (!p)
511511
return -ESRCH;
512512

513-
ret = 0;
514-
rcu_read_lock();
515-
if (!pid_task(p, PIDTYPE_TGID))
516-
ret = -EINVAL;
517-
rcu_read_unlock();
513+
if (pid_has_task(p, PIDTYPE_TGID))
514+
fd = pidfd_create(p);
515+
else
516+
fd = -EINVAL;
518517

519-
fd = ret ?: pidfd_create(p);
520518
put_pid(p);
521519
return fd;
522520
}

0 commit comments

Comments
 (0)