Commit 71e3e85c authored by Damien Le Moal's avatar Damien Le Moal Committed by Martin K. Petersen

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: default avatarkernel test robot <lkp@intel.com>
Reported-by: default avatarJulia Lawall <julia.lawall@inria.fr>
Closes: https://lore.kernel.org/r/202306221657.BJHEADkz-lkp@intel.com/Signed-off-by: default avatarDamien Le Moal <dlemoal@kernel.org>
Link: https://lore.kernel.org/r/20230623073057.816199-1-dlemoal@kernel.orgReviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent 4e452369
......@@ -586,31 +586,22 @@ static bool scsi_cdl_check_cmd(struct scsi_device *sdev, u8 opcode, u16 sa,
if ((buf[1] & 0x03) != 0x03)
return false;
/* See SPC-6, one command format of REPORT SUPPORTED OPERATION CODES */
/*
* See SPC-6, One_command parameter data format for
* REPORT SUPPORTED OPERATION CODES. We have the following cases
* depending on rwcdlp (buf[0] & 0x01) value:
* - rwcdlp == 0: then cdlp indicates support for the A mode page when
* it is equal to 1 and for the B mode page when it is
* equal to 2.
* - rwcdlp == 1: then cdlp indicates support for the T2A mode page
* when it is equal to 1 and for the T2B mode page when
* it is equal to 2.
* Overall, to detect support for command duration limits, we only need
* to check that cdlp is 1 or 2.
*/
cdlp = (buf[1] & 0x18) >> 3;
if (buf[0] & 0x01) {
/* rwcdlp == 1 */
switch (cdlp) {
case 0x01:
/* T2A page */
return true;
case 0x02:
/* T2B page */
return true;
}
} else {
/* rwcdlp == 0 */
switch (cdlp) {
case 0x01:
/* A page */
return true;
case 0x02:
/* B page */
return true;
}
}
return false;
return cdlp == 0x01 || cdlp == 0x02;
}
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment