Skip to contentSkip to conversation

libsas: fix test for negative unsigned and typos

PATCH Superseded roel kluin 2 participants 2 messages Nov 29, 2008 – Dec 3, 2008

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

roel kluin

author
#0 lore raw

PATCH 1/1 libsas: fix test for negative unsigned and typos

unsigned req->data_len cannot be negative, and fix typo

---
I am not sure whether this is what was intended, please review.

drivers/scsi/libsas/sas_host_smp.c +6 -6
index 16f9312..6eb0779 100644
@@ -199,12 +199,12 @@ int sas_smp_host_handler(struct Scsi_Host *shost, struct request *req,
 		break;
 
 	case SMP_DISCOVER:
-		req->data_len =- 16;
-		if (req->data_len < 0) {
+		if (req->data_len < 15) {
 			req->data_len = 0;
 			error = -EINVAL;
 			goto out;
 		}
+		req->data_len -= 16;
 		resp_data_len -= 56;
 		sas_host_smp_discover(sas_ha, resp_data, req_data[9]);
 		break;
@@ -215,12 +215,12 @@ int sas_smp_host_handler(struct Scsi_Host *shost, struct request *req,
 		break;
 
 	case SMP_REPORT_PHY_SATA:
-		req->data_len =- 16;
-		if (req->data_len < 0) {
+		if (req->data_len < 15) {
 			req->data_len = 0;
 			error = -EINVAL;
 			goto out;
 		}
+		req->data_len -= 16;
 		resp_data_len -= 60;
 		sas_report_phy_sata(sas_ha, resp_data, req_data[9]);
 		break;
@@ -238,12 +238,12 @@ int sas_smp_host_handler(struct Scsi_Host *shost, struct request *req,
 		break;
 
 	case SMP_PHY_CONTROL:
-		req->data_len =- 44;
-		if (req->data_len < 0) {
+		if (req->data_len < 43) {
 			req->data_len = 0;
 			error = -EINVAL;
 			goto out;
 		}
+		req->data_len -= 44;
 		resp_data_len -= 8;
 		sas_phy_control(sas_ha, req_data[9], req_data[10],
 				req_data[32] >> 4, req_data[33] >> 4,
maintainer
#1 lore raw
Quoted 5 lines · roel kluin

unsigned req->data_len cannot be negative, and fix typo

---
I am not sure whether this is what was intended, please review.

I think it was. The fix looks like we need it. However:

Quoted 5 lines
drivers/scsi/libsas/sas_host_smp.c +0 -0
index 16f9312..6eb0779 100644

drivers/scsi/libsas/sas_host_smp.c int sas_smp_host_handler(struct Scsi_Host *shost, struct request *req, · line 206

Quoted 10 lines
drivers/scsi/libsas/sas_host_smp.c +1 -2
@@ -199,12 +199,12 @@ int sas_smp_host_handler(struct Scsi_Host *shost, struct request *req,
 		break;
 
 	case SMP_DISCOVER:
-		req->data_len =- 16;
-		if (req->data_len < 0) {
+		if (req->data_len < 15) {
 			req->data_len = 0;
 			error = -EINVAL;
 			goto out;
 		}

What I don't like about this code is the magic numbers for lengths. This patch now doubles them (and makes them even more magic by having < n-1). How about fixing it like this instead:

if ((int)req->data_len < 0) {
...

That way the signed comparison just works if there was a negative overflow?

Thanks,

James