iommu/amd: Put IOMMUv2 devices in a direct mapped domain
Hello Joerg Roedel,
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 {regards,
dan carpenter
PATCH 1/1 iommu/amd: Handle errors returned from iommu_init_device
Hi Dan,
Quoted 20 lines · Dan Carpenter
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:2285amd_iommu_add_device()
error: we previously assumed 'dev_data' could be null (see line 2279)
drivers/iommu/amd_iommu.c
2278dev_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) {
Quoted 6 lines
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:
Quoted 1 line
From
8a683d98936d7aa4e3ae554efca3a52c042593b9Mon Sep 17 00:00:00 2001
From: Joerg Roedel <[email protected]>
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.
--- drivers/iommu/amd_iommu.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
drivers/iommu/amd_iommu.c +9 -2
@@ -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 */
Signature · 1 line
1.8.4.5