Skip to content

Commit 4ab7bb9

Browse files
damien-lemoalfloatious
authored andcommitted
ata: libata-scsi: Refactor ata_scsiop_maint_in()
Move the check for MI_REPORT_SUPPORTED_OPERATION_CODES from ata_scsi_simulate() into ata_scsiop_maint_in() to simplify ata_scsi_simulate() code. Furthermore, since an rbuff fill actor function returning a non-zero value causes no data to be returned for the command, directly return an error (return 1) for invalid command formt after setting the invalid field in cdb error. Signed-off-by: Damien Le Moal <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Niklas Cassel <[email protected]>
1 parent 44bdde1 commit 4ab7bb9

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

drivers/ata/libata-scsi.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3388,12 +3388,16 @@ static unsigned int ata_scsiop_maint_in(struct ata_scsi_args *args, u8 *rbuf)
33883388
struct ata_device *dev = args->dev;
33893389
u8 *cdb = args->cmd->cmnd;
33903390
u8 supported = 0, cdlp = 0, rwcdlp = 0;
3391-
unsigned int err = 0;
3391+
3392+
if ((cdb[1] & 0x1f) != MI_REPORT_SUPPORTED_OPERATION_CODES) {
3393+
ata_scsi_set_invalid_field(dev, args->cmd, 1, 0xff);
3394+
return 1;
3395+
}
33923396

33933397
if (cdb[2] != 1 && cdb[2] != 3) {
33943398
ata_dev_warn(dev, "invalid command format %d\n", cdb[2]);
3395-
err = 2;
3396-
goto out;
3399+
ata_scsi_set_invalid_field(dev, args->cmd, 1, 0xff);
3400+
return 1;
33973401
}
33983402

33993403
switch (cdb[3]) {
@@ -3461,11 +3465,12 @@ static unsigned int ata_scsiop_maint_in(struct ata_scsi_args *args, u8 *rbuf)
34613465
default:
34623466
break;
34633467
}
3464-
out:
3468+
34653469
/* One command format */
34663470
rbuf[0] = rwcdlp;
34673471
rbuf[1] = cdlp | supported;
3468-
return err;
3472+
3473+
return 0;
34693474
}
34703475

34713476
/**
@@ -4377,10 +4382,7 @@ void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd)
43774382
break;
43784383

43794384
case MAINTENANCE_IN:
4380-
if ((scsicmd[1] & 0x1f) == MI_REPORT_SUPPORTED_OPERATION_CODES)
4381-
ata_scsi_rbuf_fill(&args, ata_scsiop_maint_in);
4382-
else
4383-
ata_scsi_set_invalid_field(dev, cmd, 1, 0xff);
4385+
ata_scsi_rbuf_fill(&args, ata_scsiop_maint_in);
43844386
break;
43854387

43864388
/* all other commands */

0 commit comments

Comments
 (0)