iommu/vt-d: Introduce macro for_each_dev_scope() to walk device scope entries

Introduce for_each_dev_scope()/for_each_active_dev_scope() to walk
{active} device scope entries. This will help following RCU lock
related patches.

Signed-off-by: Jiang Liu <jiang.liu@linux.intel.com>
Signed-off-by: Joerg Roedel <joro@8bytes.org>
diff --git a/drivers/iommu/dmar.c b/drivers/iommu/dmar.c
index 58dde75..4ae6df2 100644
--- a/drivers/iommu/dmar.c
+++ b/drivers/iommu/dmar.c
@@ -170,9 +170,12 @@
 
 void dmar_free_dev_scope(struct pci_dev ***devices, int *cnt)
 {
+	int i;
+	struct pci_dev *tmp_dev;
+
 	if (*devices && *cnt) {
-		while (--*cnt >= 0)
-			pci_dev_put((*devices)[*cnt]);
+		for_each_active_dev_scope(*devices, *cnt, i, tmp_dev)
+			pci_dev_put(tmp_dev);
 		kfree(*devices);
 		*devices = NULL;
 		*cnt = 0;
@@ -402,10 +405,11 @@
 			  struct pci_dev *dev)
 {
 	int index;
+	struct pci_dev *tmp;
 
 	while (dev) {
-		for (index = 0; index < cnt; index++)
-			if (dev == devices[index])
+		for_each_active_dev_scope(devices, cnt, index, tmp)
+			if (dev == tmp)
 				return 1;
 
 		/* Check our parent */
@@ -452,7 +456,7 @@
 	if (list_empty(&dmar_drhd_units))
 		goto fail;
 
-	list_for_each_entry(drhd, &dmar_drhd_units, list) {
+	for_each_drhd_unit(drhd) {
 		ret = dmar_parse_dev(drhd);
 		if (ret)
 			goto fail;