lpfc: Fix less-than-zero comparison of unsigned value
Subsystems (2)
PATCH 1/1 lpfc: Fix less-than-zero comparison of unsigned value
The expressions 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. Re-write the expression to check for start_idx being less than dbg_cnt.
After the logic was corrected, temp_idx wasn't working correct. So fix it was fixed as well.
Addresses-Coverity: ("Unsigned compared against 0")
--- drivers/scsi/lpfc/lpfc_init.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/scsi/lpfc/lpfc_init.c +3 -5
@@ -14161,12 +14161,10 @@ void lpfc_dmp_dbg(struct lpfc_hba *phba)if ((start_idx + dbg_cnt) > (DBG_LOG_SZ -1 )) { temp_idx = (start_idx + dbg_cnt) %DBG_LOG_SZ ; }else { -if ((start_idx - dbg_cnt) <0 ) { +if (start_idx < dbg_cnt) start_idx =DBG_LOG_SZ - (dbg_cnt - start_idx); - temp_idx =0 ; - }else { +else start_idx -= dbg_cnt; - } } } dev_info(&phba->pcidev->dev, "start %d end %d cnt %d\n",
@@ -14174,7 +14172,7 @@ void lpfc_dmp_dbg(struct lpfc_hba *phba)for (i =0 ; i < dbg_cnt; i++) {if ((start_idx + i) <DBG_LOG_SZ ) - temp_idx = (start_idx + i) % (DBG_LOG_SZ -1 ); + temp_idx = (start_idx + i) %DBG_LOG_SZ ;else temp_idx = j++; rem_nsec =do_div (phba->dbg_log[temp_idx].t_ns,NSEC_PER_SEC );
Signature · 1 line
2.25.0
Martin K. Petersen
AppliedQuoted 7 lines · James Smart
The expressions
start_idx-dbg_cntis 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. Re-write the expression to check forstart_idxbeing less thandbg_cnt.After the logic was corrected,
temp_idxwasn't working correct. So fix it was fixed as well.
Applied to 5.9/scsi-queue, thanks!
[1/1] scsi: lpfc: Fix less-than-zero comparison of unsigned value
https://git.kernel.org/mkp/scsi/c/77dd7d7b3442
Signature · 1 line
Martin K. Petersen Oracle Linux Engineering