]> rtime.felk.cvut.cz Git - linux-imx.git/commitdiff
drivers/staging/hv/blkvsc_drv.c: eliminate NULL pointer dereference
authorJulia Lawall <julia@diku.dk>
Sat, 9 Jul 2011 19:23:26 +0000 (21:23 +0200)
committerGreg Kroah-Hartman <gregkh@suse.de>
Tue, 2 Aug 2011 23:12:49 +0000 (16:12 -0700)
In this code, blkvsc_req is allocated in the cache blkdev->request_pool,
but freed in the first case to the cache blkvsc_req->dev->request_pool.
blkvsc_req->dev is subsequently initialized to blkdev, making these the
same at the second call to kmem_cache_free.  But at the point of the first
call, blkvsc_req->dev is NULL.  The second call is changed too, for
uniformity.

The semantic patch that fixes this problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
expression x,e,e1,e2,e3;
@@

x = \(kmem_cache_alloc\|kmem_cache_zalloc\)(e1,e2)
... when != x = e
(
kmem_cache_free(e1,x);
|
?-kmem_cache_free(e3,x);
+kmem_cache_free(e1,x);
)
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>
Cc: KY Srinivasan <kys@microsoft.com>
Cc: Hank Janssen <hjanssen@microsoft.com>
Cc: Haiyang Zhang <haiyangz@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/staging/hv/blkvsc_drv.c

index 3612574ca52087c6a192a5ab061479d7403e08ab..d286b2223181623d284a8bd9b17ecce5445a899c 100644 (file)
@@ -325,7 +325,7 @@ static int blkvsc_do_operation(struct block_device_context *blkdev,
 
        page_buf = alloc_page(GFP_KERNEL);
        if (!page_buf) {
-               kmem_cache_free(blkvsc_req->dev->request_pool, blkvsc_req);
+               kmem_cache_free(blkdev->request_pool, blkvsc_req);
                return -ENOMEM;
        }
 
@@ -422,7 +422,7 @@ cleanup:
 
        __free_page(page_buf);
 
-       kmem_cache_free(blkvsc_req->dev->request_pool, blkvsc_req);
+       kmem_cache_free(blkdev->request_pool, blkvsc_req);
 
        return ret;
 }