Skip to contentSkip to conversation

lightnvm: don't print a warning for ADDR_EMPTY

PATCH In review Dan Carpenter 3 participants 3 messages Apr 21, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 2/2 lightnvm: don't print a warning for ADDR_EMPTY

Reading from ADDR_EMPTY is out of bounds. The current code generates a static checker warning because we check for out of bounds "lba" before we check for ADDR_EMPTY, so the second check is always false. It looks like we intended ADDR_EMPTY to be a no-op without printing a warning.

Fixes a4bd217b4326 ("lightnvm: physical block device (pblk) target")
drivers/lightnvm/pblk-read.c +3 -3
index c9daa33e8d9c..4a12f14d78c6 100644
@@ -410,15 +410,15 @@ static int read_rq_gc(struct pblk *pblk, struct nvm_rq *rqd,
 	struct ppa_addr ppa;
 	int valid_secs = 0;
 
+	if (lba = ADDR_EMPTY)
+		goto out;
+
 	/* logic error: lba out-of-bounds */
 	if (lba >= pblk->rl.nr_secs) {
 		WARN(1, "pblk: read lba out of bounds\n");
 		goto out;
 	}
 
-	if (lba = ADDR_EMPTY)
-		goto out;
-
 	spin_lock(&pblk->trans_lock);
 	ppa = pblk_trans_map_get(pblk, lba);
 	spin_unlock(&pblk->trans_lock);
Reviewed-by on v1 2/2
#1 lore raw
Quoted 23 lines · Dan Carpenter

Reading from ADDR_EMPTY is out of bounds. The current code generates a static checker warning because we check for out of bounds "lba" before we check for ADDR_EMPTY, so the second check is always false. It looks like we intended ADDR_EMPTY to be a no-op without printing a warning.

Fixes a4bd217b4326 ("lightnvm: physical block device (pblk) target")
drivers/lightnvm/pblk-read.c +3 -0
index c9daa33e8d9c..4a12f14d78c6 100644
@@ -410,15 +410,15 @@ static int read_rq_gc(struct pblk *pblk, struct nvm_rq *rqd,
 	struct ppa_addr ppa;
 	int valid_secs = 0;
 
+	if (lba == ADDR_EMPTY)
+		goto out;
+
 	/* logic error: lba out-of-bounds */
 	if (lba >= pblk->rl.nr_secs) {

drivers/lightnvm/pblk-read.c static int read_rq_gc(struct pblk *pblk, struct nvm_rq *rqd, · line 424

Quoted 10 lines
drivers/lightnvm/pblk-read.c +0 -3
 		WARN(1, "pblk: read lba out of bounds\n");
 		goto out;
 	}
 
-	if (lba == ADDR_EMPTY)
-		goto out;
-
 	spin_lock(&pblk->trans_lock);
 	ppa = pblk_trans_map_get(pblk, lba);
 	spin_unlock(&pblk->trans_lock);

Thanks Dan.

maintainer
#2 lore raw
In reply to Dan Carpenter
Quoted 7 lines · Dan Carpenter

Reading from ADDR_EMPTY is out of bounds. The current code generates a static checker warning because we check for out of bounds "lba" before we check for ADDR_EMPTY, so the second check is always false. It looks like we intended ADDR_EMPTY to be a no-op without printing a warning.

Fixes a4bd217b4326 ("lightnvm: physical block device (pblk) target")

Added, thanks Dan.

Signature · 1 line
Jens Axboe