Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp102414ybh; Tue, 10 Mar 2020 20:22:59 -0700 (PDT) X-Google-Smtp-Source: ADFU+vscbuTEbTfhcKkOaZZQVfE1vkqeTki55zgmxknGnAxfZaXsku3Nak+XhA4oO8AqMjfOx+G6 X-Received: by 2002:a9d:4b15:: with SMTP id q21mr708033otf.84.1583896979586; Tue, 10 Mar 2020 20:22:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1583896979; cv=none; d=google.com; s=arc-20160816; b=VuV7WyeVbJNAADe1eSGrFGLIY/lv200+iuMEUD3CI21MJ78DDLZaXuckQZiUWqzqhK h2fJz4Kc6G4FckPTgjfhO0K1htm2adXtD5q2jfmE8rxTezszAkfLvFVzT/7/0BDUp7o3 cw4yVEua/ut0lvoUk6STsWUhr3Hr26szXwUrAOnQCXfUebDw1MKytcq/fTMBEawhAEwX Sei6zsIqbr/ZJ/Gysajem+ADwt1Zj5jWM9D0DXnw05UQTtsyUqE0yYDq3FWhP2u53jDl oJTKm3w8b4wpXMCbF59f3QdRSCuVgbNPSwsCipBPeymx6rfWa399PxR9YGU/6L52Y5yK UYVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:dkim-signature:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from; bh=aNbMTHzEBed2jLOkpeGMmsEaPHwGzRfzqOjyErWK5uk=; b=xzS8FEey+4jPIfeYzIp1jZEtkfsNf5s4Fg4Nc5jYAYzHBTmU1mwdIzKZyo0re+cZ+G xirGPvB42lcR4F13UJOs58dGzR8dCBwuV84DI07L0w2mD+mMqoPeQAKwpuxcVFOuXqUa ONtL1U4+/nNrkvgpDfYw8GIYZm9kTC70sc7Ep6yqRXqRpCNy6IrUA8vIIsr5Eaa7e2/X bXPkaK8HFxZQBuuxIGiDrc+4D1BMcJ0BjAhxK0RjXCPuvlYCUBYXOTX7W+CosMhVCquO HWsWl4LYj5eVTSEPv+aeX79JD6TGrvB6I1+YzM1i5Jj/igcY5bMCEMotr0bsZjyqiFmT MdLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=KX3p6IR6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 18si406847oiq.71.2020.03.10.20.22.45; Tue, 10 Mar 2020 20:22:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=KX3p6IR6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727965AbgCKDV7 (ORCPT + 99 others); Tue, 10 Mar 2020 23:21:59 -0400 Received: from hqnvemgate25.nvidia.com ([216.228.121.64]:2076 "EHLO hqnvemgate25.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727307AbgCKDV6 (ORCPT ); Tue, 10 Mar 2020 23:21:58 -0400 Received: from hqpgpgate102.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate25.nvidia.com (using TLS: TLSv1.2, DES-CBC3-SHA) id ; Tue, 10 Mar 2020 20:21:13 -0700 Received: from hqmail.nvidia.com ([172.20.161.6]) by hqpgpgate102.nvidia.com (PGP Universal service); Tue, 10 Mar 2020 20:21:58 -0700 X-PGP-Universal: processed; by hqpgpgate102.nvidia.com on Tue, 10 Mar 2020 20:21:58 -0700 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1473.3; Wed, 11 Mar 2020 03:21:57 +0000 Received: from rnnvemgw01.nvidia.com (10.128.109.123) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1473.3 via Frontend Transport; Wed, 11 Mar 2020 03:21:57 +0000 Received: from blueforge.nvidia.com (Not Verified[10.110.48.28]) by rnnvemgw01.nvidia.com with Trustwave SEG (v7,5,8,10121) id ; Tue, 10 Mar 2020 20:21:57 -0700 From: John Hubbard To: Stephen Rothwell , Christian Brauner CC: Linux Next , LKML , John Hubbard Subject: [PATCH] pid: fix uninitialized retval in alloc_pid() Date: Tue, 10 Mar 2020 20:21:53 -0700 Message-ID: <20200311032153.431492-1-jhubbard@nvidia.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-NVConfidentiality: public Content-Transfer-Encoding: quoted-printable Content-Type: text/plain DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1583896873; bh=aNbMTHzEBed2jLOkpeGMmsEaPHwGzRfzqOjyErWK5uk=; h=X-PGP-Universal:From:To:CC:Subject:Date:Message-ID:X-Mailer: MIME-Version:X-NVConfidentiality:Content-Transfer-Encoding: Content-Type; b=KX3p6IR6m/cQXjuSydvF0pEZ0gTdkgVJTOLRSOdojHLdH5cQZk+I1nwGRl7Kg3Kcx +eHwLyP6kuBpa7FnsUx7RtImMfZi1udoigiyeUtkKskqhxifRO4MYg01M0jc0qFiOe Z5FQvDYPOfdRrMdvcbnPl94iuMROFDiRBShgbJNnsVaDn3IfhjEHulDKNfTpfOVJsr mizltKbR1xzsUzhDYx0ENA8xRQkz3zWcK4ZAaDkLNq2pfAGov0hIV0glXu6Y3o903p /wRm1fGcK/W0WgG32Hf3STT45EgDarQKBrCareLKlyLOCH5ZnFCqYdXcdwSkq6EBd2 r0E2TKg4ssdYw== Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Signed-off-by: John Hubbard --- 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 =3D -ENOMEM; =20 /* * 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 =3D tmp->parent; } =20 - /* - * 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 =3D -ENOMEM; - get_pid_ns(ns); refcount_set(&pid->count, 1); for (type =3D 0; type < PIDTYPE_MAX; ++type) base-commit: 134546626849cd6852d6d4bf8f207b5fbc54261b --=20 2.25.1