[PATCH 05/10] exit "for each PCI device" loop as soon as Radeon device is found

Jonathan Nieder jrnieder at gmail.com
Fri Feb 24 19:55:03 PST 2012


This just unindents the code some more.

Signed-off-by: Jonathan Nieder <jrnieder at gmail.com>
---
 avivotool.c  |   30 +++++++++++++++---------------
 radeonreg.c  |   24 ++++++++++++------------
 radeontool.c |   44 +++++++++++++++++++++-----------------------
 3 files changed, 48 insertions(+), 50 deletions(-)

diff --git a/avivotool.c b/avivotool.c
index ab41286b..9c35fc79 100644
--- a/avivotool.c
+++ b/avivotool.c
@@ -1850,26 +1850,26 @@ static int map_radeon_mem(void)
 
         if (skip--)
             continue;
-
-        for (i = 0; i < 6; i++) {
-            if (device->regions[i].size == 64 * 1024)
-                ctrl_region = i;
-            else if (device->regions[i].size == 128 * 1024)
-                ctrl_region = i;
-            else if (device->regions[i].size == 256 * 1024)
-                ctrl_region = i;
-            else if (device->regions[i].size >= 128 * 1024 * 1024)
-                fb_region = i;
-        }
-        avivo_device = device;
         break;
     }
 
-    if (!avivo_device){
-      printf("cannot find Radeon device\n");
-      return -1;
+    if (!device) {
+        printf("cannot find Radeon device\n");
+        return -1;
     }
       
+    for (i = 0; i < 6; i++) {
+        if (device->regions[i].size == 64 * 1024)
+            ctrl_region = i;
+        else if (device->regions[i].size == 128 * 1024)
+            ctrl_region = i;
+        else if (device->regions[i].size == 256 * 1024)
+            ctrl_region = i;
+        else if (device->regions[i].size >= 128 * 1024 * 1024)
+            fb_region = i;
+    }
+    avivo_device = device;
+
     if (pci_device_map_region(avivo_device, ctrl_region, 1) != 0) {
         fprintf(stderr, "error: mapping ctrl region\n");
         return -1;
diff --git a/radeonreg.c b/radeonreg.c
index 14e8b0a7..2223cee2 100644
--- a/radeonreg.c
+++ b/radeonreg.c
@@ -398,23 +398,23 @@ static int map_radeon_mem(void)
             continue;
         if (skip--)
             continue;
-
-        for (i = 0; i < sizeof(RADEONCards) / sizeof(RADEONCardInfo); i++) {
-            if (RADEONCards[i].pci_device_id == device->device_id)
-                card_info = &RADEONCards[i];
-        }
-
-        fb_region = 0;
-        ctrl_region = 2;
-        avivo_device = device;
         break;
     }
 
-    if (!avivo_device){
-      printf("cannot find Radeon device\n");
-      return -1;
+    if (!device) {
+        printf("cannot find Radeon device\n");
+        return -1;
     }
 
+    for (i = 0; i < sizeof(RADEONCards) / sizeof(RADEONCardInfo); i++) {
+        if (RADEONCards[i].pci_device_id == device->device_id)
+            card_info = &RADEONCards[i];
+    }
+
+    fb_region = 0;
+    ctrl_region = 2;
+    avivo_device = device;
+
     if (pci_device_map_region(avivo_device, ctrl_region, 1) != 0)
         die("mapping ctrl region");
     ctrl_mem = avivo_device->regions[ctrl_region].memory;
diff --git a/radeontool.c b/radeontool.c
index ecf13d10..9ed92c24 100644
--- a/radeontool.c
+++ b/radeontool.c
@@ -937,37 +937,35 @@ static void map_radeon_cntl_mem(void)
         if ((device->device_class & 0x00ffff00) != 0x00030000)
             continue;
 
-        if (debug) {
+        if (debug)
             printf("Found card %x:%x (%x)\n", device->vendor_id,
                    device->device_id, device->device_class);
-        }
-
-        if (skip-- != 0) {
+        if (skip--)
             continue;
-        }
-        for (i = 0; i < 6; i++) {
-            if (device->regions[i].size >= 16 * 1024 &&
-                device->regions[i].size <= 64 * 1024) {
-                if (ctrl_region != -1)
-                    die("cannot distinguish ctrl region");
-                ctrl_region = i;
-            } else if (device->regions[i].size >= 64 * 1024 * 1024) {
-                if (fb_region != -1)
-                    die("cannot distinguish fb region");
-                fb_region = i;
-            }
-        }
-        if (ctrl_region == -1)
-            die("cannot find ctrl region");
-        if (fb_region == -1)
-            die("cannot find fb region");
-        avivo_device = device;
         break;
     }
 
-    if (!avivo_device)
+    if (!device)
         die("cannot find Radeon device");
 
+    for (i = 0; i < 6; i++) {
+        if (device->regions[i].size >= 16 * 1024 &&
+            device->regions[i].size <= 64 * 1024) {
+            if (ctrl_region != -1)
+                die("cannot distinguish ctrl region");
+            ctrl_region = i;
+        } else if (device->regions[i].size >= 64 * 1024 * 1024) {
+            if (fb_region != -1)
+                die("cannot distinguish fb region");
+            fb_region = i;
+        }
+    }
+    if (ctrl_region == -1)
+        die("cannot find ctrl region");
+    if (fb_region == -1)
+        die("cannot find fb region");
+    avivo_device = device;
+
     if (pci_device_map_region(avivo_device, ctrl_region, 1) != 0)
         die("mapping ctrl region");
     ctrl_mem = avivo_device->regions[ctrl_region].memory;
-- 
1.7.9.2



More information about the xorg-driver-ati mailing list