summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Nieder <jrnieder@gmail.com>2012-02-24 21:47:13 -0600
committerDave Airlie <airlied@redhat.com>2012-03-09 09:35:47 +0000
commit47e021d5ba4731a92b0eca9bce30427418d81a0a (patch)
treeba86943c788290e999e098ead259118787f24e0b
parent20840fc94fe709c047093c82eb78c4258d5fdcd1 (diff)
use continue statement to simplify "for each PCI device" loop
In the construct for each PCI device: if PCI ID is interesting: long block of code to handle the detected device the "if" with long body leaves the reader in suspense about what will happen when the PCI ID is not interesting. Rewriting as for each PCI device: if PCI ID is uninteresting: continue handle the detected device deals with the easy case right away and decreases nesting for the bulk of the "while" loop body as a nice side effect. No change in functionality intended. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Dave Airlie <airlied@redhat.com>
-rw-r--r--avivotool.c62
-rw-r--r--radeonreg.c28
-rw-r--r--radeontool.c54
3 files changed, 75 insertions, 69 deletions
diff --git a/avivotool.c b/avivotool.c
index 9a01a9f..f08ab2d 100644
--- a/avivotool.c
+++ b/avivotool.c
@@ -1825,40 +1825,42 @@ static int map_radeon_mem(void)
while ((device = pci_device_next(iter))) {
pci_device_probe(device);
- if (device->vendor_id == 0x1002 &&
- (((device->device_class & 0x00ffff00) == 0x00030000) ||
- ((device->device_class & 0x00ffff00) == 0x00038000))) {
- for (i = 0; i < sizeof(RADEONCards) / sizeof(RADEONCardInfo); i++) {
- if (RADEONCards[i].pci_device_id == device->device_id)
- card_info = &RADEONCards[i];
- }
+ if (device->vendor_id != 0x1002)
+ continue;
+ if ((device->device_class & 0x00ffff00) != 0x00030000 &&
+ (device->device_class & 0x00ffff00) != 0x00038000)
+ continue;
+
+ for (i = 0; i < sizeof(RADEONCards) / sizeof(RADEONCardInfo); i++) {
+ if (RADEONCards[i].pci_device_id == device->device_id)
+ card_info = &RADEONCards[i];
+ }
- if (debug) {
- printf("Found card %x:%x (%x)\n", device->vendor_id,
- device->device_id, device->device_class);
+ if (debug) {
+ printf("Found card %x:%x (%x)\n", device->vendor_id,
+ device->device_id, device->device_class);
- if (card_info)
- printf("Found card %x %s %s %s\n", card_info->pci_device_id,
- family_strings[card_info->chip_family],
- card_info->mobility ? "mobile" : "",
- card_info->igp ? "igp" : "");
- }
+ if (card_info)
+ printf("Found card %x %s %s %s\n", card_info->pci_device_id,
+ family_strings[card_info->chip_family],
+ card_info->mobility ? "mobile" : "",
+ card_info->igp ? "igp" : "");
+ }
- 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(skip-- == 0) {
- break;
- }
+ 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(skip-- == 0) {
+ break;
}
}
diff --git a/radeonreg.c b/radeonreg.c
index 4d016fd..d5b4aa2 100644
--- a/radeonreg.c
+++ b/radeonreg.c
@@ -391,20 +391,22 @@ static int map_radeon_mem(void)
while ((device = pci_device_next(iter))) {
pci_device_probe(device);
- if (device->vendor_id == 0x1002 &&
- (((device->device_class & 0x00ffff00) == 0x00030000) ||
- ((device->device_class & 0x00ffff00) == 0x00038000))) {
- for (i = 0; i < sizeof(RADEONCards) / sizeof(RADEONCardInfo); i++) {
- if (RADEONCards[i].pci_device_id == device->device_id)
- card_info = &RADEONCards[i];
- }
+ if (device->vendor_id != 0x1002)
+ continue;
+ if ((device->device_class & 0x00ffff00) != 0x00030000 &&
+ (device->device_class & 0x00ffff00) != 0x00038000)
+ 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;
- if(skip-- == 0) {
- break;
- }
+ fb_region = 0;
+ ctrl_region = 2;
+ avivo_device = device;
+ if(skip-- == 0) {
+ break;
}
}
diff --git a/radeontool.c b/radeontool.c
index d259254..ecf13d1 100644
--- a/radeontool.c
+++ b/radeontool.c
@@ -932,35 +932,37 @@ static void map_radeon_cntl_mem(void)
while ((device = pci_device_next(iter))) {
pci_device_probe(device);
- if (device->vendor_id == 0x1002 &&
- (device->device_class & 0x00ffff00) == 0x00030000) {
- if (debug) {
- printf("Found card %x:%x (%x)\n", device->vendor_id,
- device->device_id, device->device_class);
- }
+ if (device->vendor_id != 0x1002)
+ continue;
+ if ((device->device_class & 0x00ffff00) != 0x00030000)
+ continue;
+
+ if (debug) {
+ printf("Found card %x:%x (%x)\n", device->vendor_id,
+ device->device_id, device->device_class);
+ }
- if (skip-- != 0) {
- 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 (skip-- != 0) {
+ 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 (ctrl_region == -1)
+ die("cannot find ctrl region");
+ if (fb_region == -1)
+ die("cannot find fb region");
+ avivo_device = device;
+ break;
}
if (!avivo_device)