lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Tue, 4 Jan 2022 21:17:04 -0500
From:   Wenchao Hao <haowenchao@...wei.com>
To:     Damien Le Moal <damien.lemoal@...nsource.wdc.com>,
        <linux-ide@...r.kernel.org>, <linux-kernel@...r.kernel.org>
CC:     Zhiqiang Liu <liuzhiqiang26@...wei.com>,
        Wenchao Hao <haowenchao@...wei.com>
Subject: [PATCH demo] ata_scsi_queuecmd: Make input parameters check more clearly

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 the logic of input parameters check.

The patch do not change origin function logic.

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

diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 313e9475507b..1c653b5327db 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -4020,19 +4020,18 @@ void ata_scsi_dump_cdb(struct ata_port *ap, struct scsi_cmnd *cmd)
 int __ata_scsi_queuecmd(struct scsi_cmnd *scmd, struct ata_device *dev)
 {
 	u8 scsi_op = scmd->cmnd[0];
-	ata_xlat_func_t xlat_func;
+	ata_xlat_func_t xlat_func = NULL;
 	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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ