]> mj.ucw.cz Git - pciutils.git/commitdiff
Detect and report loops in capability lists.
authorMartin Mares <mj@ucw.cz>
Fri, 5 Oct 2007 10:37:16 +0000 (12:37 +0200)
committerMartin Mares <mj@ucw.cz>
Fri, 5 Oct 2007 10:37:16 +0000 (12:37 +0200)
ChangeLog
lspci.c

index 69ea70f69b8b72a7536f2ba16910077c10c098d2..daf35344392c7980973799de33868cc230dc2e0a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2007-10-05  Martin Mares <mj@ucw.cz>
+
+       * lspci.c (show_caps, show_ext_caps): Detect and report loops in
+       capability lists.
+
 2007-09-12  Hasso Tepper <hasso@estpak.ee>
 
        * Extended the fbsd-device backend to run on Dragonfly BSD.
diff --git a/lspci.c b/lspci.c
index f02219b2986e8e8639756f73778755b9cda1dd6a..2576068448349571c5355eb0bac429c4a268f394 100644 (file)
--- a/lspci.c
+++ b/lspci.c
@@ -1374,6 +1374,8 @@ static void
 show_ext_caps(struct device *d)
 {
   int where = 0x100;
+  char been_there[0x1000];
+  memset(been_there, 0, 0x1000);
   do
     {
       u32 header;
@@ -1386,6 +1388,11 @@ show_ext_caps(struct device *d)
        break;
       id = header & 0xffff;
       printf("\tCapabilities: [%03x] ", where);
+      if (been_there[where++])
+       {
+         printf("<chain looped>\n");
+         break;
+       }
       switch (id)
        {
          case PCI_EXT_CAP_ID_AER:
@@ -1416,6 +1423,8 @@ show_caps(struct device *d)
   if (get_conf_word(d, PCI_STATUS) & PCI_STATUS_CAP_LIST)
     {
       int where = get_conf_byte(d, PCI_CAPABILITY_LIST) & ~3;
+      byte been_there[256];
+      memset(been_there, 0, 256);
       while (where)
        {
          int id, next, cap;
@@ -1429,6 +1438,11 @@ show_caps(struct device *d)
          next = get_conf_byte(d, where + PCI_CAP_LIST_NEXT) & ~3;
          cap = get_conf_word(d, where + PCI_CAP_FLAGS);
          printf("[%02x] ", where);
+         if (been_there[where]++)
+           {
+             printf("<chain looped>\n");
+             break;
+           }
          if (id == 0xff)
            {
              printf("<chain broken>\n");