Skip to contentSkip to conversation

qla4xxx: don't free pool that wasn't allocated

PATCH In review Dan Carpenter 3 participants 4 messages May 17, 2012

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

PATCH 1/1 qla4xxx: don't free pool that wasn't allocated

In the original code if dma_pool_alloc() fails then we call dma_pool_free(). The problem is that "chap_table" is NULL and "chap_dma" is uninitialized so it will cause an error.

drivers/scsi/qla4xxx/ql4_mbx.c +2 -4
index 7ac21da..21dce92 100644
@@ -1329,10 +1329,8 @@ int qla4xxx_get_chap(struct scsi_qla_host *ha, char *username, char *password,
 	dma_addr_t chap_dma;
 
 	chap_table = dma_pool_alloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma);
-	if (chap_table = NULL) {
-		ret = -ENOMEM;
-		goto exit_get_chap;
-	}
+	if (chap_table = NULL)
+		return -ENOMEM;
 
 	chap_size = sizeof(struct ql4_chap_table);
 	memset(chap_table, 0, chap_size);
#1 lore raw

PATCH 1/1 qla2xxx: don't free pool that wasn't allocated

In the original code, if dma_pool_alloc() fails then we call dma_pool_free(). It causes an error, possibly a NULL dereference.

drivers/scsi/qla2xxx/qla_iocb.c +1 -1
index c17975d..44380d3 100644
@@ -2386,7 +2386,7 @@ sufficient_dsds:
 		if (!ctx->fcp_cmnd) {
 			ql_log(ql_log_fatal, vha, 0x3011,
 			    "Failed to allocate fcp_cmnd for cmd=%p.\n", cmd);
-			goto queuing_error_fcp_cmnd;
+			goto queuing_error;
 		}
 
 		/* Initialize the DSD list and dma handle */
Acked-by on v1 1/1
#2 lore raw

Re: [patch] [SCSI] qla2xxx: don't free pool that wasn't allocated

Quoted 19 lines · Dan Carpenter

In the original code, if dma_pool_alloc() fails then we call dma_pool_free(). It causes an error, possibly a NULL dereference.

drivers/scsi/qla2xxx/qla_iocb.c +1 -2
index c17975d..44380d3 100644
@@ -2386,7 +2386,7 @@ sufficient_dsds:
              if (!ctx->fcp_cmnd) {
                      ql_log(ql_log_fatal, vha, 0x3011,
                          "Failed to allocate fcp_cmnd for cmd=%p.\n", cmd);
-                     goto queuing_error_fcp_cmnd;
+                     goto queuing_error;
              }
 
              /* Initialize the DSD list and dma handle */
--
Quoted 5 lines

To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Thanks for the patch.

This message and any attached documents contain information from QLogic Corporation or its wholly-owned subsidiaries that may be confidential. If you are not the intended recipient, you may not read, copy, distribute, or use this information. If you have received this transmission in error, please notify the sender immediately by reply e-mail and then delete this message.

Reviewed-by on v1 1/1
#3 lore raw
In reply to Dan Carpenter
Quoted 13 lines · Dan Carpenter

In the original code if dma_pool_alloc() fails then we call dma_pool_free(). The problem is that "chap_table" is NULL and "chap_dma" is uninitialized so it will cause an error.

drivers/scsi/qla4xxx/ql4_mbx.c +0 -0
index 7ac21da..21dce92 100644
@@ -1329,10 +1329,8 @@ int qla4xxx_get_chap(struct scsi_qla_host *ha, char *username, char *password,
 	dma_addr_t chap_dma;
 

drivers/scsi/qla4xxx/ql4_mbx.c int qla4xxx_get_chap(struct scsi_qla_host *ha, char *username, char *password, · line 1336

Quoted 10 lines
drivers/scsi/qla4xxx/ql4_mbx.c +2 -4
 	chap_table = dma_pool_alloc(ha->chap_dma_pool, GFP_KERNEL, &chap_dma);
-	if (chap_table = NULL) {
-		ret = -ENOMEM;
-		goto exit_get_chap;
-	}
+	if (chap_table = NULL)
+		return -ENOMEM;
 
 	chap_size = sizeof(struct ql4_chap_table);
 	memset(chap_table, 0, chap_size);

I thought dma_pool_free checked the vaddr/chap_table like how kfree checks for nulls. You are right. Looks ok to me.