Fix long standing MTRR bug.
[platform/upstream/libpciaccess.git] / src / common_vgaarb.c
index 6358a66..86eceb5 100644 (file)
@@ -33,6 +33,7 @@
 #include <stdlib.h>
 #include <limits.h>
 
+#include "config.h"
 #include "pciaccess.h"
 #include "pciaccess_private.h"
 
@@ -42,7 +43,7 @@ static int
 parse_string_to_decodes_rsrc(char *input, int *vga_count, struct pci_slot_match *match)
 {
     char *tok;
-    char *input_sp, *count_sp, *pci_sp;
+    char *input_sp = NULL, *count_sp, *pci_sp;
     char tmp[32];
 
     tok = strtok_r(input,",",&input_sp);
@@ -259,10 +260,17 @@ pci_device_vgaarb_decodes(int new_vgaarb_rsrc)
     if (dev->vgaarb_rsrc == new_vgaarb_rsrc)
         return 0;
 
-    len = snprintf(buf, BUFSIZE, "decodes %s", rsrc_to_str(dev->vgaarb_rsrc));
+    len = snprintf(buf, BUFSIZE, "decodes %s", rsrc_to_str(new_vgaarb_rsrc));
     ret = vgaarb_write(pci_sys->vgaarb_fd, buf, len);
     if (ret == 0)
         dev->vgaarb_rsrc = new_vgaarb_rsrc;
+
+    ret = read(pci_sys->vgaarb_fd, buf, BUFSIZE);
+    if (ret <= 0)
+        return -1;
+
+    parse_string_to_decodes_rsrc(buf, &pci_sys->vga_count, NULL);
+
     return ret;
 }