linux-stable/drivers/s390/scsi
Benjamin Block 4846470888 scsi: zfcp: fix GCC compiler warning emitted with -Wmaybe-uninitialized
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 399b6c8bc9 ("scsi: zfcp: drop old
default switch case which might paper over missing case").

Signed-off-by: Benjamin Block <bblock@linux.ibm.com>
Reviewed-by: Jens Remus <jremus@linux.ibm.com>
Reviewed-by: Steffen Maier <maier@linux.ibm.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2019-07-11 21:04:23 -04:00
..
Makefile s390: add a few more SPDX identifiers 2017-12-05 07:51:09 +01:00
zfcp_aux.c scsi: zfcp: fix sysfs block queue limit output for max_segment_size 2019-01-29 01:14:59 -05:00
zfcp_ccw.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
zfcp_dbf.c scsi: zfcp: silence all W=1 build warnings for existing kdoc 2018-11-15 15:01:18 -05:00
zfcp_dbf.h scsi: zfcp: silence remaining kdoc warnings in header files 2018-11-15 15:01:18 -05:00
zfcp_def.h scsi: zfcp: use enum zfcp_erp_steps for struct zfcp_erp_action.step 2018-11-15 15:01:18 -05:00
zfcp_erp.c scsi: zfcp: fix GCC compiler warning emitted with -Wmaybe-uninitialized 2019-07-11 21:04:23 -04:00
zfcp_ext.h scsi: zfcp: fix scsi_eh host reset with port_forced ERP for non-NPIV FCP devices 2019-03-27 21:26:12 -04:00
zfcp_fc.c scsi: s390: zfcp_fc: use sg helper to iterate over scatterlist 2019-06-20 15:21:33 -04:00
zfcp_fc.h scsi: zfcp: silence remaining kdoc warnings in header files 2018-11-15 15:01:18 -05:00
zfcp_fsf.c scsi: zfcp: fix request object use-after-free in send path causing wrong traces 2019-07-11 21:04:22 -04:00
zfcp_fsf.h scsi: zfcp: silence remaining kdoc warnings in header files 2018-11-15 15:01:18 -05:00
zfcp_qdio.c s390/qdio: make SBAL address array type-safe 2019-02-07 11:57:07 +01:00
zfcp_qdio.h scsi: zfcp: silence remaining kdoc warnings in header files 2018-11-15 15:01:18 -05:00
zfcp_reqlist.h scsi: zfcp: silence remaining kdoc warnings in header files 2018-11-15 15:01:18 -05:00
zfcp_scsi.c scsi: zfcp: fix scsi_eh host reset with port_forced ERP for non-NPIV FCP devices 2019-03-27 21:26:12 -04:00
zfcp_sysfs.c scsi: zfcp: support SCSI_ADAPTER_RESET via scsi_host sysfs attribute host_reset 2018-05-18 11:28:15 -04:00
zfcp_unit.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00