mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Wan Zongshun <vincent.wan@amd.com>
To: Joerg Roedel <joro@8bytes.org>, <iommu@lists.linux-foundation.org>
Cc: Suravee Suthikulpanit <Suravee.Suthikulpanit@amd.com>,
	Borislav Petkov <bp@suse.de>, Ray Huang <ray.huang@amd.com>,
	<ken.xue@amd.com>, <vw@iommu.org>, <mcuos.com@gmail.com>,
	<linux-kernel@vger.kernel.org>,
	"Wan Zongshun" <Vincent.Wan@amd.com>
Subject: [PATCH V2 5/8] iommu/amd: Make call-sites of get_device_id aware of its return value
Date: Tue, 26 Jan 2016 18:14:34 -0500	[thread overview]
Message-ID: <1453850077-2539-6-git-send-email-vincent.wan@amd.com> (raw)
In-Reply-To: <1453850077-2539-1-git-send-email-vincent.wan@amd.com>

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

This patch is to make the call-sites of get_device_id aware of its
return value.

Signed-off-by: Wan Zongshun <Vincent.Wan@amd.com>
---
 drivers/iommu/amd_iommu.c | 51 +++++++++++++++++++++++++++++++++++++----------
 1 file changed, 41 insertions(+), 10 deletions(-)

diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 8063ab2..10d6623 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -278,9 +278,11 @@ static void init_unity_mappings_for_device(struct device *dev,
 					   struct dma_ops_domain *dma_dom)
 {
 	struct unity_map_entry *e;
-	u16 devid;
+	int devid;
 
 	devid = get_device_id(dev);
+	if (IS_ERR_VALUE(devid))
+		return;
 
 	list_for_each_entry(e, &amd_iommu_unity_map, list) {
 		if (!(devid >= e->devid_start && devid <= e->devid_end))
@@ -295,7 +297,7 @@ static void init_unity_mappings_for_device(struct device *dev,
  */
 static bool check_device(struct device *dev)
 {
-	u16 devid;
+	int devid;
 
 	if (!dev || !dev->dma_mask)
 		return false;
@@ -305,6 +307,8 @@ static bool check_device(struct device *dev)
 		return false;
 
 	devid = get_device_id(dev);
+	if (IS_ERR_VALUE(devid))
+		return false;
 
 	/* Out of our scope? */
 	if (devid > amd_iommu_last_bdf)
@@ -341,11 +345,16 @@ static int iommu_init_device(struct device *dev)
 {
 	struct pci_dev *pdev = to_pci_dev(dev);
 	struct iommu_dev_data *dev_data;
+	int devid;
 
 	if (dev->archdata.iommu)
 		return 0;
 
-	dev_data = find_dev_data(get_device_id(dev));
+	devid = get_device_id(dev);
+	if (IS_ERR_VALUE(devid))
+		return devid;
+
+	dev_data = find_dev_data(devid);
 	if (!dev_data)
 		return -ENOMEM;
 
@@ -366,9 +375,13 @@ static int iommu_init_device(struct device *dev)
 
 static void iommu_ignore_device(struct device *dev)
 {
-	u16 devid, alias;
+	u16 alias;
+	int devid;
 
 	devid = get_device_id(dev);
+	if (IS_ERR_VALUE(devid))
+		return;
+
 	alias = amd_iommu_alias_table[devid];
 
 	memset(&amd_iommu_dev_table[devid], 0, sizeof(struct dev_table_entry));
@@ -380,8 +393,14 @@ static void iommu_ignore_device(struct device *dev)
 
 static void iommu_uninit_device(struct device *dev)
 {
-	struct iommu_dev_data *dev_data = search_dev_data(get_device_id(dev));
+	int devid;
+	struct iommu_dev_data *dev_data;
+
+	devid = get_device_id(dev);
+	if (IS_ERR_VALUE(devid))
+		return;
 
+	dev_data = search_dev_data(devid);
 	if (!dev_data)
 		return;
 
@@ -2310,13 +2329,15 @@ static int amd_iommu_add_device(struct device *dev)
 	struct iommu_dev_data *dev_data;
 	struct iommu_domain *domain;
 	struct amd_iommu *iommu;
-	u16 devid;
-	int ret;
+	int ret, devid;
 
 	if (!check_device(dev) || get_dev_data(dev))
 		return 0;
 
 	devid = get_device_id(dev);
+	if (IS_ERR_VALUE(devid))
+		return devid;
+
 	iommu = amd_iommu_rlookup_table[devid];
 
 	ret = iommu_init_device(dev);
@@ -2354,12 +2375,15 @@ out:
 static void amd_iommu_remove_device(struct device *dev)
 {
 	struct amd_iommu *iommu;
-	u16 devid;
+	int devid;
 
 	if (!check_device(dev))
 		return;
 
 	devid = get_device_id(dev);
+	if (IS_ERR_VALUE(devid))
+		return;
+
 	iommu = amd_iommu_rlookup_table[devid];
 
 	iommu_uninit_device(dev);
@@ -3031,12 +3055,14 @@ static void amd_iommu_detach_device(struct iommu_domain *dom,
 {
 	struct iommu_dev_data *dev_data = dev->archdata.iommu;
 	struct amd_iommu *iommu;
-	u16 devid;
+	int devid;
 
 	if (!check_device(dev))
 		return;
 
 	devid = get_device_id(dev);
+	if (IS_ERR_VALUE(devid))
+		return;
 
 	if (dev_data->domain != NULL)
 		detach_device(dev);
@@ -3154,9 +3180,11 @@ static void amd_iommu_get_dm_regions(struct device *dev,
 				     struct list_head *head)
 {
 	struct unity_map_entry *entry;
-	u16 devid;
+	int devid;
 
 	devid = get_device_id(dev);
+	if (IS_ERR_VALUE(devid))
+		return;
 
 	list_for_each_entry(entry, &amd_iommu_unity_map, list) {
 		struct iommu_dm_region *region;
@@ -3858,6 +3886,9 @@ static struct irq_domain *get_irq_domain(struct irq_alloc_info *info)
 	case X86_IRQ_ALLOC_TYPE_MSI:
 	case X86_IRQ_ALLOC_TYPE_MSIX:
 		devid = get_device_id(&info->msi_dev->dev);
+		if (IS_ERR_VALUE(devid))
+			return NULL;
+
 		iommu = amd_iommu_rlookup_table[devid];
 		if (iommu)
 			return iommu->msi_domain;
-- 
1.9.1

  parent reply	other threads:[~2016-01-26 15:37 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-01-26 23:14 [PATCH V2 0/8] iommu/amd: enable ACPI hardware ID device support Wan Zongshun
2016-01-26 23:14 ` [PATCH V2 1/8] iommu/amd: Modify ivhd_header structure to support type 11h and 40h Wan Zongshun
2016-01-26 23:14 ` [PATCH V2 2/8] iommu/amd: Use the most comprehensive IVHD type that the driver can support Wan Zongshun
2016-01-26 23:14 ` [PATCH V2 3/8] iommu/amd: Add new map for storing IVHD dev entry type HID Wan Zongshun
2016-01-26 23:14 ` [PATCH V2 4/8] iommu/amd: Introduces ivrs_acpihid kernel parameter Wan Zongshun
2016-01-26 23:14 ` Wan Zongshun [this message]
2016-01-26 23:14 ` [PATCH V2 6/8] iommu/amd: Add iommu support for ACPI HID devices Wan Zongshun
2016-01-26 23:14 ` [PATCH V2 7/8] iommu/amd: Manage iommu_group " Wan Zongshun
2016-01-26 23:14 ` [PATCH V2 8/8] iommu/amd: Set AMD iommu callbacks for amba bus Wan Zongshun
2016-02-26 14:44 ` [PATCH V2 0/8] iommu/amd: enable ACPI hardware ID device support Joerg Roedel
2016-03-04  1:52   ` Wan, Vincent
2016-03-04  8:46     ` Joerg Roedel
2016-03-04  8:49       ` Wan, Vincent
2016-03-05  9:00         ` Suravee Suthikulpanit

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1453850077-2539-6-git-send-email-vincent.wan@amd.com \
    --to=vincent.wan@amd.com \
    --cc=Suravee.Suthikulpanit@amd.com \
    --cc=bp@suse.de \
    --cc=iommu@lists.linux-foundation.org \
    --cc=joro@8bytes.org \
    --cc=ken.xue@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mcuos.com@gmail.com \
    --cc=ray.huang@amd.com \
    --cc=vw@iommu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®