Skip to contentSkip to conversation

Fix incorrect memset in bnx2fc_parse_fcp_rsp

PATCH In review Andi Kleen 2 participants 2 messages Sep 3, 2012 – Sep 4, 2012

Subsystems (2)
lore
Share & tools
lore

Andi Kleen

author
#0 lore raw

PATCH 1/1 Fix incorrect memset in bnx2fc_parse_fcp_rsp

gcc 4.8 warns because the memset only clears sizeof(char *) bytes, not the whole buffer. Use the correct buffer size and clear the whole sense buffer.

/backup/lsrc/git/linux-lto-2.6/drivers/scsi/bnx2fc/bnx2fc_io.c: In function 'bnx2fc_parse_fcp_rsp':
/backup/lsrc/git/linux-lto-2.6/drivers/scsi/bnx2fc/bnx2fc_io.c:1810:41:
warning: argument to 'sizeof' in 'memset' call is the same expression as the destination; did you mean to provide an explicit length? [-Wsizeof-pointer-memaccess]

   memset(sc_cmd->sense_buffer, 0, sizeof(sc_cmd->sense_buffer));
                                         ^
drivers/scsi/bnx2fc/bnx2fc_io.c +1 -1
index 73f231c..8d4626c 100644
@@ -1807,7 +1807,7 @@ static void bnx2fc_parse_fcp_rsp(struct bnx2fc_cmd *io_req,
 			fcp_sns_len = SCSI_SENSE_BUFFERSIZE;
 		}
 
-		memset(sc_cmd->sense_buffer, 0, sizeof(sc_cmd->sense_buffer));
+		memset(sc_cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
 		if (fcp_sns_len)
 			memcpy(sc_cmd->sense_buffer, rq_data, fcp_sns_len);
 
Signature · 1 line
[email protected] -- Speaking for myself only.
Acked-by on v1 1/1
#1 lore raw
Quoted 23 lines · Andi Kleen

gcc 4.8 warns because the memset only clears sizeof(char *) bytes, not the whole buffer. Use the correct buffer size and clear the whole sense buffer.

/backup/lsrc/git/linux-lto-2.6/drivers/scsi/bnx2fc/bnx2fc_io.c: In function 'bnx2fc_parse_fcp_rsp':
/backup/lsrc/git/linux-lto-2.6/drivers/scsi/bnx2fc/bnx2fc_io.c:1810:41:
warning: argument to 'sizeof' in 'memset' call is the same expression as the destination; did you mean to provide an explicit length? [-Wsizeof-pointer-memaccess]

    memset(sc_cmd->sense_buffer, 0, sizeof(sc_cmd->sense_buffer));
                                          ^
drivers/scsi/bnx2fc/bnx2fc_io.c +0 -0
index 73f231c..8d4626c 100644

drivers/scsi/bnx2fc/bnx2fc_io.c static void bnx2fc_parse_fcp_rsp(struct bnx2fc_cmd *io_req, · line 1813

Quoted 8 lines
drivers/scsi/bnx2fc/bnx2fc_io.c +1 -1
@@ -1807,7 +1807,7 @@ static void bnx2fc_parse_fcp_rsp(struct bnx2fc_cmd *io_req,
  			fcp_sns_len = SCSI_SENSE_BUFFERSIZE;
  		}
 
-		memset(sc_cmd->sense_buffer, 0, sizeof(sc_cmd->sense_buffer));
+		memset(sc_cmd->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
  		if (fcp_sns_len)
  			memcpy(sc_cmd->sense_buffer, rq_data, fcp_sns_len);
 

Thanks Andi. Looks good to me.