OSDN Git Service

vfio/spapr_tce: Check kzalloc() return when preregistering memory
authorAlexey Kardashevskiy <aik@ozlabs.ru>
Mon, 27 Mar 2017 03:23:40 +0000 (14:23 +1100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 22 Mar 2018 08:17:51 +0000 (09:17 +0100)
[ Upstream commit 3393af24b665cb0aea7353b05e522b03ab1e7d73 ]

This adds missing checking for kzalloc() return value.

Fixes: 4b6fad7097f8 ("powerpc/mm/iommu, vfio/spapr: Put pages on VFIO container shutdown")
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/vfio/vfio_iommu_spapr_tce.c

index 87ad0d7..70c748a 100644 (file)
@@ -195,6 +195,11 @@ static long tce_iommu_register_pages(struct tce_container *container,
                return ret;
 
        tcemem = kzalloc(sizeof(*tcemem), GFP_KERNEL);
+       if (!tcemem) {
+               mm_iommu_put(container->mm, mem);
+               return -ENOMEM;
+       }
+
        tcemem->mem = mem;
        list_add(&tcemem->next, &container->prereg_list);