Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp2765423ybh; Mon, 5 Aug 2019 06:30:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqzd0QpEVSiY8CzOsb1dG/cey0vNpKpgg1UCBG5i6Stx58R8s77u1/o7YU4XQMt7LjulvUmH X-Received: by 2002:a17:902:7448:: with SMTP id e8mr144590218plt.85.1565011821267; Mon, 05 Aug 2019 06:30:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565011821; cv=none; d=google.com; s=arc-20160816; b=j5SkvjlHcSjNfNduWsFvrXtdyUYFTZHCBwPZAk94EveT6pervJ0kThQzXHqJeu1Yna uB06WEUbybLtAVQ2QebfEARdQmyyjkYAPf2ANUKRdbke7FTmw/1jkNLINg39lucx41c+ fxJkPUy9fn0fw09ikSFzxBmbgxLI46qC53uwU2qaOb1RX/H5UZBPsE09GIaS8Hzq5Fx3 xZlb2f7b5bHWjq5EY6SzUDA++OhKxKZ2d8X1ba62G2MslWnepSmfL9l7KYtByB6yyF9a 3E3qmkdB76qEUPeKEHjN4vEp1oII8TCHTCD9/Imk6X19Nupf9zBrFcpx3tpCTNNGsJAd Lc8w== 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=OI+K2JZHcQTr+hcmw+pyStRODNHgPs2NmTF6PWFLuD8=; b=nZie7dwuarPjufVYmH1oESimiyxxFjxK8GL5+4bRb7BqBDpUHNP5bliFY0YFrP7lGt 3Ui5EpU/xFfCu4PUIFIGHRApNrYTTURjk/FYSQ1Wmg55gsNXJt27GSotkxgW3jAw6QVB 1Irnoh7WHUfHBR8KFtRD2sqlp+5xmzYkI8Jv52uXaYHmTMvPfFCW+K5wTU4Ik+hKzF8q 5izRwCocnjMEXgNO/TtjPydcupILWVnQNGx5Tv8gYFQwJjUqaHpnF6H+lph+f5MbCPPS UCFCoQilH+wUaKPmlXt1w0PEFk6Hbv9Xjw9xAk16xO0wQWqeacoJOaybN/8f7Y7MzBwf n6Jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=VSLPOUXd; 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 102si41328664plf.250.2019.08.05.06.30.05; Mon, 05 Aug 2019 06:30:21 -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=VSLPOUXd; 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 S1729948AbfHENVk (ORCPT + 99 others); Mon, 5 Aug 2019 09:21:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:57816 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730548AbfHENVg (ORCPT ); Mon, 5 Aug 2019 09:21:36 -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 08B2820644; Mon, 5 Aug 2019 13:21:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565011295; bh=LfqVRI0a5anIHSclf40jjYqrWoE2vDPcEfEHJgl4e+0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VSLPOUXdomzeCBrVp+6E/AfhP1HQ36DjTsQTOtzMRbGS4lobmfT+Ny+WPPXFu0sg6 +/FmuP5+iFJyZMsT3FSJJiJ246BEiYUc/1YwufR1ZPGP75BYlrnxEJToLQw2UOjn9+ MSs6a635kqqIJnMoc5YNisHdpZHsCd58370NU3Bw= 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 5.2 037/131] scsi: zfcp: fix GCC compiler warning emitted with -Wmaybe-uninitialized Date: Mon, 5 Aug 2019 15:02:04 +0200 Message-Id: <20190805124953.922567249@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190805124951.453337465@linuxfoundation.org> References: <20190805124951.453337465@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 e8fc28dba8dfc..96f0d34e94593 100644 --- a/drivers/s390/scsi/zfcp_erp.c +++ b/drivers/s390/scsi/zfcp_erp.c @@ -11,6 +11,7 @@ #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt #include +#include #include "zfcp_ext.h" #include "zfcp_reqlist.h" @@ -217,6 +218,12 @@ static struct zfcp_erp_action *zfcp_erp_setup_act(enum zfcp_erp_act_type need, 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