Skip to contentSkip to conversation

vfio/spapr_tce: Check kzalloc() return when preregistering memory

PATCH In review Alexey Kardashevskiy 3 participants 5 messages Mar 27, 2017 – Apr 11, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vfio/spapr_tce: Check kzalloc() return when preregistering memory

This adds missing checking for kzalloc() return value.

Fixes 4b6fad7097f8 ("powerpc/mm/iommu, vfio/spapr: Put pages on VFIO container shutdown")
---
 drivers/vfio/vfio_iommu_spapr_tce.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/vfio/vfio_iommu_spapr_tce.c +5 -0
index cf3de91fbfe7..c298bb36e27a 100644
@@ -198,6 +198,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);
 
Signature · 1 line
2.11.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Alexey Kardashevskiy

This adds missing checking for kzalloc() return value.

Fixes 4b6fad7097f8 ("powerpc/mm/iommu, vfio/spapr: Put pages on VFIO container shutdown")
Quoted 20 lines
---
 drivers/vfio/vfio_iommu_spapr_tce.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/vfio/vfio_iommu_spapr_tce.c +5 -0
index cf3de91fbfe7..c298bb36e27a 100644
@@ -198,6 +198,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);
 
Signature · 4 lines
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson
#2 lore raw
Quoted 7 lines · David Gibson
Quoted 4 lines · Alexey Kardashevskiy

This adds missing checking for kzalloc() return value.

Fixes 4b6fad7097f8 ("powerpc/mm/iommu, vfio/spapr: Put pages on VFIO container shutdown")

Alex?

Quoted 22 lines
Quoted 21 lines
---
 drivers/vfio/vfio_iommu_spapr_tce.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/vfio/vfio_iommu_spapr_tce.c +5 -0
index cf3de91fbfe7..c298bb36e27a 100644
@@ -198,6 +198,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);
 
Signature · 1 line
Alexey
#3 lore raw
Quoted 11 lines · On Tue, 11 Apr 2017 18:27:49 +1000 Alexey Kardashevskiy <[email protected]> wrote:
Quoted 7 lines · David Gibson
Quoted 4 lines · Alexey Kardashevskiy

This adds missing checking for kzalloc() return value.

Fixes 4b6fad7097f8 ("powerpc/mm/iommu, vfio/spapr: Put pages on VFIO container shutdown")

Alex?

I've updated my next branch, I've got these from you:

3393af24b665 vfio/spapr_tce: Check kzalloc() return when preregistering memory 1282ba7fc28d vfio/powerpc/spapr_tce: Enforce IOMMU type compatibility check

Am I missing anything else that needs to go through my tree for v4.12? Thanks,

Alex

Quoted 23 lines
Quoted 21 lines
Quoted 20 lines
---
 drivers/vfio/vfio_iommu_spapr_tce.c | 5 +++++
 1 file changed, 5 insertions(+)
(quoted diff) +0 -0

b/drivers/vfio/vfio_iommu_spapr_tce.c index cf3de91fbfe7..c298bb36e27a 100644 --- a/drivers/vfio/vfio_iommu_spapr_tce.c +++ b/drivers/vfio/vfio_iommu_spapr_tce.c @@ -198,6 +198,11 @@ static long tce_iommu_register_pages(struct tce_container *container, return ret;

drivers/vfio/vfio_iommu_spapr_tce.c +5 -0
 	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);
#4 lore raw
Quoted 13 lines · Alex Williamson
Quoted 10 lines · On Tue, 11 Apr 2017 18:27:49 +1000 Alexey Kardashevskiy <[email protected]> wrote:
Quoted 7 lines · David Gibson
Quoted 4 lines · Alexey Kardashevskiy

This adds missing checking for kzalloc() return value.

Fixes 4b6fad7097f8 ("powerpc/mm/iommu, vfio/spapr: Put pages on VFIO container shutdown")
Quoted 8 lines
Quoted 1 line

Alex?

I've updated my next branch, I've got these from you:

3393af24b665 vfio/spapr_tce: Check kzalloc() return when preregistering memory 1282ba7fc28d vfio/powerpc/spapr_tce: Enforce IOMMU type compatibility check

Am I missing anything else that needs to go through my tree for v4.12?

No, this is all I wanted, thanks. I just did not see in any of your trees but I see it now.

Quoted 28 lines

Thanks,

Alex

Quoted 23 lines
Quoted 21 lines
Quoted 20 lines
---
 drivers/vfio/vfio_iommu_spapr_tce.c | 5 +++++
 1 file changed, 5 insertions(+)
(quoted diff) +0 -0

b/drivers/vfio/vfio_iommu_spapr_tce.c index cf3de91fbfe7..c298bb36e27a 100644 --- a/drivers/vfio/vfio_iommu_spapr_tce.c +++ b/drivers/vfio/vfio_iommu_spapr_tce.c @@ -198,6 +198,11 @@ static long tce_iommu_register_pages(struct tce_container *container, return ret;

drivers/vfio/vfio_iommu_spapr_tce.c +5 -0
 	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);
Signature · 1 line
Alexey