Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp2741862ybh; Mon, 5 Aug 2019 06:09:30 -0700 (PDT) X-Google-Smtp-Source: APXvYqx4unM07zcSYAiYrcuN2DpmEXBD8EW8ugamNCaCqqGxPI1ObDhkNfgyNxCfeqr9vZ510zfC X-Received: by 2002:a17:902:7283:: with SMTP id d3mr54014411pll.93.1565010570544; Mon, 05 Aug 2019 06:09:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565010570; cv=none; d=google.com; s=arc-20160816; b=p6W3Wve0ALKRLb9Y0nM/aliy6tw89FiWoqcv46PMuAFIbmhi+5NVTnBR284Qti57L+ DJ12I7mbp8NcAJzhm3e7LMgBogGGNK2NLjdyQ8YadCOAt6k4WZnZ+WgqAXt7iHWTWZj2 tM/1HTwMlqh/YjOkf3XGjcgeTrcjGzdMpwv0HyAwUn2YkPYRzRGqUhdIgs2QFBpPfmbO ObT5SUU4TNU65kmz6RToWgDNQ/zV64L3wfscJFZPaUoVJ7haoKyvhLu3nkPuMQrNbUJ7 ZhLMCsz+o81LxItfwG1RfaFr62zw+fEgw6xDOlw5lea9ocPqqfektaqmWRjYNDsFn7hL oDcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=nHCBvLRSNryK13NmDYKI1MfDOskKPrNvHrz7PvaP+cg=; b=nrcKwr4jMuODsKFT2Y1ER+5jAUkzauZ8Uio8jousLqAJ+pRsS/gBn19sZ8b7djoFBu O9EzTlnOTPlGwN1frcYTxARDUJEw9ZraWszUAAs1SoIUzUtPFv8kGlglr0ENtphP29dj wbBngV6JqzQZGEeYZmjTKE6LXNCCsx2vHpeYpelu22UMVL7zler4RmieayryVYDHDnvk fyB+XiJ26EcosSyBdTynYuASsu9cGtkfA5ly/ldKm0y0k1jQbg7bwzTQOlgDkYE8t58G oU7HNolYef6Pp4fXpUYOoY/pgCw6k+rUtt1/AMEXy3NNQus+mT/0eTiffvJFv/LHNeIx JyGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=sTHUebjN; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a5si7355593pgw.454.2019.08.05.06.09.15; Mon, 05 Aug 2019 06:09:30 -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=@kernel.org header.s=default header.b=sTHUebjN; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729153AbfHENGj (ORCPT + 99 others); Mon, 5 Aug 2019 09:06:39 -0400 Received: from mail.kernel.org ([198.145.29.99]:43548 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729606AbfHENGi (ORCPT ); Mon, 5 Aug 2019 09:06:38 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 780CD214C6; Mon, 5 Aug 2019 13:06:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565010397; bh=Q0r+99K5J7kIeiEntfm7cv9iuAgk3irlIKMtudbxTh8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sTHUebjNAJQpFOOhbn4mCNrv9jiFQ1OfyovNWTQ56OLrwDnCw3DgpevezwvqBZ31a 0pzaX0C2ZPf4FuMCsEwKb7r/LhaOTrsr+R2jPInNXzGvHpchSL6HdsNWSZ/qNKXyAh NrMObr54rWk3L0CdTgYCx0ofR29hhVWce7v4LSbc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Benjamin Block , Jens Remus , Steffen Maier , "Martin K. Petersen" , Sasha Levin Subject: [PATCH 4.9 13/42] scsi: zfcp: fix GCC compiler warning emitted with -Wmaybe-uninitialized Date: Mon, 5 Aug 2019 15:02:39 +0200 Message-Id: <20190805124926.394145531@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190805124924.788666484@linuxfoundation.org> References: <20190805124924.788666484@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 484647088826f2f651acbda6bcf9536b8a466703 ] GCC v9 emits this warning: CC drivers/s390/scsi/zfcp_erp.o drivers/s390/scsi/zfcp_erp.c: In function 'zfcp_erp_action_enqueue': drivers/s390/scsi/zfcp_erp.c:217:26: warning: 'erp_action' may be used uninitialized in this function [-Wmaybe-uninitialized] 217 | struct zfcp_erp_action *erp_action; | ^~~~~~~~~~ This is a possible false positive case, as also documented in the GCC documentations: https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html#index-Wmaybe-uninitialized The actual code-sequence is like this: Various callers can invoke the function below with the argument "want" being one of: ZFCP_ERP_ACTION_REOPEN_ADAPTER, ZFCP_ERP_ACTION_REOPEN_PORT_FORCED, ZFCP_ERP_ACTION_REOPEN_PORT, or ZFCP_ERP_ACTION_REOPEN_LUN. zfcp_erp_action_enqueue(want, ...) ... need = zfcp_erp_required_act(want, ...) need = want ... maybe: need = ZFCP_ERP_ACTION_REOPEN_PORT maybe: need = ZFCP_ERP_ACTION_REOPEN_ADAPTER ... return need ... zfcp_erp_setup_act(need, ...) struct zfcp_erp_action *erp_action; // <== line 217 ... switch(need) { case ZFCP_ERP_ACTION_REOPEN_LUN: ... erp_action = &zfcp_sdev->erp_action; WARN_ON_ONCE(erp_action->port != port); // <== access ... break; case ZFCP_ERP_ACTION_REOPEN_PORT: case ZFCP_ERP_ACTION_REOPEN_PORT_FORCED: ... erp_action = &port->erp_action; WARN_ON_ONCE(erp_action->port != port); // <== access ... break; case ZFCP_ERP_ACTION_REOPEN_ADAPTER: ... erp_action = &adapter->erp_action; WARN_ON_ONCE(erp_action->port != NULL); // <== access ... break; } ... WARN_ON_ONCE(erp_action->adapter != adapter); // <== access When zfcp_erp_setup_act() is called, 'need' will never be anything else than one of the 4 possible enumeration-names that are used in the switch-case, and 'erp_action' is initialized for every one of them, before it is used. Thus the warning is a false positive, as documented. We introduce the extra if{} in the beginning to create an extra code-flow, so the compiler can be convinced that the switch-case will never see any other value. BUG_ON()/BUG() is intentionally not used to not crash anything, should this ever happen anyway - right now it's impossible, as argued above; and it doesn't introduce a 'default:' switch-case to retain warnings should 'enum zfcp_erp_act_type' ever be extended and no explicit case be introduced. See also v5.0 commit 399b6c8bc9f7 ("scsi: zfcp: drop old default switch case which might paper over missing case"). Signed-off-by: Benjamin Block Reviewed-by: Jens Remus Reviewed-by: Steffen Maier Signed-off-by: Martin K. Petersen Signed-off-by: Sasha Levin --- drivers/s390/scsi/zfcp_erp.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/s390/scsi/zfcp_erp.c b/drivers/s390/scsi/zfcp_erp.c index abe460eac7126..cc62d8cc8cfdd 100644 --- a/drivers/s390/scsi/zfcp_erp.c +++ b/drivers/s390/scsi/zfcp_erp.c @@ -10,6 +10,7 @@ #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt #include +#include #include "zfcp_ext.h" #include "zfcp_reqlist.h" @@ -244,6 +245,12 @@ static struct zfcp_erp_action *zfcp_erp_setup_act(int need, u32 act_status, struct zfcp_erp_action *erp_action; struct zfcp_scsi_dev *zfcp_sdev; + if (WARN_ON_ONCE(need != ZFCP_ERP_ACTION_REOPEN_LUN && + need != ZFCP_ERP_ACTION_REOPEN_PORT && + need != ZFCP_ERP_ACTION_REOPEN_PORT_FORCED && + need != ZFCP_ERP_ACTION_REOPEN_ADAPTER)) + return NULL; + switch (need) { case ZFCP_ERP_ACTION_REOPEN_LUN: zfcp_sdev = sdev_to_zfcp(sdev); -- 2.20.1