Skip to contentSkip to conversation

iommu: Fix some static checker warnings

PATCH New Joerg Roedel 1 participant 10 messages Aug 13, 2015

Subsystems (3)
lore
Share & tools
lore

Joerg Roedel

author maintainer
#0 lore raw

cover iommu: Fix some static checker warnings

Hi,

here are some patches to fix various static checker warnings I have seen through testing other code. Main intention behind these is to reduce the noise. In particular I used these checkers:

* coccinelle scripts in the kernel tree
* smatch
* sparse

Please review.

Thanks,

Joerg

Joerg Roedel (9):
iommu/amd: Simplify allocation in irq_remapping_alloc() iommu/amd: Make a symbol static
iommu/amd: Use BUG_ON instead of if () BUG() iommu/vt-d: Return false instead of 0 in irq_remapping_cap() iommu/vt-d: Use BUG_ON instead of if () BUG() iommu/vt-d: Make two functions static
iommu/vt-d: Access iomem correctly
iommu/msm: Use BUG_ON instead of if () BUG() iommu/io-pgtable-arm: Move init-fn declarations to io-pgtable.h

 drivers/iommu/amd_iommu.c           | 21 ++++++++-------------
 drivers/iommu/amd_iommu_init.c      |  2 +-
 drivers/iommu/amd_iommu_v2.c        |  4 ++--
 drivers/iommu/intel-iommu.c         | 26 ++++++++++++++------------
 drivers/iommu/intel_irq_remapping.c |  4 ++--
 drivers/iommu/io-pgtable.c          |  5 -----
 drivers/iommu/io-pgtable.h          |  5 +++++
 drivers/iommu/irq_remapping.c       |  2 +-
 drivers/iommu/msm_iommu.c           |  4 ++--
 9 files changed, 35 insertions(+), 38 deletions(-)
Signature · 1 line
1.9.1
author maintainer
#1 lore raw

PATCH 1/9 iommu/amd: Simplify allocation in irq_remapping_alloc()

From: Joerg Roedel <[email protected]>

Allocate the irq data only in the loop.

---
 drivers/iommu/amd_iommu.c | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)
drivers/iommu/amd_iommu.c +6 -11
index 658ee39..a158579 100644
@@ -3947,11 +3947,6 @@ static int irq_remapping_alloc(struct irq_domain *domain, unsigned int virq,
 	if (ret < 0)
 		return ret;
 
-	ret = -ENOMEM;
-	data = kzalloc(sizeof(*data), GFP_KERNEL);
-	if (!data)
-		goto out_free_parent;
-
 	if (info->type == X86_IRQ_ALLOC_TYPE_IOAPIC) {
 		if (get_irq_table(devid, true))
 			index = info->ioapic_pin;
@@ -3962,7 +3957,6 @@ static int irq_remapping_alloc(struct irq_domain *domain, unsigned int virq,
 	}
 	if (index < 0) {
 		pr_warn("Failed to allocate IRTE\n");
-		kfree(data);
 		goto out_free_parent;
 	}
 
@@ -3974,17 +3968,18 @@ static int irq_remapping_alloc(struct irq_domain *domain, unsigned int virq,
 			goto out_free_data;
 		}
 
-		if (i > 0) {
-			data = kzalloc(sizeof(*data), GFP_KERNEL);
-			if (!data)
-				goto out_free_data;
-		}
+		ret = -ENOMEM;
+		data = kzalloc(sizeof(*data), GFP_KERNEL);
+		if (!data)
+			goto out_free_data;
+
 		irq_data->hwirq = (devid << 16) + i;
 		irq_data->chip_data = data;
 		irq_data->chip = &amd_ir_chip;
 		irq_remapping_prepare_irte(data, cfg, info, devid, index, i);
 		irq_set_status_flags(virq + i, IRQ_MOVE_PCNTXT);
 	}
+
 	return 0;
 
 out_free_data:
Signature · 1 line
1.9.1
author maintainer
#2 lore raw

PATCH 2/9 iommu/amd: Make a symbol static

In reply to Joerg Roedel

From: Joerg Roedel <[email protected]>

Symbol is only used in that file and can be static.

---
 drivers/iommu/amd_iommu_init.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/amd_iommu_init.c +1 -1
index a24495e..5ef347a 100644
@@ -154,7 +154,7 @@ bool amd_iommu_iotlb_sup __read_mostly = true;
 u32 amd_iommu_max_pasid __read_mostly = ~0;
 
 bool amd_iommu_v2_present __read_mostly;
-bool amd_iommu_pc_present __read_mostly;
+static bool amd_iommu_pc_present __read_mostly;
 
 bool amd_iommu_force_isolation __read_mostly;
 
Signature · 1 line
1.9.1
author maintainer
#3 lore raw

PATCH 3/9 iommu/amd: Use BUG_ON instead of if () BUG()

In reply to Joerg Roedel

From: Joerg Roedel <[email protected]>

Found by a coccicheck script.

---
 drivers/iommu/amd_iommu.c    | 4 ++--
 drivers/iommu/amd_iommu_v2.c | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
drivers/iommu/amd_iommu.c +2 -2
index a158579..f82060e7 100644
@@ -1835,8 +1835,8 @@ static void free_gcr3_table(struct protection_domain *domain)
 		free_gcr3_tbl_level2(domain->gcr3_tbl);
 	else if (domain->glx == 1)
 		free_gcr3_tbl_level1(domain->gcr3_tbl);
-	else if (domain->glx != 0)
-		BUG();
+	else
+		BUG_ON(domain->glx != 0);
 
 	free_page((unsigned long)domain->gcr3_tbl);
 }
drivers/iommu/amd_iommu_v2.c +2 -2
index f7b875b..1131664 100644
@@ -356,8 +356,8 @@ static void free_pasid_states(struct device_state *dev_state)
 		free_pasid_states_level2(dev_state->states);
 	else if (dev_state->pasid_levels == 1)
 		free_pasid_states_level1(dev_state->states);
-	else if (dev_state->pasid_levels != 0)
-		BUG();
+	else
+		BUG_ON(dev_state->pasid_levels != 0);
 
 	free_page((unsigned long)dev_state->states);
 }
Signature · 1 line
1.9.1
author maintainer
#4 lore raw

PATCH 4/9 iommu/vt-d: Return false instead of 0 in irq_remapping_cap()

In reply to Joerg Roedel

From: Joerg Roedel <[email protected]>

The function return type is bool, so return false instead of 0.

---
 drivers/iommu/irq_remapping.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/iommu/irq_remapping.c +1 -1
index 2d99930..913455a 100644
@@ -84,7 +84,7 @@ void set_irq_remapping_broken(void)
 bool irq_remapping_cap(enum irq_remap_cap cap)
 {
 	if (!remap_ops || disable_irq_post)
-		return 0;
+		return false;
 
 	return (remap_ops->capability & (1 << cap));
 }
Signature · 1 line
1.9.1
author maintainer
#5 lore raw

PATCH 5/9 iommu/vt-d: Use BUG_ON instead of if () BUG()

In reply to Joerg Roedel

From: Joerg Roedel <[email protected]>

Found by a coccicheck script.

---
 drivers/iommu/intel-iommu.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/iommu/intel-iommu.c +1 -2
index 8834765..2a7e017 100644
@@ -4760,8 +4760,7 @@ static size_t intel_iommu_unmap(struct iommu_domain *domain,
 
 	/* Cope with horrid API which requires us to unmap more than the
 	   size argument if it happens to be a large-page mapping. */
-	if (!pfn_to_dma_pte(dmar_domain, iova >> VTD_PAGE_SHIFT, &level))
-		BUG();
+	BUG_ON(!pfn_to_dma_pte(dmar_domain, iova >> VTD_PAGE_SHIFT, &level));
 
 	if (size < VTD_PAGE_SIZE << level_to_offset_bits(level))
 		size = VTD_PAGE_SIZE << level_to_offset_bits(level);
Signature · 1 line
1.9.1
author maintainer
#6 lore raw

PATCH 6/9 iommu/vt-d: Make two functions static

In reply to Joerg Roedel

From: Joerg Roedel <[email protected]>

These functions are only used in that file and can be static.

---
 drivers/iommu/intel-iommu.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/iommu/intel-iommu.c +4 -4
index 2a7e017..93f16aa 100644
@@ -1210,9 +1210,9 @@ next:
 /* We can't just free the pages because the IOMMU may still be walking
    the page tables, and may have cached the intermediate levels. The
    pages can only be freed after the IOTLB flush has been done. */
-struct page *domain_unmap(struct dmar_domain *domain,
-			  unsigned long start_pfn,
-			  unsigned long last_pfn)
+static struct page *domain_unmap(struct dmar_domain *domain,
+				 unsigned long start_pfn,
+				 unsigned long last_pfn)
 {
 	struct page *freelist = NULL;
 
@@ -1236,7 +1236,7 @@ struct page *domain_unmap(struct dmar_domain *domain,
 	return freelist;
 }
 
-void dma_free_pagelist(struct page *freelist)
+static void dma_free_pagelist(struct page *freelist)
 {
 	struct page *pg;
 
Signature · 1 line
1.9.1
author maintainer
#7 lore raw

PATCH 7/9 iommu/vt-d: Access iomem correctly

In reply to Joerg Roedel

From: Joerg Roedel <[email protected]>

This fixes wrong accesses to iomem introduced by the kdump fixing code.

---
 drivers/iommu/intel-iommu.c         | 15 +++++++++------
 drivers/iommu/intel_irq_remapping.c |  4 ++--
 2 files changed, 11 insertions(+), 8 deletions(-)
drivers/iommu/intel-iommu.c +9 -6
index 93f16aa..a85077d 100644
@@ -2799,15 +2799,18 @@ static void intel_iommu_init_qi(struct intel_iommu *iommu)
 }
 
 static int copy_context_table(struct intel_iommu *iommu,
-			      struct root_entry *old_re,
+			      struct root_entry __iomem *old_re,
 			      struct context_entry **tbl,
 			      int bus, bool ext)
 {
-	struct context_entry *old_ce = NULL, *new_ce = NULL, ce;
 	int tbl_idx, pos = 0, idx, devfn, ret = 0, did;
+	struct context_entry __iomem *old_ce = NULL;
+	struct context_entry *new_ce = NULL, ce;
+	struct root_entry re;
 	phys_addr_t old_ce_phys;
 
 	tbl_idx = ext ? bus * 2 : bus;
+	memcpy_fromio(&re, old_re, sizeof(re));
 
 	for (devfn = 0; devfn < 256; devfn++) {
 		/* First calculate the correct index */
@@ -2827,9 +2830,9 @@ static int copy_context_table(struct intel_iommu *iommu,
 
 			ret = 0;
 			if (devfn < 0x80)
-				old_ce_phys = root_entry_lctp(old_re);
+				old_ce_phys = root_entry_lctp(&re);
 			else
-				old_ce_phys = root_entry_uctp(old_re);
+				old_ce_phys = root_entry_uctp(&re);
 
 			if (!old_ce_phys) {
 				if (ext && devfn == 0) {
@@ -2854,7 +2857,7 @@ static int copy_context_table(struct intel_iommu *iommu,
 		}
 
 		/* Now copy the context entry */
-		ce = old_ce[idx];
+		memcpy_fromio(&ce, old_ce + idx, sizeof(ce));
 
 		if (!__context_present(&ce))
 			continue;
@@ -2898,8 +2901,8 @@ out:
 
 static int copy_translation_tables(struct intel_iommu *iommu)
 {
+	struct root_entry __iomem *old_rt;
 	struct context_entry **ctxt_tbls;
-	struct root_entry *old_rt;
 	phys_addr_t old_rt_phys;
 	int ctxt_table_entries;
 	unsigned long flags;
drivers/iommu/intel_irq_remapping.c +2 -2
index 27cdfa8..9ec4e0d 100644
@@ -384,7 +384,7 @@ static int set_msi_sid(struct irte *irte, struct pci_dev *dev)
 
 static int iommu_load_old_irte(struct intel_iommu *iommu)
 {
-	struct irte *old_ir_table;
+	struct irte __iomem *old_ir_table;
 	phys_addr_t irt_phys;
 	unsigned int i;
 	size_t size;
@@ -413,7 +413,7 @@ static int iommu_load_old_irte(struct intel_iommu *iommu)
 		return -ENOMEM;
 
 	/* Copy data over */
-	memcpy(iommu->ir_table->base, old_ir_table, size);
+	memcpy_fromio(iommu->ir_table->base, old_ir_table, size);
 
 	__iommu_flush_cache(iommu, iommu->ir_table->base, size);
 
Signature · 1 line
1.9.1
author maintainer
#8 lore raw

PATCH 8/9 iommu/msm: Use BUG_ON instead of if () BUG()

In reply to Joerg Roedel

From: Joerg Roedel <[email protected]>

Found by a coccicheck script.

---
 drivers/iommu/msm_iommu.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iommu/msm_iommu.c +2 -2
index 15a2063..e321fa5 100644
@@ -106,8 +106,8 @@ static int __flush_iotlb(struct iommu_domain *domain)
 #endif
 
 	list_for_each_entry(ctx_drvdata, &priv->list_attached, attached_elm) {
-		if (!ctx_drvdata->pdev || !ctx_drvdata->pdev->dev.parent)
-			BUG();
+
+		BUG_ON(!ctx_drvdata->pdev || !ctx_drvdata->pdev->dev.parent);
 
 		iommu_drvdata = dev_get_drvdata(ctx_drvdata->pdev->dev.parent);
 		BUG_ON(!iommu_drvdata);
Signature · 1 line
1.9.1
author maintainer
#9 lore raw

PATCH 9/9 iommu/io-pgtable-arm: Move init-fn declarations to io-pgtable.h

In reply to Joerg Roedel

From: Joerg Roedel <[email protected]>

Avoid extern declarations in c files.

---
 drivers/iommu/io-pgtable.c | 5 -----
 drivers/iommu/io-pgtable.h | 5 +++++
 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/iommu/io-pgtable.c +0 -5
index 6436fe2..6f2e319 100644
@@ -24,11 +24,6 @@
 
 #include "io-pgtable.h"
 
-extern struct io_pgtable_init_fns io_pgtable_arm_32_lpae_s1_init_fns;
-extern struct io_pgtable_init_fns io_pgtable_arm_32_lpae_s2_init_fns;
-extern struct io_pgtable_init_fns io_pgtable_arm_64_lpae_s1_init_fns;
-extern struct io_pgtable_init_fns io_pgtable_arm_64_lpae_s2_init_fns;
-
 static const struct io_pgtable_init_fns *
 io_pgtable_init_table[IO_PGTABLE_NUM_FMTS] =
 {
drivers/iommu/io-pgtable.h +5 -0
index 48538a3..ac9e234 100644
@@ -143,4 +143,9 @@ struct io_pgtable_init_fns {
 	void (*free)(struct io_pgtable *iop);
 };
 
+extern struct io_pgtable_init_fns io_pgtable_arm_32_lpae_s1_init_fns;
+extern struct io_pgtable_init_fns io_pgtable_arm_32_lpae_s2_init_fns;
+extern struct io_pgtable_init_fns io_pgtable_arm_64_lpae_s1_init_fns;
+extern struct io_pgtable_init_fns io_pgtable_arm_64_lpae_s2_init_fns;
+
 #endif /* __IO_PGTABLE_H */
Signature · 1 line
1.9.1