Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Damien Le Moal and committed by
Martin K. Petersen
71e3e85c 4e452369

+14 -23
+14 -23
drivers/scsi/scsi.c
··· 586 586 if ((buf[1] & 0x03) != 0x03) 587 587 return false; 588 588 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 + */ 590 602 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 - } 612 603 613 - return false; 604 + return cdlp == 0x01 || cdlp == 0x02; 614 605 } 615 606 616 607 /**