Skip to content

Commit 71e3e85

Browse files
damien-lemoalmartinkpetersen
authored andcommitted
scsi: core: Simplify scsi_cdl_check_cmd()
Reading the 800+ pages of SPC often leads to a brain shutdown and to less than ideal code... This resulted in the checks of the rwcdlp and cdlp fields in scsi_cdl_check_cmd() to have identical if-else branches. Replace this with a comment describing the cases we are interested in and replace the if-else code block with a simple test of the cdlp field that is used as the function return value. Reported-by: kernel test robot <lkp@intel.com> Reported-by: Julia Lawall <julia.lawall@inria.fr> Closes: https://lore.kernel.org/r/202306221657.BJHEADkz-lkp@intel.com/ Signed-off-by: Damien Le Moal <dlemoal@kernel.org> Link: https://lore.kernel.org/r/20230623073057.816199-1-dlemoal@kernel.org Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 4e45236 commit 71e3e85

File tree

1 file changed

+14
-23
lines changed

1 file changed

+14
-23
lines changed

drivers/scsi/scsi.c

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -586,31 +586,22 @@ static bool scsi_cdl_check_cmd(struct scsi_device *sdev, u8 opcode, u16 sa,
586586
if ((buf[1] & 0x03) != 0x03)
587587
return false;
588588

589-
/* See SPC-6, one command format of REPORT SUPPORTED OPERATION CODES */
589+
/*
590+
* See SPC-6, One_command parameter data format for
591+
* REPORT SUPPORTED OPERATION CODES. We have the following cases
592+
* depending on rwcdlp (buf[0] & 0x01) value:
593+
* - rwcdlp == 0: then cdlp indicates support for the A mode page when
594+
* it is equal to 1 and for the B mode page when it is
595+
* equal to 2.
596+
* - rwcdlp == 1: then cdlp indicates support for the T2A mode page
597+
* when it is equal to 1 and for the T2B mode page when
598+
* it is equal to 2.
599+
* Overall, to detect support for command duration limits, we only need
600+
* to check that cdlp is 1 or 2.
601+
*/
590602
cdlp = (buf[1] & 0x18) >> 3;
591-
if (buf[0] & 0x01) {
592-
/* rwcdlp == 1 */
593-
switch (cdlp) {
594-
case 0x01:
595-
/* T2A page */
596-
return true;
597-
case 0x02:
598-
/* T2B page */
599-
return true;
600-
}
601-
} else {
602-
/* rwcdlp == 0 */
603-
switch (cdlp) {
604-
case 0x01:
605-
/* A page */
606-
return true;
607-
case 0x02:
608-
/* B page */
609-
return true;
610-
}
611-
}
612603

613-
return false;
604+
return cdlp == 0x01 || cdlp == 0x02;
614605
}
615606

616607
/**

0 commit comments

Comments
 (0)