Skip to contentSkip to conversation

SCSI: esas2r: Static check fixes

PATCH New Bradley Grove 1 participant 8 messages Sep 5, 2013

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover SCSI: esas2r: Static check fixes

This series of patches fixes errors detected by smatch and coccinelle.

V2 adds an additional fix, removing a null check on a stack allocated array. The test was needed in older versions of the driver when the buffer was allocated on the heap.

Bradley Grove (7):
SCSI: esas2r: smatch - Use biwise rather than logical AND for checking
if any bit set
SCSI: esas2r: smatch - Fix dereference that occurs prior to check
SCSI: esas2r: smatch - Fix dereference that occurs prior to check
SCSI: esas2r: smatch - Fix overrun due to sprintf appending NULL
SCSI: esas2r: smatch - Remove test for impossible condition (uint8 >

    255)

SCSI: esas2r: coccinelle - Replace memcpy with struct assignment
SCSI: esas2r: Remove null test for stack allocated fw_coredump_buffer

 drivers/scsi/esas2r/esas2r_flash.c | 11 ++++++++---
 drivers/scsi/esas2r/esas2r_init.c  |  8 ++++----
 drivers/scsi/esas2r/esas2r_ioctl.c |  2 +-
 drivers/scsi/esas2r/esas2r_vda.c   |  7 +++++--
 4 files changed, 18 insertions(+), 10 deletions(-)
Signature · 1 line
1.8.1.4
#1 lore raw

PATCH v2 1/7 SCSI: esas2r: smatch - Use biwise rather than logical AND for checking if any bit set

---
 drivers/scsi/esas2r/esas2r_init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/esas2r/esas2r_init.c +1 -1
index 3a798e7..78b18c1 100644
@@ -808,7 +808,7 @@ static void esas2r_init_pci_cfg_space(struct esas2r_adapter *a)
 	int pcie_cap_reg;
 
 	pcie_cap_reg = pci_find_capability(a->pcid, PCI_CAP_ID_EXP);
-	if (0xffff && pcie_cap_reg) {
+	if (0xffff & pcie_cap_reg) {
 		u16 devcontrol;
 
 		pci_read_config_word(a->pcid, pcie_cap_reg + PCI_EXP_DEVCTL,
Signature · 1 line
1.8.1.4
#2 lore raw

PATCH v2 2/7 SCSI: esas2r: smatch - Fix dereference that occurs prior to check

In reply to Bradley Grove
---
 drivers/scsi/esas2r/esas2r_init.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/scsi/esas2r/esas2r_init.c +2 -1
index 78b18c1..9aaad0d 100644
@@ -665,7 +665,7 @@ void esas2r_kill_adapter(int i)
 
 int esas2r_cleanup(struct Scsi_Host *host)
 {
-	struct esas2r_adapter *a = (struct esas2r_adapter *)host->hostdata;
+	struct esas2r_adapter *a;
 	int index;
 
 	if (host == NULL) {
@@ -678,6 +678,7 @@ int esas2r_cleanup(struct Scsi_Host *host)
 	}
 
 	esas2r_debug("esas2r_cleanup called for host %p", host);
+	a = (struct esas2r_adapter *)host->hostdata;
 	index = a->index;
 	esas2r_kill_adapter(index);
 	return index;
Signature · 1 line
1.8.1.4
#3 lore raw

PATCH v2 3/7 SCSI: esas2r: smatch - Fix dereference that occurs prior to check

In reply to Bradley Grove
---
 drivers/scsi/esas2r/esas2r_flash.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/scsi/esas2r/esas2r_flash.c +6 -1
index 8582929..45e353f 100644
@@ -860,8 +860,13 @@ bool esas2r_process_fs_ioctl(struct esas2r_adapter *a,
 		return false;
 	}
 
+	if (fsc->command >= cmdcnt) {
+		fs->status = ATTO_STS_INV_FUNC;
+		return false;
+	}
+
 	func = cmd_to_fls_func[fsc->command];
-	if (fsc->command >= cmdcnt || func == 0xFF) {
+	if (func == 0xFF) {
 		fs->status = ATTO_STS_INV_FUNC;
 		return false;
 	}
Signature · 1 line
1.8.1.4
#4 lore raw

PATCH v2 4/7 SCSI: esas2r: smatch - Fix overrun due to sprintf appending NULL

In reply to Bradley Grove
---
 drivers/scsi/esas2r/esas2r_vda.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/scsi/esas2r/esas2r_vda.c +5 -2
index f8ec6d6..fd13928 100644
@@ -302,6 +302,7 @@ static void esas2r_complete_vda_ioctl(struct esas2r_adapter *a,
 		if (vi->cmd.cfg.cfg_func == VDA_CFG_GET_INIT) {
 			struct atto_ioctl_vda_cfg_cmd *cfg = &vi->cmd.cfg;
 			struct atto_vda_cfg_rsp *rsp = &rq->func_rsp.cfg_rsp;
+			char buf[sizeof(cfg->data.init.fw_release) + 1];
 
 			cfg->data_length =
 				cpu_to_le32(sizeof(struct atto_vda_cfg_init));
@@ -309,11 +310,13 @@ static void esas2r_complete_vda_ioctl(struct esas2r_adapter *a,
 				le32_to_cpu(rsp->vda_version);
 			cfg->data.init.fw_build = rsp->fw_build;
 
-			sprintf((char *)&cfg->data.init.fw_release,
-				"%1d.%02d",
+			snprintf(buf, sizeof(buf), "%1d.%02d",
 				(int)LOBYTE(le16_to_cpu(rsp->fw_release)),
 				(int)HIBYTE(le16_to_cpu(rsp->fw_release)));
 
+			memcpy(&cfg->data.init.fw_release, buf,
+			       sizeof(cfg->data.init.fw_release));
+
 			if (LOWORD(LOBYTE(cfg->data.init.fw_build)) == 'A')
 				cfg->data.init.fw_version =
 					cfg->data.init.fw_build;
Signature · 1 line
1.8.1.4
#5 lore raw

PATCH v2 5/7 SCSI: esas2r: smatch - Remove test for impossible condition (uint8 > 255)

In reply to Bradley Grove
---
 drivers/scsi/esas2r/esas2r_ioctl.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/scsi/esas2r/esas2r_ioctl.c +1 -1
index f3d0cb8..e5b0902 100644
@@ -415,7 +415,7 @@ static int csmi_ioctl_callback(struct esas2r_adapter *a,
 		lun = tm->lun;
 	}
 
-	if (path > 0 || tid > ESAS2R_MAX_ID) {
+	if (path > 0) {
 		rq->func_rsp.ioctl_rsp.csmi.csmi_status = cpu_to_le32(
 			CSMI_STS_INV_PARAM);
 		return false;
Signature · 1 line
1.8.1.4
#6 lore raw

PATCH v2 6/7 SCSI: esas2r: coccinelle - Replace memcpy with struct assignment

In reply to Bradley Grove
---
 drivers/scsi/esas2r/esas2r_flash.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/scsi/esas2r/esas2r_flash.c +2 -2
index 45e353f..2ec3c23 100644
@@ -1360,7 +1360,7 @@ void esas2r_nvram_set_defaults(struct esas2r_adapter *a)
 	u32 time = jiffies_to_msecs(jiffies);
 
 	esas2r_lock_clear_flags(&a->flags, AF_NVR_VALID);
-	memcpy(n, &default_sas_nvram, sizeof(struct esas2r_sas_nvram));
+	*n = default_sas_nvram;
 	n->sas_addr[3] |= 0x0F;
 	n->sas_addr[4] = HIBYTE(LOWORD(time));
 	n->sas_addr[5] = LOBYTE(LOWORD(time));
@@ -1378,7 +1378,7 @@ void esas2r_nvram_get_defaults(struct esas2r_adapter *a,
 	 * address out first.
 	 */
 	memcpy(&sas_addr[0], a->nvram->sas_addr, 8);
-	memcpy(nvram, &default_sas_nvram, sizeof(struct esas2r_sas_nvram));
+	*nvram = default_sas_nvram;
 	memcpy(&nvram->sas_addr[0], &sas_addr[0], 8);
 }
 
Signature · 1 line
1.8.1.4
#7 lore raw

PATCH v2 7/7 SCSI: esas2r: Remove null test for stack allocated fw_coredump_buffer

In reply to Bradley Grove
---
 drivers/scsi/esas2r/esas2r_init.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/scsi/esas2r/esas2r_init.c +1 -2
index 9aaad0d..da1869d 100644
@@ -1551,8 +1551,7 @@ void esas2r_reset_chip(struct esas2r_adapter *a)
 	 * to not overwrite a previous crash that was saved.
 	 */
 	if ((a->flags2 & AF2_COREDUMP_AVAIL)
-	    && !(a->flags2 & AF2_COREDUMP_SAVED)
-	    && a->fw_coredump_buff) {
+	    && !(a->flags2 & AF2_COREDUMP_SAVED)) {
 		esas2r_read_mem_block(a,
 				      a->fw_coredump_buff,
 				      MW_DATA_ADDR_SRAM + 0x80000,
Signature · 1 line
1.8.1.4