mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v2] ata: libata-scsi: Make __ata_scsi_queuecmd() parameters check more clearly
@ 2022-01-05 20:27 Wenchao Hao
  2022-01-05  7:39 ` Damien Le Moal
  0 siblings, 1 reply; 4+ messages in thread
From: Wenchao Hao @ 2022-01-05 20:27 UTC (permalink / raw)
  To: Damien Le Moal, linux-ide, linux-kernel; +Cc: Zhiqiang Liu, Wenchao Hao

This is just a clean code. Since each branch of "if" state would check
scmd->cmd_len, so move the check of scmd->cmd_len out of "if" state to
simplify input parameters check.

And remove redundant init of xlat_func at hand

The patch do not change origin function logic.

Signed-off-by: Wenchao Hao <haowenchao@huawei.com>
---
 drivers/ata/libata-scsi.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 313e9475507b..ab8a2833dfec 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -4023,16 +4023,15 @@ int __ata_scsi_queuecmd(struct scsi_cmnd *scmd, struct ata_device *dev)
 	ata_xlat_func_t xlat_func;
 	int rc = 0;
 
+	if (unlikely(!scmd->cmd_len))
+		goto bad_cdb_len;
+
 	if (dev->class == ATA_DEV_ATA || dev->class == ATA_DEV_ZAC) {
-		if (unlikely(!scmd->cmd_len || scmd->cmd_len > dev->cdb_len))
+		if (unlikely(scmd->cmd_len > dev->cdb_len))
 			goto bad_cdb_len;
 
 		xlat_func = ata_get_xlat_func(dev, scsi_op);
 	} else {
-		if (unlikely(!scmd->cmd_len))
-			goto bad_cdb_len;
-
-		xlat_func = NULL;
 		if (likely((scsi_op != ATA_16) || !atapi_passthru16)) {
 			/* relay SCSI command to ATAPI device */
 			int len = COMMAND_SIZE(scsi_op);
-- 
2.32.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-01-05  9:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-05 20:27 [PATCH v2] ata: libata-scsi: Make __ata_scsi_queuecmd() parameters check more clearly Wenchao Hao
2022-01-05  7:39 ` Damien Le Moal
2022-01-05  8:48   ` Wenchao Hao
2022-01-05  9:07     ` Damien Le Moal

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®