]> Git Repo - linux.git/commitdiff
mm: use pidfd_get_task()
authorChristian Brauner <[email protected]>
Mon, 11 Oct 2021 13:32:45 +0000 (15:32 +0200)
committerChristian Brauner <[email protected]>
Thu, 14 Oct 2021 11:29:22 +0000 (13:29 +0200)
Instead of duplicating the same code in two places use the newly added
pidfd_get_task() helper. This fixes an (unimportant for now) bug where
PIDTYPE_PID is used whereas PIDTYPE_TGID should have been used.

Link: https://lore.kernel.org/r/[email protected]
Link: https://lore.kernel.org/r/[email protected]
Cc: Vlastimil Babka <[email protected]>
Cc: Suren Baghdasaryan <[email protected]>
Cc: Matthew Bobrowski <[email protected]>
Cc: Alexander Duyck <[email protected]>
Cc: David Hildenbrand <[email protected]>
Cc: Jan Kara <[email protected]>
Cc: Minchan Kim <[email protected]>
Reviewed-by: Matthew Bobrowski <[email protected]>
Acked-by: David Hildenbrand <[email protected]>
Signed-off-by: Christian Brauner <[email protected]>
mm/madvise.c
mm/oom_kill.c

index 0734db8d53a7a9e8ebb65112c6ae76e9c9b07f2d..8c927202bbe61d389777f6668d692bc7871a1547 100644 (file)
@@ -1235,7 +1235,6 @@ SYSCALL_DEFINE5(process_madvise, int, pidfd, const struct iovec __user *, vec,
        struct iovec iovstack[UIO_FASTIOV], iovec;
        struct iovec *iov = iovstack;
        struct iov_iter iter;
-       struct pid *pid;
        struct task_struct *task;
        struct mm_struct *mm;
        size_t total_len;
@@ -1250,18 +1249,12 @@ SYSCALL_DEFINE5(process_madvise, int, pidfd, const struct iovec __user *, vec,
        if (ret < 0)
                goto out;
 
-       pid = pidfd_get_pid(pidfd, &f_flags);
-       if (IS_ERR(pid)) {
-               ret = PTR_ERR(pid);
+       task = pidfd_get_task(pidfd, &f_flags);
+       if (IS_ERR(task)) {
+               ret = PTR_ERR(task);
                goto free_iov;
        }
 
-       task = get_pid_task(pid, PIDTYPE_PID);
-       if (!task) {
-               ret = -ESRCH;
-               goto put_pid;
-       }
-
        if (!process_madvise_behavior_valid(behavior)) {
                ret = -EINVAL;
                goto release_task;
@@ -1301,8 +1294,6 @@ release_mm:
        mmput(mm);
 release_task:
        put_task_struct(task);
-put_pid:
-       put_pid(pid);
 free_iov:
        kfree(iov);
 out:
index 831340e7ad8b4721a066c7d7d850e9b841ab38ff..70d399d5817ee18982b1a7574f5662b0b6c0426e 100644 (file)
@@ -1151,21 +1151,14 @@ SYSCALL_DEFINE2(process_mrelease, int, pidfd, unsigned int, flags)
        struct task_struct *p;
        unsigned int f_flags;
        bool reap = true;
-       struct pid *pid;
        long ret = 0;
 
        if (flags)
                return -EINVAL;
 
-       pid = pidfd_get_pid(pidfd, &f_flags);
-       if (IS_ERR(pid))
-               return PTR_ERR(pid);
-
-       task = get_pid_task(pid, PIDTYPE_TGID);
-       if (!task) {
-               ret = -ESRCH;
-               goto put_pid;
-       }
+       task = pidfd_get_task(pidfd, &f_flags);
+       if (IS_ERR(task))
+               return PTR_ERR(task);
 
        /*
         * Make sure to choose a thread which still has a reference to mm
@@ -1204,8 +1197,6 @@ drop_mm:
        mmdrop(mm);
 put_task:
        put_task_struct(task);
-put_pid:
-       put_pid(pid);
        return ret;
 #else
        return -ENOSYS;
This page took 0.062806 seconds and 4 git commands to generate.