]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
[SCSI] Fix range check in scsi_host_dif_capable()
authorMartin K. Petersen <martin.petersen@oracle.com>
Thu, 27 Sep 2012 02:39:44 +0000 (22:39 -0400)
committerJames Bottomley <JBottomley@Parallels.com>
Sun, 24 Feb 2013 09:26:18 +0000 (09:26 +0000)
The range checking from fe542396 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>
include/scsi/scsi_host.h

index 49084807eb6b37448bc659a2c0290768038d89d3..2b6956e9853dd576d47af629e4635c24c92c9c97 100644 (file)
@@ -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;
@@ -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];