Skip to content

Commit 77dd7d7

Browse files
Dick Kennedymartinkpetersen
authored andcommitted
scsi: lpfc: Fix less-than-zero comparison of unsigned value
The expression start_idx - dbg_cnt is evaluated using unsigned int arthithmetic (since these variables are unsigned ints) and hence can never be less than zero, so the less than comparison is never true. Rewrite the expression to check for start_idx being less than dbg_cnt. After the logic was corrected, temp_idx wasn't working correctly. So fix it as well. Link: https://lore.kernel.org/r/20200706204246.130416-1-jsmart2021@gmail.com Fixes: 372c187 ("scsi: lpfc: Add an internal trace log buffer") CC: Colin Ian King <colin.king@canonical.com> Signed-off-by: Dick Kennedy <dick.kennedy@broadcom.com> Signed-off-by: James Smart <jsmart2021@gmail.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com> Addresses-Coverity: ("Unsigned compared against 0")
1 parent 17105d9 commit 77dd7d7

1 file changed

Lines changed: 3 additions & 5 deletions

File tree

‎drivers/scsi/lpfc/lpfc_init.c‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14161,20 +14161,18 @@ void lpfc_dmp_dbg(struct lpfc_hba *phba)
1416114161
if ((start_idx + dbg_cnt) > (DBG_LOG_SZ - 1)) {
1416214162
temp_idx = (start_idx + dbg_cnt) % DBG_LOG_SZ;
1416314163
} else {
14164-
if ((start_idx - dbg_cnt) < 0) {
14164+
if (start_idx < dbg_cnt)
1416514165
start_idx = DBG_LOG_SZ - (dbg_cnt - start_idx);
14166-
temp_idx = 0;
14167-
} else {
14166+
else
1416814167
start_idx -= dbg_cnt;
14169-
}
1417014168
}
1417114169
}
1417214170
dev_info(&phba->pcidev->dev, "start %d end %d cnt %d\n",
1417314171
start_idx, temp_idx, dbg_cnt);
1417414172

1417514173
for (i = 0; i < dbg_cnt; i++) {
1417614174
if ((start_idx + i) < DBG_LOG_SZ)
14177-
temp_idx = (start_idx + i) % (DBG_LOG_SZ - 1);
14175+
temp_idx = (start_idx + i) % DBG_LOG_SZ;
1417814176
else
1417914177
temp_idx = j++;
1418014178
rem_nsec = do_div(phba->dbg_log[temp_idx].t_ns, NSEC_PER_SEC);

0 commit comments

Comments
 (0)