nvmap: add null pointer check in __nvmap_sg_table
Ishwarya Balaji Gururajan [Wed, 2 Jul 2014 01:04:32 +0000 (18:04 -0700)]
Possible null pointer derefernce occurs when
nvmap_pages return NULL. Add null pointer check after
nvmap_pages call to prevent null pointer dereference in
sg_alloc_table_from_pages

bug 1516222

Change-Id: I7aa06f8b3e8c0846c496f62ad49f753d21bc9102
Signed-off-by: Ishwarya Balaji Gururajan <igururajan@nvidia.com>
Reviewed-on: http://git-master/r/433389
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Krishna Reddy <vdumpa@nvidia.com>
Reviewed-by: Sri Krishna Chowdary <schowdary@nvidia.com>
GVS: Gerrit_Virtual_Submit
Reviewed-by: Thomas Cherry <tcherry@nvidia.com>
Tested-by: Sri Krishna Chowdary <schowdary@nvidia.com>

drivers/video/tegra/nvmap/nvmap.c

index f0f16d8..16eeeb2 100644 (file)
@@ -458,6 +458,10 @@ struct sg_table *__nvmap_sg_table(struct nvmap_client *client,
                sg_set_buf(sgt->sgl, phys_to_virt(handle_phys(h)), h->size);
        } else {
                pages = nvmap_pages(h->pgalloc.pages, npages);
+               if (!pages) {
+                       err = -ENOMEM;
+                       goto err;
+               }
                err = sg_alloc_table_from_pages(sgt, pages,
                                npages, 0, h->size, GFP_KERNEL);
                nvmap_altfree(pages, npages * sizeof(*pages));