Advertisement
Black_Fox

pciutils Fedora patch relevant to amdgpuinfo#1

Apr 19th, 2020
1,304
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 3.96 KB | None | 0 0
  1. diff -up pciutils-3.0.0/lib/names-parse.c.dird pciutils-3.0.0/lib/names-parse.c
  2. --- pciutils-3.0.0/lib/names-parse.c.dird   2008-04-10 21:15:47.000000000 +0200
  3. +++ pciutils-3.0.0/lib/names-parse.c    2008-09-01 15:17:23.000000000 +0200
  4. @@ -6,10 +6,13 @@
  5.   * Can be freely distributed and used under the terms of the GNU GPL.
  6.   */
  7.  
  8. +#define _GNU_SOURCE
  9.  #include <stdio.h>
  10.  #include <stdlib.h>
  11.  #include <string.h>
  12.  #include <errno.h>
  13. +#include <dirent.h>
  14. +#include <libgen.h>
  15.  
  16.  #include "internal.h"
  17.  #include "names.h"
  18. @@ -82,7 +85,7 @@ static inline int id_white_p(int c)
  19.  }
  20.  
  21.  
  22. -static const char *id_parse_list(struct pci_access *a, pci_file f, int *lino)
  23. +static const char *id_parse_list(struct pci_access *a, pci_file f, int *lino, int flags)
  24.  {
  25.    char line[MAX_LINE];
  26.    char *p;
  27. @@ -207,7 +210,7 @@ static const char *id_parse_list(struct
  28.     p++;
  29.        if (!*p)
  30.     return parse_error;
  31. -      if (pci_id_insert(a, cat, id1, id2, id3, id4, p, SRC_LOCAL))
  32. +      if (pci_id_insert(a, cat, id1, id2, id3, id4, p, SRC_LOCAL) && flags)
  33.     return "Duplicate entry";
  34.      }
  35.    return NULL;
  36. @@ -223,13 +226,14 @@ pci_load_name_list(struct pci_access *a)
  37.    pci_free_name_list(a);
  38.    a->id_load_failed = 1;
  39.    if (!(f = pci_open(a)))
  40. -    return 0;
  41. -  err = id_parse_list(a, f, &lino);
  42. +    return pci_new_load_name_list(a);
  43. +  err = id_parse_list(a, f, &lino, 0);
  44.    PCI_ERROR(f, err);
  45.    pci_close(f);
  46.    if (err)
  47.      a->error("%s at %s, line %d\n", err, a->id_file_name, lino);
  48.    a->id_load_failed = 0;
  49. +  pci_new_load_name_list(a);
  50.    return 1;
  51.  }
  52.  
  53. @@ -249,3 +253,49 @@ pci_set_name_list_path(struct pci_access
  54.    a->id_file_name = name;
  55.    a->free_id_name = to_be_freed;
  56.  }
  57. +int pci_new_load_name_list(struct pci_access *a)
  58. +{
  59. +  pci_file f;
  60. +  int lino, tempsize;
  61. +  const char *err;
  62. +  char *temp;
  63. +  char new_id_path[PATH_MAX+1] = {0,};
  64. +  DIR *pci_ids_dir;
  65. +  struct dirent *dp;
  66. +  
  67. +  strncpy(new_id_path, a->id_file_name, PATH_MAX);
  68. +  new_id_path[PATH_MAX] = 0;
  69. +  strncat(new_id_path, ".d/", PATH_MAX - strnlen(new_id_path, PATH_MAX));
  70. +  /* printf("new_id_path is %s\n", new_id_path); */
  71. +  pci_ids_dir = opendir(new_id_path);
  72. +  if (pci_ids_dir == NULL)
  73. +    return 0;
  74. +
  75. +  do
  76. +    {
  77. +     if ((dp = readdir(pci_ids_dir)) != NULL)
  78. +       {
  79. +          if (! strcmp(dp->d_name, "..") || ! strcmp(dp->d_name, "."))
  80. +            continue;
  81. +          if (strstr(dp->d_name, ".ids"))
  82. +            {
  83. +             tempsize = strnlen(new_id_path, PATH_MAX) + dp->d_reclen + 1;
  84. +             temp = malloc(tempsize);      /* This malloced memory is freed in the function pci_set_name_list_path() */
  85. +             memset(temp, 0, tempsize);
  86. +             strncpy(temp, new_id_path, (strnlen(new_id_path, PATH_MAX))+1);
  87. +             strncat(temp, dp->d_name, PATH_MAX - strnlen(temp, PATH_MAX));
  88. +             /* printf("Found file %s, processing it\n", temp); */
  89. +             pci_set_name_list_path(a, temp, 1);
  90. +             if (!(f = pci_open(a)))
  91. +               continue;
  92. +             err = id_parse_list(a, f, &lino, 0);
  93. +             PCI_ERROR(f, err);
  94. +             pci_close(f);
  95. +             if (err)
  96. +               a->error("%s at %s, line %d\n", err, a->id_file_name, lino);
  97. +            }
  98. +       }
  99. +    }while (dp != NULL);
  100. +  closedir(pci_ids_dir);
  101. +  return 1;
  102. +}  
  103. diff -up pciutils-3.0.0/lib/pci.h.dird pciutils-3.0.0/lib/pci.h
  104. --- pciutils-3.0.0/lib/pci.h.dird   2008-04-10 21:23:05.000000000 +0200
  105. +++ pciutils-3.0.0/lib/pci.h    2008-09-01 15:17:23.000000000 +0200
  106. @@ -194,6 +194,7 @@ int pci_load_name_list(struct pci_access
  107.  void pci_free_name_list(struct pci_access *a) PCI_ABI; /* Called automatically by pci_cleanup() */
  108.  void pci_set_name_list_path(struct pci_access *a, char *name, int to_be_freed) PCI_ABI;
  109.  void pci_id_cache_flush(struct pci_access *a) PCI_ABI;
  110. +int pci_new_load_name_list(struct pci_access *a);
  111.  
  112.  enum pci_lookup_mode {
  113.    PCI_LOOKUP_VENDOR = 1,       /* Vendor name (args: vendorID) */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement