Skip to contentSkip to conversation

iommu: Initialize domain->handler in iommu_domain_alloc()

PATCH Applied KyongHo Cho 2 participants 4 messages Dec 13, 2011 – Dec 16, 2011

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

PATCH 1/1 iommu: Initialize domain->handler in iommu_domain_alloc()

Since it is not guaranteed that an iommu driver initializes in its domain_init() function, it must be initialized with NULL to prevent calling a function in an arbitrary location when iommu fault occurred.

---
 drivers/iommu/iommu.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/iommu/iommu.c +1 -0
index 7cc3c65..1afb896 100644
@@ -148,6 +148,7 @@ struct iommu_domain *iommu_domain_alloc(struct bus_type *bus)
 		return NULL;
 
 	domain->ops = bus->iommu_ops;
+	domain->handler = NULL;
 
 	ret = domain->ops->domain_init(domain);
 	if (ret)
Signature · 1 line
1.7.1
maintainer
#1 lore raw
Quoted 14 lines · KyongHo Cho

Since it is not guaranteed that an iommu driver initializes in its domain_init() function, it must be initialized with NULL to prevent calling a function in an arbitrary location when iommu fault occurred.

---
 drivers/iommu/iommu.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/iommu/iommu.c +0 -0
index 7cc3c65..1afb896 100644

drivers/iommu/iommu.c struct iommu_domain *iommu_domain_alloc(struct bus_type *bus) · line 151

Quoted 4 lines
drivers/iommu/iommu.c +1 -0
@@ -148,6 +148,7 @@ struct iommu_domain *iommu_domain_alloc(struct bus_type *bus)
 		return NULL;
 
 	domain->ops = bus->iommu_ops;
+	domain->handler = NULL;

Good catch. But it is better to change the kmalloc in the function to kzalloc. This will implicitly initialize all future members correctly.

Thanks,

Joerg

#2 lore raw
Quoted 16 lines · Joerg Roedel

drivers/iommu/iommu.c struct iommu_domain *iommu_domain_alloc(struct

Quoted 14 lines · KyongHo Cho

Since it is not guaranteed that an iommu driver initializes in its domain_init() function, it must be initialized with NULL to prevent calling a function in an arbitrary location when iommu fault occurred.

---
 drivers/iommu/iommu.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
drivers/iommu/iommu.c +0 -0
index 7cc3c65..1afb896 100644
@@ -148,6 +148,7 @@ struct iommu_domain *iommu_domain_alloc(struct

bus_type *bus)

Quoted 7 lines

drivers/iommu/iommu.c struct iommu_domain *iommu_domain_alloc(struct · line 151

Quoted 4 lines
drivers/iommu/iommu.c +1 -0
 		return NULL;
 
 	domain->ops = bus->iommu_ops;
+	domain->handler = NULL;

Good catch. But it is better to change the kmalloc in the function to kzalloc. This will implicitly initialize all future members correctly.

Hi.

Here is the patch that change kmalloc -> kzalloc
according to your advice.

Quoted 1 line

From 821141fcf00a64fe4fbacc78b2bbe90e15da9fca Mon Sep 17 00:00:00 2001

From: KyongHo Cho <[email protected]>
Date: Tue, 13 Dec 2011 16:08:51 +0900
Subject: [PATCH] iommu: Initialize domain->handler in iommu_domain_alloc()

Since it is not guaranteed that an iommu driver initializes in its domain_init() function, it must be initialized with NULL to prevent calling a function in an arbitrary location when iommu fault occurred.

---
 drivers/iommu/iommu.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/iommu/iommu.c +1 -1
index 7cc3c65..2198b2d 100644
@@ -143,7 +143,7 @@ struct iommu_domain *iommu_domain_alloc(struct bus_type *bus)
 	if (bus == NULL || bus->iommu_ops == NULL)
 		return NULL;
 
-	domain = kmalloc(sizeof(*domain), GFP_KERNEL);
+	domain = kzalloc(sizeof(*domain), GFP_KERNEL);
 	if (!domain)
 		return NULL;
 
Signature · 1 line
1.7.1
maintainer Applied
#3 lore raw
Quoted 7 lines · KyongHo Cho

Subject: [PATCH] iommu: Initialize domain->handler in iommu_domain_alloc()

Since it is not guaranteed that an iommu driver initializes in its domain_init() function, it must be initialized with NULL to prevent calling a function in an arbitrary location when iommu fault occurred.

Applied to iommu/fixes, thanks a lot.