All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
To: Dan Carpenter <dan.carpenter-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
Cc: iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
Subject: [PATCH] iommu/amd: Handle errors returned from iommu_init_device
Date: Thu, 11 Jun 2015 09:35:52 +0200	[thread overview]
Message-ID: <20150611073552.GC16345@suse.de> (raw)
In-Reply-To: <20150610153618.GA10549@mwanda>

Hi Dan,

On Wed, Jun 10, 2015 at 06:36:18PM +0300, Dan Carpenter wrote:
> This is a semi-automatic email about new static checker warnings.
> 
> The patch 0a3da4517107: "iommu/amd: Put IOMMUv2 devices in a direct 
> mapped domain" from May 28, 2015, leads to the following Smatch 
> complaint:
> 
> drivers/iommu/amd_iommu.c:2285 amd_iommu_add_device()
> 	 error: we previously assumed 'dev_data' could be null (see line 2279)
> 
> drivers/iommu/amd_iommu.c
>   2278		dev_data = get_dev_data(dev);
>   2279		if (dev_data && dev_data->iommu_v2)
>                     ^^^^^^^^
> Check.
> 
>   2280			iommu_request_dm_for_dev(dev);
>   2281	
>   2282		/* Domains are initialized for this device - have a look what we ended up with */
>   2283		domain = iommu_get_domain_for_dev(dev);
>   2284		if (domain->type == IOMMU_DOMAIN_IDENTITY) {
>   2285			dev_data->passthrough = true;
>                         ^^^^^^^^^^
> Unchecked dereference.
> 
>   2286			dev->archdata.dma_ops = &nommu_dma_ops;
>   2287		} else {

This was a bit more complicated. I fixed it with this add-on patch:

>From 8a683d98936d7aa4e3ae554efca3a52c042593b9 Mon Sep 17 00:00:00 2001
From: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
Date: Thu, 11 Jun 2015 09:21:39 +0200
Subject: [PATCH] iommu/amd: Handle errors returned from iommu_init_device

Without this patch only -ENOTSUPP is handled, but there are
other possible errors. Handle them too.

Reported-by: Dan Carpenter <dan.carpenter-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org>
Signed-off-by: Joerg Roedel <jroedel-l3A5Bk7waGM@public.gmane.org>
---
 drivers/iommu/amd_iommu.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 6659b51..73fc4b7 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -2265,7 +2265,11 @@ static int amd_iommu_add_device(struct device *dev)
 	iommu = amd_iommu_rlookup_table[devid];
 
 	ret = iommu_init_device(dev);
-	if (ret == -ENOTSUPP) {
+	if (ret) {
+		if (ret != -ENOTSUPP)
+			pr_err("Failed to initialize device %s - trying to proceed anyway\n",
+				dev_name(dev));
+
 		iommu_ignore_device(dev);
 		dev->archdata.dma_ops = &nommu_dma_ops;
 		goto out;
@@ -2273,7 +2277,10 @@ static int amd_iommu_add_device(struct device *dev)
 	init_iommu_group(dev);
 
 	dev_data = get_dev_data(dev);
-	if (dev_data && dev_data->iommu_v2)
+
+	BUG_ON(!dev_data);
+
+	if (dev_data->iommu_v2)
 		iommu_request_dm_for_dev(dev);
 
 	/* Domains are initialized for this device - have a look what we ended up with */
-- 
1.8.4.5

      reply	other threads:[~2015-06-11  7:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-10 15:36 iommu/amd: Put IOMMUv2 devices in a direct mapped domain Dan Carpenter
2015-06-11  7:35 ` Joerg Roedel [this message]

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=20150611073552.GC16345@suse.de \
    --to=jroedel-l3a5bk7wagm@public.gmane.org \
    --cc=dan.carpenter-QHcLZuEGTsvQT0dZR+AlfA@public.gmane.org \
    --cc=iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.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 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.