Received: by 2002:a25:b794:0:0:0:0:0 with SMTP id n20csp2747309ybh; Mon, 5 Aug 2019 06:13:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqztjNU1MhxWCXHKnVZLIxRD+lvKI6+kMXgQlb4Wl3sLddIBNYCV5EbtljwhfCxVn1dND4X1 X-Received: by 2002:a65:6850:: with SMTP id q16mr101255113pgt.423.1565010825139; Mon, 05 Aug 2019 06:13:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565010825; cv=none; d=google.com; s=arc-20160816; b=MeN0GQzjJ+ZSNxw3coCGDA9nl38VVe3MAZA/Q6cD005gB19u8DM1hbX5yVkjMP+B5Y gp4skucrLYbOXwmwqnMIWrv1qRGxl4lea8F72nT/B/pgMtLGF7bW+Wq6Zcwq01AYByfd bRjVLHnIZcdFFdtcGbkcA5ZuFfy+2Y8nSyp86D2mOg/r+0+XKtgNz49JJu5NCoXEC/Lx /Ec68ih1MxxmxofD0sbowYYSyRI6OfvBQHn3XBP2OI6mtt3jJQbDZii5sCfu4MyVuO6G tr0m91gPNZ1/prxXRwukuz7+jpwAkMBQkXvnHCACDaDKIa9U4xCLmCop85FFUlZPvekd An3g== 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=zo0eC/CeRFFwfENvW9HiBxo9GbMdUGq6Jvg53rl6kiw=; b=EJABppf9F3tEoXppZ3s021dvsIH0SIkZTG6/Q8lb/rLYPDzfFyFK0ENdaUkB+H+FEw 31sbudlzkLwIx3w0I8ubrZIv8ZnZqtbehUrCra8jyYc0Yxt67Yaxg08mkP0IinEFxf4B oKjNk5lA9gxnMvtgHzJUO30SEptGST3Qastrh/7OHDno5NKjaeNzZ8SjEET5wqj3nDVt 5R49Gb4iR6gOEYvqV6yssSn6DaEc+Tu+1CMxOdiwQDaETkc2SC+90i+S8XxOmveIqVJ7 txuuAcG5IT+uly85wWSQZkX4geWYpznWT8Vh6x5SLHERIeHZnX5Wx0ZqfFWDKbTlZNlp H8qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=YkeQSpQm; 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 i198si43807025pfe.228.2019.08.05.06.13.29; Mon, 05 Aug 2019 06:13:45 -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=YkeQSpQm; 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 S1730434AbfHENK4 (ORCPT + 99 others); Mon, 5 Aug 2019 09:10:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:50020 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730420AbfHENKx (ORCPT ); Mon, 5 Aug 2019 09:10:53 -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 0890B21874; Mon, 5 Aug 2019 13:10:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1565010652; bh=4uf/pER265RJHkRXVJyrW+7dtTx8C978xgkpJD07Zwc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YkeQSpQmrT2sU3Ka+VsXA2y6FAuggzZOV4MfCPm5vCiBJjDMBgO1SNBFpUE8thoGe acDfm8ohXWWaMCBLUgPcTvQ+5HNbtMR1Uf158dStmzN/k69zPT7AnmS+cmy9mQ1K+k j688w3f1z+rm8biFvXsJwJYbSy1Oen0ulwZITY7M= 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.19 21/74] scsi: zfcp: fix GCC compiler warning emitted with -Wmaybe-uninitialized Date: Mon, 5 Aug 2019 15:02:34 +0200 Message-Id: <20190805124937.489556604@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190805124935.819068648@linuxfoundation.org> References: <20190805124935.819068648@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 ebdbc457003fe..332701db7379d 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" @@ -238,6 +239,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