Skip to contentSkip to conversation

iommu: Return ERR_PTR() values from device_group call-backs

PATCH In review Joerg Roedel 3 participants 5 messages Jun 28, 2017 IOMMU

lore
Share & tools
lore

Joerg Roedel

author maintainer
#0 lore raw

PATCH 1/3 iommu: Return ERR_PTR() values from device_group call-backs

From: Joerg Roedel <[email protected]>

The generic device_group call-backs in iommu.c return NULL in case of error. Since they are getting ERR_PTR values from iommu_group_alloc(), just pass them up instead.

---
 drivers/iommu/iommu.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)
drivers/iommu/iommu.c +2 -12
index cf7ca7e..de09e1e 100644
@@ -915,13 +915,7 @@ static int get_pci_alias_or_group(struct pci_dev *pdev, u16 alias, void *opaque)
  */
 struct iommu_group *generic_device_group(struct device *dev)
 {
-	struct iommu_group *group;
-
-	group = iommu_group_alloc();
-	if (IS_ERR(group))
-		return NULL;
-
-	return group;
+	return iommu_group_alloc();
 }
 
 /*
@@ -988,11 +982,7 @@ struct iommu_group *pci_device_group(struct device *dev)
 		return group;
 
 	/* No shared group found, allocate new */
-	group = iommu_group_alloc();
-	if (IS_ERR(group))
-		return NULL;
-
-	return group;
+	return iommu_group_alloc();
 }
 
 /**
Signature · 1 line
2.7.4
author maintainer
#1 lore raw

PATCH 2/3 iommu/omap: Return ERR_PTR in device_group call-back

From: Joerg Roedel <[email protected]>

Make sure that the device_group callback returns an ERR_PTR instead of NULL.

---
 drivers/iommu/omap-iommu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/omap-iommu.c +1 -1
index 95dfca3..641e035 100644
@@ -1309,7 +1309,7 @@ static void omap_iommu_remove_device(struct device *dev)
 static struct iommu_group *omap_iommu_device_group(struct device *dev)
 {
 	struct omap_iommu_arch_data *arch_data = dev->archdata.iommu;
-	struct iommu_group *group = NULL;
+	struct iommu_group *group = ERR_PTR(-EINVAL);
 
 	if (arch_data->iommu_dev)
 		group = arch_data->iommu_dev->group;
Signature · 1 line
2.7.4
Acked-by on v1 2/3
#2 lore raw

Re: [PATCH 2/3] iommu/omap: Return ERR_PTR in device_group call-back

Quoted 6 lines · Joerg Roedel

From: Joerg Roedel <[email protected]>

Make sure that the device_group callback returns an ERR_PTR instead of NULL.

Thanks for the patch,

regards
Suman

Quoted 18 lines
---
 drivers/iommu/omap-iommu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/omap-iommu.c +1 -1
index 95dfca3..641e035 100644
@@ -1309,7 +1309,7 @@ static void omap_iommu_remove_device(struct device *dev)
 static struct iommu_group *omap_iommu_device_group(struct device *dev)
 {
 	struct omap_iommu_arch_data *arch_data = dev->archdata.iommu;
-	struct iommu_group *group = NULL;
+	struct iommu_group *group = ERR_PTR(-EINVAL);
 
 	if (arch_data->iommu_dev)
 		group = arch_data->iommu_dev->group;
author maintainer
#3 lore raw

PATCH 3/3 iommu: Warn once when device_group callback returns NULL

In reply to Joerg Roedel

From: Joerg Roedel <[email protected]>

This callback should never return NULL. Print a warning if that happens so that we notice and can fix it.

---
 drivers/iommu/iommu.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/iommu/iommu.c +3 -0
index de09e1e..3f6ea16 100644
@@ -1010,6 +1010,9 @@ struct iommu_group *iommu_group_get_for_dev(struct device *dev)
 	if (ops && ops->device_group)
 		group = ops->device_group(dev);
 
+	if (WARN_ON_ONCE(group == NULL))
+		return ERR_PTR(-EINVAL);
+
 	if (IS_ERR(group))
 		return group;
 
Signature · 1 line
2.7.4
Reviewed-by on v1 1/3
#4 lore raw
In reply to Joerg Roedel
Quoted 9 lines · On Wed, 28 Jun 2017 14:00:56 +0200 Joerg Roedel…

From: Joerg Roedel <[email protected]>

The generic device_group call-backs in iommu.c return NULL in case of error. Since they are getting ERR_PTR values from iommu_group_alloc(), just pass them up instead.

---

Looks good,

Quoted 35 lines
 drivers/iommu/iommu.c | 14 ++------------
 1 file changed, 2 insertions(+), 12 deletions(-)
drivers/iommu/iommu.c +2 -12
index cf7ca7e..de09e1e 100644
@@ -915,13 +915,7 @@ static int get_pci_alias_or_group(struct pci_dev *pdev, u16 alias, void *opaque)
  */
 struct iommu_group *generic_device_group(struct device *dev)
 {
-	struct iommu_group *group;
-
-	group = iommu_group_alloc();
-	if (IS_ERR(group))
-		return NULL;
-
-	return group;
+	return iommu_group_alloc();
 }
 
 /*
@@ -988,11 +982,7 @@ struct iommu_group *pci_device_group(struct device *dev)
 		return group;
 
 	/* No shared group found, allocate new */
-	group = iommu_group_alloc();
-	if (IS_ERR(group))
-		return NULL;
-
-	return group;
+	return iommu_group_alloc();
 }
 
 /**