scsi: zfcp: fix GCC compiler warning emitted with -Wmaybe-uninitialized [Linux 4.4.188]

This Linux kernel change "scsi: zfcp: fix GCC compiler warning emitted with -Wmaybe-uninitialized" is included in the Linux 4.4.188 release. This change is authored by Benjamin Block <bblock [at]> on Tue Jul 2 23:02:02 2019 +0200. The commit for this change in Linux stable tree is ad96d13 (patch) which is from upstream commit 4846470. The same Linux upstream change may have been applied to various maintained Linux releases and you can find all Linux releases containing changes from upstream 4846470.

scsi: zfcp: fix GCC compiler warning emitted with -Wmaybe-uninitialized

[ 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

The actual code-sequence is like this:
    Various callers can invoke the function below with the argument "want"
    being one of:

    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
                    erp_action = &port->erp_action;
                    WARN_ON_ONCE(erp_action->port != port); // <== access
                    erp_action = &adapter->erp_action;
                    WARN_ON_ONCE(erp_action->port != NULL); // <== access
            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 <>

There are 7 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 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 abe460e..cc62d8c 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 <linux/kthread.h>
+#include <linux/bug.h>
 #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;

+            need != ZFCP_ERP_ACTION_REOPEN_PORT &&
+            need != ZFCP_ERP_ACTION_REOPEN_PORT_FORCED &&
+            need != ZFCP_ERP_ACTION_REOPEN_ADAPTER))
+       return NULL;
    switch (need) {
        zfcp_sdev = sdev_to_zfcp(sdev);

Leave a Reply

Your email address will not be published. Required fields are marked *