public inbox for linux-next@vger.kernel.org
 help / color / mirror / Atom feed
From: John Hubbard <jhubbard@nvidia.com>
To: Stephen Rothwell <sfr@canb.auug.org.au>,
	Christian Brauner <christian.brauner@ubuntu.com>
Cc: Linux Next <linux-next@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	John Hubbard <jhubbard@nvidia.com>
Subject: [PATCH] pid: fix uninitialized retval in alloc_pid()
Date: Tue, 10 Mar 2020 20:21:53 -0700	[thread overview]
Message-ID: <20200311032153.431492-1-jhubbard@nvidia.com> (raw)

Commit 8deb24dcb89cb ("pid: make ENOMEM return value more obvious")
left the return value uninitialized in one error case. The justification
for the above commit included a statement that retval is "initialized on
ever[y] failure path in the loop". However, that is not quite good
enough because there is an earlier case that is before the loop. And
also, it's more maintenance and merge-safe to initialize it once at the
top, as evidenced by this build warning that we now have.

Therefore, restore the top-level initialization of retval.

Also move the descriptive comment up, and remove the now-redundant
later initialization of retval.

Fixes: 8deb24dcb89cb ("pid: make ENOMEM return value more obvious")
Cc: Christian Brauner <christian.brauner@ubuntu.com>
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
---
 kernel/pid.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/kernel/pid.c b/kernel/pid.c
index ff6cd6786d10..49bf6dd32de4 100644
--- a/kernel/pid.c
+++ b/kernel/pid.c
@@ -162,7 +162,16 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *set_tid,
 	int i, nr;
 	struct pid_namespace *tmp;
 	struct upid *upid;
-	int retval;
+
+	/*
+	 * ENOMEM is not the most obvious choice especially for the case
+	 * where the child subreaper has already exited and the pid
+	 * namespace denies the creation of any new processes. But ENOMEM
+	 * is what we have exposed to userspace for a long time and it is
+	 * documented behavior for pid namespaces. So we can't easily
+	 * change it even if there were an error code better suited.
+	 */
+	int retval = -ENOMEM;
 
 	/*
 	 * set_tid_size contains the size of the set_tid array. Starting at
@@ -244,16 +253,6 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *set_tid,
 		tmp = tmp->parent;
 	}
 
-	/*
-	 * ENOMEM is not the most obvious choice especially for the case
-	 * where the child subreaper has already exited and the pid
-	 * namespace denies the creation of any new processes. But ENOMEM
-	 * is what we have exposed to userspace for a long time and it is
-	 * documented behavior for pid namespaces. So we can't easily
-	 * change it even if there were an error code better suited.
-	 */
-	retval = -ENOMEM;
-
 	get_pid_ns(ns);
 	refcount_set(&pid->count, 1);
 	for (type = 0; type < PIDTYPE_MAX; ++type)

base-commit: 134546626849cd6852d6d4bf8f207b5fbc54261b
-- 
2.25.1


             reply	other threads:[~2020-03-11  3:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-11  3:21 John Hubbard [this message]
2020-03-11  3:30 ` [PATCH] pid: fix uninitialized retval in alloc_pid() Christian Brauner
2020-03-11  3:33   ` John Hubbard

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200311032153.431492-1-jhubbard@nvidia.com \
    --to=jhubbard@nvidia.com \
    --cc=christian.brauner@ubuntu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-next@vger.kernel.org \
    --cc=sfr@canb.auug.org.au \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox