All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] iommu/amd: Add proper error check in two functions
@ 2016-06-16 11:57 ` Wan Zongshun
  0 siblings, 0 replies; 2+ messages in thread
From: Wan Zongshun @ 2016-06-16 11:57 UTC (permalink / raw)
  To: Joerg Roedel, iommu; +Cc: vw, mcuos.com, linux-kernel, Wan Zongshun

From: Wan Zongshun <Vincent.Wan@amd.com>

This patch is to do the following:

1. Add error check for caller of iommu_device_create.

2. Add error check for caller of iommu_device_link and
move 'iommu = amd_iommu_rlookup_table[dev_data->devid]' out of
iommuv2 capability condition that make iommu_device_link also
use the 'iommu' to make code more clear and no more than 80
characters.

Signed-off-by: Wan Zongshun <Vincent.Wan@amd.com>
---
Changes from v1:

Don't fail the iommu_init_device() function when the iommu_device_link returned
an error,just print a warning message.
---
 drivers/iommu/amd_iommu.c      | 11 +++++------
 drivers/iommu/amd_iommu_init.c |  2 ++
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 634f636..dbdcaeb 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -476,6 +476,7 @@ out:
 static int iommu_init_device(struct device *dev)
 {
 	struct iommu_dev_data *dev_data;
+	struct amd_iommu *iommu;
 	int devid;
 
 	if (dev->archdata.iommu)
@@ -491,17 +492,15 @@ static int iommu_init_device(struct device *dev)
 
 	dev_data->alias = get_alias(dev);
 
-	if (dev_is_pci(dev) && pci_iommuv2_capable(to_pci_dev(dev))) {
-		struct amd_iommu *iommu;
+	iommu = amd_iommu_rlookup_table[dev_data->devid];
 
-		iommu = amd_iommu_rlookup_table[dev_data->devid];
+	if (dev_is_pci(dev) && pci_iommuv2_capable(to_pci_dev(dev)))
 		dev_data->iommu_v2 = iommu->is_iommu_v2;
-	}
 
 	dev->archdata.iommu = dev_data;
 
-	iommu_device_link(amd_iommu_rlookup_table[dev_data->devid]->iommu_dev,
-			  dev);
+	if (iommu_device_link(iommu->iommu_dev, dev))
+		dev_warn(dev, "Creating iommu device link failed in sysfs.\n");
 
 	return 0;
 }
diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c
index 9e00341..73fa986 100644
--- a/drivers/iommu/amd_iommu_init.c
+++ b/drivers/iommu/amd_iommu_init.c
@@ -1526,6 +1526,8 @@ static int iommu_init_pci(struct amd_iommu *iommu)
 	iommu->iommu_dev = iommu_device_create(&iommu->dev->dev, iommu,
 					       amd_iommu_groups, "ivhd%d",
 					       iommu->index);
+	if (IS_ERR(iommu->iommu_dev))
+		return PTR_ERR(iommu->iommu_dev);
 
 	return pci_enable_device(iommu->dev);
 }
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH v2] iommu/amd: Add proper error check in two functions
@ 2016-06-16 11:57 ` Wan Zongshun
  0 siblings, 0 replies; 2+ messages in thread
From: Wan Zongshun @ 2016-06-16 11:57 UTC (permalink / raw)
  To: Joerg Roedel, iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA
  Cc: Wan Zongshun, linux-kernel-u79uwXL29TY76Z2rM5mHXA

From: Wan Zongshun <Vincent.Wan-5C7GfCeVMHo@public.gmane.org>

This patch is to do the following:

1. Add error check for caller of iommu_device_create.

2. Add error check for caller of iommu_device_link and
move 'iommu = amd_iommu_rlookup_table[dev_data->devid]' out of
iommuv2 capability condition that make iommu_device_link also
use the 'iommu' to make code more clear and no more than 80
characters.

Signed-off-by: Wan Zongshun <Vincent.Wan-5C7GfCeVMHo@public.gmane.org>
---
Changes from v1:

Don't fail the iommu_init_device() function when the iommu_device_link returned
an error,just print a warning message.
---
 drivers/iommu/amd_iommu.c      | 11 +++++------
 drivers/iommu/amd_iommu_init.c |  2 ++
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 634f636..dbdcaeb 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -476,6 +476,7 @@ out:
 static int iommu_init_device(struct device *dev)
 {
 	struct iommu_dev_data *dev_data;
+	struct amd_iommu *iommu;
 	int devid;
 
 	if (dev->archdata.iommu)
@@ -491,17 +492,15 @@ static int iommu_init_device(struct device *dev)
 
 	dev_data->alias = get_alias(dev);
 
-	if (dev_is_pci(dev) && pci_iommuv2_capable(to_pci_dev(dev))) {
-		struct amd_iommu *iommu;
+	iommu = amd_iommu_rlookup_table[dev_data->devid];
 
-		iommu = amd_iommu_rlookup_table[dev_data->devid];
+	if (dev_is_pci(dev) && pci_iommuv2_capable(to_pci_dev(dev)))
 		dev_data->iommu_v2 = iommu->is_iommu_v2;
-	}
 
 	dev->archdata.iommu = dev_data;
 
-	iommu_device_link(amd_iommu_rlookup_table[dev_data->devid]->iommu_dev,
-			  dev);
+	if (iommu_device_link(iommu->iommu_dev, dev))
+		dev_warn(dev, "Creating iommu device link failed in sysfs.\n");
 
 	return 0;
 }
diff --git a/drivers/iommu/amd_iommu_init.c b/drivers/iommu/amd_iommu_init.c
index 9e00341..73fa986 100644
--- a/drivers/iommu/amd_iommu_init.c
+++ b/drivers/iommu/amd_iommu_init.c
@@ -1526,6 +1526,8 @@ static int iommu_init_pci(struct amd_iommu *iommu)
 	iommu->iommu_dev = iommu_device_create(&iommu->dev->dev, iommu,
 					       amd_iommu_groups, "ivhd%d",
 					       iommu->index);
+	if (IS_ERR(iommu->iommu_dev))
+		return PTR_ERR(iommu->iommu_dev);
 
 	return pci_enable_device(iommu->dev);
 }
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-06-16 11:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-16 11:57 [PATCH v2] iommu/amd: Add proper error check in two functions Wan Zongshun
2016-06-16 11:57 ` Wan Zongshun

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.