Re: [PATCH 1/1] [SCSI] mpt2sas: Convert non-returned local variable to boolean when relevant

From: Joe Perches
Date: Wed Dec 17 2014 - 13:52:52 EST


On Wed, 2014-12-17 at 15:56 +0100, Quentin Lambert wrote:
> This patch was produced using Coccinelle. A simplified version of the
> semantic patch is:

[...]

Interesting.

Some of these conversions show what I think is
relatively poor logic. For instance:

> diff --git a/drivers/scsi/mpt2sas/mpt2sas_base.c b/drivers/scsi/mpt2sas/mpt2sas_base.c
[]
> @@ -1414,10 +1414,10 @@ _base_enable_msix(struct MPT2SAS_ADAPTER *ioc)
> struct msix_entry *entries, *a;
> int r;
> int i;
> - u8 try_msix = 0;
> + bool try_msix = false;
>
> if (msix_disable == -1 || msix_disable == 0)
> - try_msix = 1;
> + try_msix = true;
>
> if (!try_msix)
> goto try_ioapic;

This might as well remove the try_msix variable
and become:

if (msix_disable != -1 && msix_disable != 0)
goto try_ioapic;

> @@ -3236,7 +3236,7 @@ mpt2sas_base_sas_iounit_control(struct MPT2SAS_ADAPTER *ioc,
> u16 smid;
> u32 ioc_state;
> unsigned long timeleft;
> - u8 issue_reset;
> + bool issue_reset;
> int rc;
> void *request;
> u16 wait_state_count;
> @@ -3300,7 +3300,7 @@ mpt2sas_base_sas_iounit_control(struct MPT2SAS_ADAPTER *ioc,
> _debug_dump_mf(mpi_request,
> sizeof(Mpi2SasIoUnitControlRequest_t)/4);
> if (!(ioc->base_cmds.status & MPT2_CMD_RESET))
> - issue_reset = 1;
> + issue_reset = true;
> goto issue_host_reset;
> }
> if (ioc->base_cmds.status & MPT2_CMD_REPLY_VALID)

It seems like issue_reset should be initialized to false.
issue_reset can be an arbitrary value before the goto issue_host_reset
which is:

issue_host_reset:
if (issue_reset)
mpt2sas_base_hard_reset_handler(ioc, CAN_SLEEP,
FORCE_BIG_HAMMER);

> @@ -3341,7 +3341,7 @@ mpt2sas_base_scsi_enclosure_processor(struct MPT2SAS_ADAPTER *ioc,
> u16 smid;
> u32 ioc_state;p
> unsigned long timeleft;
> - u8 issue_reset;
> + bool issue_reset;
> int rc;
> void *request;
> u16 wait_state_count;
> @@ -3398,7 +3398,7 @@ mpt2sas_base_scsi_enclosure_processor(struct MPT2SAS_ADAPTER *ioc,
> _debug_dump_mf(mpi_request,
> sizeof(Mpi2SepRequest_t)/4);
> if (!(ioc->base_cmds.status & MPT2_CMD_RESET))
> - issue_reset = 1;
> + issue_reset = true;
> goto issue_host_reset;
> }

same

I stopped looking here.


--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/