* [PATCH] scsi: Simplify scsi_cdl_check_cmd()
@ 2023-06-23 0:29 Damien Le Moal
2023-06-23 5:40 ` Christoph Hellwig
0 siblings, 1 reply; 4+ messages in thread
From: Damien Le Moal @ 2023-06-23 0:29 UTC (permalink / raw)
To: Martin K . Petersen, linux-scsi; +Cc: Niklas Cassel
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>
---
drivers/scsi/scsi.c | 37 ++++++++++++++-----------------------
1 file changed, 14 insertions(+), 23 deletions(-)
diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index c4bf99a842f3..cea10616e630 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -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 format of 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;
}
/**
--
2.40.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] scsi: Simplify scsi_cdl_check_cmd()
2023-06-23 0:29 [PATCH] scsi: Simplify scsi_cdl_check_cmd() Damien Le Moal
@ 2023-06-23 5:40 ` Christoph Hellwig
2023-06-23 7:26 ` Damien Le Moal
0 siblings, 1 reply; 4+ messages in thread
From: Christoph Hellwig @ 2023-06-23 5:40 UTC (permalink / raw)
To: Damien Le Moal; +Cc: Martin K . Petersen, linux-scsi, Niklas Cassel
> + * See SPC-6, one command format of REPORT SUPPORTED OPERATION CODES.
/one/on/ or even on the?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] scsi: Simplify scsi_cdl_check_cmd()
2023-06-23 5:40 ` Christoph Hellwig
@ 2023-06-23 7:26 ` Damien Le Moal
2023-06-26 7:58 ` Christoph Hellwig
0 siblings, 1 reply; 4+ messages in thread
From: Damien Le Moal @ 2023-06-23 7:26 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: Martin K . Petersen, linux-scsi, Niklas Cassel
On 6/23/23 14:40, Christoph Hellwig wrote:
>> + * See SPC-6, one command format of REPORT SUPPORTED OPERATION CODES.
>
> /one/on/ or even on the?
The spec has that as "One_command parameter data format", as opposed to the
other format which is "All_command parameter data format". Will re-phrase it
exactly like that.
--
Damien Le Moal
Western Digital Research
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] scsi: Simplify scsi_cdl_check_cmd()
2023-06-23 7:26 ` Damien Le Moal
@ 2023-06-26 7:58 ` Christoph Hellwig
0 siblings, 0 replies; 4+ messages in thread
From: Christoph Hellwig @ 2023-06-26 7:58 UTC (permalink / raw)
To: Damien Le Moal
Cc: Christoph Hellwig, Martin K . Petersen, linux-scsi, Niklas Cassel
On Fri, Jun 23, 2023 at 04:26:09PM +0900, Damien Le Moal wrote:
> On 6/23/23 14:40, Christoph Hellwig wrote:
> >> + * See SPC-6, one command format of REPORT SUPPORTED OPERATION CODES.
> >
> > /one/on/ or even on the?
>
> The spec has that as "One_command parameter data format", as opposed to the
> other format which is "All_command parameter data format". Will re-phrase it
> exactly like that.
Oh, ok.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-06-26 7:58 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-23 0:29 [PATCH] scsi: Simplify scsi_cdl_check_cmd() Damien Le Moal
2023-06-23 5:40 ` Christoph Hellwig
2023-06-23 7:26 ` Damien Le Moal
2023-06-26 7:58 ` Christoph Hellwig
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox