Skip to content

Commit 84eac32

Browse files
Wenchao HaoDamien Le Moal
authored andcommitted
ata: libata-scsi: simplify __ata_scsi_queuecmd()
This patch cleans up the code of __ata_scsi_queuecmd(). Since each branch of the "if" condition check that scmd->cmd_len is not zero, move this check out of the "if" to simplify the conditions being checked in the "else" branch. While at it, avoid the if-else-if-else structure using if-else if structure and remove the redundant rc local variable. This patch does not change the function logic. Signed-off-by: Wenchao Hao <haowenchao@huawei.com> Signed-off-by: Damien Le Moal <damien.lemoal@opensource.wdc.com>
1 parent db6a3f4 commit 84eac32

File tree

1 file changed

+21
-24
lines changed

1 file changed

+21
-24
lines changed

drivers/ata/libata-scsi.c

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3958,42 +3958,39 @@ int __ata_scsi_queuecmd(struct scsi_cmnd *scmd, struct ata_device *dev)
39583958
{
39593959
u8 scsi_op = scmd->cmnd[0];
39603960
ata_xlat_func_t xlat_func;
3961-
int rc = 0;
3961+
3962+
if (unlikely(!scmd->cmd_len))
3963+
goto bad_cdb_len;
39623964

39633965
if (dev->class == ATA_DEV_ATA || dev->class == ATA_DEV_ZAC) {
3964-
if (unlikely(!scmd->cmd_len || scmd->cmd_len > dev->cdb_len))
3966+
if (unlikely(scmd->cmd_len > dev->cdb_len))
39653967
goto bad_cdb_len;
39663968

39673969
xlat_func = ata_get_xlat_func(dev, scsi_op);
3968-
} else {
3969-
if (unlikely(!scmd->cmd_len))
3970-
goto bad_cdb_len;
3970+
} else if (likely((scsi_op != ATA_16) || !atapi_passthru16)) {
3971+
/* relay SCSI command to ATAPI device */
3972+
int len = COMMAND_SIZE(scsi_op);
39713973

3972-
xlat_func = NULL;
3973-
if (likely((scsi_op != ATA_16) || !atapi_passthru16)) {
3974-
/* relay SCSI command to ATAPI device */
3975-
int len = COMMAND_SIZE(scsi_op);
3976-
if (unlikely(len > scmd->cmd_len ||
3977-
len > dev->cdb_len ||
3978-
scmd->cmd_len > ATAPI_CDB_LEN))
3979-
goto bad_cdb_len;
3974+
if (unlikely(len > scmd->cmd_len ||
3975+
len > dev->cdb_len ||
3976+
scmd->cmd_len > ATAPI_CDB_LEN))
3977+
goto bad_cdb_len;
39803978

3981-
xlat_func = atapi_xlat;
3982-
} else {
3983-
/* ATA_16 passthru, treat as an ATA command */
3984-
if (unlikely(scmd->cmd_len > 16))
3985-
goto bad_cdb_len;
3979+
xlat_func = atapi_xlat;
3980+
} else {
3981+
/* ATA_16 passthru, treat as an ATA command */
3982+
if (unlikely(scmd->cmd_len > 16))
3983+
goto bad_cdb_len;
39863984

3987-
xlat_func = ata_get_xlat_func(dev, scsi_op);
3988-
}
3985+
xlat_func = ata_get_xlat_func(dev, scsi_op);
39893986
}
39903987

39913988
if (xlat_func)
3992-
rc = ata_scsi_translate(dev, scmd, xlat_func);
3993-
else
3994-
ata_scsi_simulate(dev, scmd);
3989+
return ata_scsi_translate(dev, scmd, xlat_func);
39953990

3996-
return rc;
3991+
ata_scsi_simulate(dev, scmd);
3992+
3993+
return 0;
39973994

39983995
bad_cdb_len:
39993996
scmd->result = DID_ERROR << 16;

0 commit comments

Comments
 (0)