public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: James Smart <jsmart2021@gmail.com>
To: linux-scsi@vger.kernel.org
Cc: James Smart <jsmart2021@gmail.com>,
	Dick Kennedy <dick.kennedy@broadcom.com>,
	Colin Ian King <colin.king@canonical.com>
Subject: [PATCH] lpfc: Fix less-than-zero comparison of unsigned value
Date: Mon,  6 Jul 2020 13:42:46 -0700	[thread overview]
Message-ID: <20200706204246.130416-1-jsmart2021@gmail.com> (raw)

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")
Fixes: 372c187b8a70 ("scsi: lpfc: Add an internal trace log buffer")
Signed-off-by: Dick Kennedy <dick.kennedy@broadcom.com>
Signed-off-by: James Smart <jsmart2021@gmail.com>
CC: Colin Ian King <colin.king@canonical.com>
---
 drivers/scsi/lpfc/lpfc_init.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
index 4ba8202d391b..f3656bdcb582 100644
--- a/drivers/scsi/lpfc/lpfc_init.c
+++ b/drivers/scsi/lpfc/lpfc_init.c
@@ -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);
-- 
2.25.0


             reply	other threads:[~2020-07-06 20:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-06 20:42 James Smart [this message]
2020-07-08  6:06 ` [PATCH] lpfc: Fix less-than-zero comparison of unsigned value Martin K. Petersen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200706204246.130416-1-jsmart2021@gmail.com \
    --to=jsmart2021@gmail.com \
    --cc=colin.king@canonical.com \
    --cc=dick.kennedy@broadcom.com \
    --cc=linux-scsi@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox