diff mbox

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

Message ID 20170421205437.fom72nbe3rfngdra@mwanda (mailing list archive)
State New, archived
Headers show

Commit Message

Dan Carpenter April 21, 2017, 8:54 p.m. UTC
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")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Comments

=?UTF-8?q?Javier=20Gonz=C3=A1lez?= April 21, 2017, 10:33 p.m. UTC | #1
> On 21 Apr 2017, at 22.54, Dan Carpenter <dan.carpenter@oracle.com> wrote:
> 
> 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")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> 
> diff --git a/drivers/lightnvm/pblk-read.c b/drivers/lightnvm/pblk-read.c
> index c9daa33e8d9c..4a12f14d78c6 100644
> --- a/drivers/lightnvm/pblk-read.c
> +++ b/drivers/lightnvm/pblk-read.c
> @@ -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);

Thanks Dan.

Reviewed-by: Javier González <javier@cnexlabs.com>
Jens Axboe April 21, 2017, 10:50 p.m. UTC | #2
On 04/21/2017 02:54 PM, Dan Carpenter wrote:
> 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")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>

Added, thanks Dan.
diff mbox

Patch

diff --git a/drivers/lightnvm/pblk-read.c b/drivers/lightnvm/pblk-read.c
index c9daa33e8d9c..4a12f14d78c6 100644
--- a/drivers/lightnvm/pblk-read.c
+++ b/drivers/lightnvm/pblk-read.c
@@ -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);