Skip to contentSkip to conversation

iommu/vt-d: check for allocation failure in aux_detach_device()

PATCH In review Dan Carpenter 2 participants 2 messages May 12, 2021

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

PATCH 1/1 iommu/vt-d: check for allocation failure in aux_detach_device()

In current kernels small allocations never fail, but checking for allocation failure is the correct thing to do.

Fixes 18abda7a2d55 ("iommu/vt-d: Fix general protection fault in aux_detach_device()")
---
 drivers/iommu/intel/iommu.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/iommu/intel/iommu.c +2 -0
index 708f430af1c4..9a7b79b5af18 100644
@@ -4606,6 +4606,8 @@ static int auxiliary_link_device(struct dmar_domain *domain,
 
 	if (!sinfo) {
 		sinfo = kzalloc(sizeof(*sinfo), GFP_ATOMIC);
+		if (!sinfo)
+			return -ENOMEM;
 		sinfo->domain = domain;
 		sinfo->pdev = dev;
 		list_add(&sinfo->link_phys, &info->subdevices);
Signature · 1 line
2.30.2
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 15 lines · Dan Carpenter

In current kernels small allocations never fail, but checking for allocation failure is the correct thing to do.

Fixes 18abda7a2d55 ("iommu/vt-d: Fix general protection fault in aux_detach_device()")
---
  drivers/iommu/intel/iommu.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/iommu/intel/iommu.c +0 -0
index 708f430af1c4..9a7b79b5af18 100644

drivers/iommu/intel/iommu.c static int auxiliary_link_device(struct dmar_domain *domain, · line 4613

Quoted 8 lines
drivers/iommu/intel/iommu.c +2 -0
@@ -4606,6 +4606,8 @@ static int auxiliary_link_device(struct dmar_domain *domain,
 
  	if (!sinfo) {
  		sinfo = kzalloc(sizeof(*sinfo), GFP_ATOMIC);
+		if (!sinfo)
+			return -ENOMEM;
  		sinfo->domain = domain;
  		sinfo->pdev = dev;
  		list_add(&sinfo->link_phys, &info->subdevices);

Thank you!

Best regards,
baolu