Skip to content

Commit

Permalink
[SCSI] Fix range check in scsi_host_dif_capable()
Browse files Browse the repository at this point in the history
The range checking from fe54239 was bad. We would still end up walking
beyond the array as Type 3 is defined to be 4 in the protection
bitmask. Instead use ARRAY_SIZE() for the range check.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>
  • Loading branch information
Martin K. Petersen authored and James Bottomley committed Feb 24, 2013
1 parent 9d2696e commit 4d24834
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions include/scsi/scsi_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ static inline unsigned int scsi_host_dif_capable(struct Scsi_Host *shost, unsign
SHOST_DIF_TYPE2_PROTECTION,
SHOST_DIF_TYPE3_PROTECTION };

if (target_type > SHOST_DIF_TYPE3_PROTECTION)
if (target_type >= ARRAY_SIZE(cap))
return 0;

return shost->prot_capabilities & cap[target_type] ? target_type : 0;
Expand All @@ -887,7 +887,7 @@ static inline unsigned int scsi_host_dix_capable(struct Scsi_Host *shost, unsign
SHOST_DIX_TYPE2_PROTECTION,
SHOST_DIX_TYPE3_PROTECTION };

if (target_type > SHOST_DIX_TYPE3_PROTECTION)
if (target_type >= ARRAY_SIZE(cap))
return 0;

return shost->prot_capabilities & cap[target_type];
Expand Down

0 comments on commit 4d24834

Please sign in to comment.