From bb5e934df7f23fb365ed673a12d283ff52af79c0 Mon Sep 17 00:00:00 2001 From: Daniel Stone Date: Fri, 26 Aug 2005 07:15:04 +0000 Subject: [PATCH] Only open /proc/bus/pci/devices once. (Ubuntu #029) --- hw/xfree86/os-support/linux/lnx_pci.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/hw/xfree86/os-support/linux/lnx_pci.c b/hw/xfree86/os-support/linux/lnx_pci.c index 97edd11a6..1b74fcbbd 100644 --- a/hw/xfree86/os-support/linux/lnx_pci.c +++ b/hw/xfree86/os-support/linux/lnx_pci.c @@ -23,10 +23,11 @@ #define PCIADDR_FMT "%lx" #endif +FILE *xf86OSLinuxPCIFile = NULL; + Bool xf86GetPciSizeFromOS(PCITAG tag, int index, int* bits) { - FILE *file; char c[0x200]; char *res; unsigned int bus, devfn, dev, fn; @@ -37,10 +38,11 @@ xf86GetPciSizeFromOS(PCITAG tag, int index, int* bits) if (index > 7) return FALSE; - if (!(file = fopen("/proc/bus/pci/devices","r"))) + if (!xf86OSLinuxPCIFile && \ + !(xf86OSLinuxPCIFile = fopen("/proc/bus/pci/devices","r"))) return FALSE; do { - res = fgets(c,0x1ff,file); + res = fgets(c,0x1ff,xf86OSLinuxPCIFile); if (res) { num = sscanf(res, /*bus+dev vendorid deviceid irq */ @@ -64,7 +66,7 @@ xf86GetPciSizeFromOS(PCITAG tag, int index, int* bits) &bus,&devfn,&size[0],&size[1],&size[2],&size[3], &size[4],&size[5],&size[6]); if (num != 9) { /* apparantly not 2.3 style */ - fclose(file); + fseek(xf86OSLinuxPCIFile, 0L, SEEK_SET); return FALSE; } dev = devfn >> 3; @@ -78,13 +80,13 @@ xf86GetPciSizeFromOS(PCITAG tag, int index, int* bits) (*bits)++; } } - fclose(file); + fseek(xf86OSLinuxPCIFile, 0L, SEEK_SET); return TRUE; } } } while (res); - fclose(file); + fseek(xf86OSLinuxPCIFile, 0L, SEEK_SET); return FALSE; }