diff mbox

block: xen-blkback: add null check to avoid null pointer dereference

Message ID 20170511152735.GA4409@embeddedgus (mailing list archive)
State Accepted
Headers show

Commit Message

Gustavo A. R. Silva May 11, 2017, 3:27 p.m. UTC
Add null check before calling xen_blkif_put() to avoid potential
null pointer dereference.

Addresses-Coverity-ID: 1350942
Cc: Juergen Gross <jgross@suse.com>
Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
---
 drivers/block/xen-blkback/xenbus.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

Comments

Konrad Rzeszutek Wilk May 15, 2017, 9:18 p.m. UTC | #1
On Thu, May 11, 2017 at 10:27:35AM -0500, Gustavo A. R. Silva wrote:
> Add null check before calling xen_blkif_put() to avoid potential
> null pointer dereference.
> 

Applied to 'stable/for-jens-4.12' and will push soon to Jens.

> Addresses-Coverity-ID: 1350942
> Cc: Juergen Gross <jgross@suse.com>
> Signed-off-by: Gustavo A. R. Silva <garsilva@embeddedor.com>
> ---
>  drivers/block/xen-blkback/xenbus.c | 8 +++++---
>  1 file changed, 5 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c
> index 8fe61b5..1f3dfaa 100644
> --- a/drivers/block/xen-blkback/xenbus.c
> +++ b/drivers/block/xen-blkback/xenbus.c
> @@ -504,11 +504,13 @@ static int xen_blkbk_remove(struct xenbus_device *dev)
>  
>  	dev_set_drvdata(&dev->dev, NULL);
>  
> -	if (be->blkif)
> +	if (be->blkif) {
>  		xen_blkif_disconnect(be->blkif);
>  
> -	/* Put the reference we set in xen_blkif_alloc(). */
> -	xen_blkif_put(be->blkif);
> +		/* Put the reference we set in xen_blkif_alloc(). */
> +		xen_blkif_put(be->blkif);
> +	}
> +
>  	kfree(be->mode);
>  	kfree(be);
>  	return 0;
> -- 
> 2.5.0
>
diff mbox

Patch

diff --git a/drivers/block/xen-blkback/xenbus.c b/drivers/block/xen-blkback/xenbus.c
index 8fe61b5..1f3dfaa 100644
--- a/drivers/block/xen-blkback/xenbus.c
+++ b/drivers/block/xen-blkback/xenbus.c
@@ -504,11 +504,13 @@  static int xen_blkbk_remove(struct xenbus_device *dev)
 
 	dev_set_drvdata(&dev->dev, NULL);
 
-	if (be->blkif)
+	if (be->blkif) {
 		xen_blkif_disconnect(be->blkif);
 
-	/* Put the reference we set in xen_blkif_alloc(). */
-	xen_blkif_put(be->blkif);
+		/* Put the reference we set in xen_blkif_alloc(). */
+		xen_blkif_put(be->blkif);
+	}
+
 	kfree(be->mode);
 	kfree(be);
 	return 0;