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

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>

authored by

Wenchao Hao and committed by
Damien Le Moal
84eac327 db6a3f47

+21 -24
+21 -24
drivers/ata/libata-scsi.c
··· 3958 3958 { 3959 3959 u8 scsi_op = scmd->cmnd[0]; 3960 3960 ata_xlat_func_t xlat_func; 3961 - int rc = 0; 3961 + 3962 + if (unlikely(!scmd->cmd_len)) 3963 + goto bad_cdb_len; 3962 3964 3963 3965 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)) 3965 3967 goto bad_cdb_len; 3966 3968 3967 3969 xlat_func = ata_get_xlat_func(dev, scsi_op); 3968 - } else { 3969 - if (unlikely(!scmd->cmd_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); 3973 + 3974 + if (unlikely(len > scmd->cmd_len || 3975 + len > dev->cdb_len || 3976 + scmd->cmd_len > ATAPI_CDB_LEN)) 3970 3977 goto bad_cdb_len; 3971 3978 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; 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; 3980 3984 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; 3986 - 3987 - xlat_func = ata_get_xlat_func(dev, scsi_op); 3988 - } 3985 + xlat_func = ata_get_xlat_func(dev, scsi_op); 3989 3986 } 3990 3987 3991 3988 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); 3995 3990 3996 - return rc; 3991 + ata_scsi_simulate(dev, scmd); 3992 + 3993 + return 0; 3997 3994 3998 3995 bad_cdb_len: 3999 3996 scmd->result = DID_ERROR << 16;