From a4bb46627f67b6af7a257c74968379aafe56b087 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pali=20Roh=C3=A1r?= Date: Sun, 26 Dec 2021 22:11:45 +0100 Subject: [PATCH] lspci: Declare variables before doing function calls Unfortunately this change is needed for MSVC as otherwise it throws compile errors. --- ls-ecaps.c | 35 ++++++++++++++++++++++++----------- ls-tree.c | 3 ++- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/ls-ecaps.c b/ls-ecaps.c index 99c55ff..2c63aeb 100644 --- a/ls-ecaps.c +++ b/ls-ecaps.c @@ -637,6 +637,13 @@ cap_rclink(struct device *d, int where) static void cap_rcec(struct device *d, int where) { + u32 hdr; + byte cap_ver; + u32 bmap; + u32 busn; + u8 lastbusn; + u8 nextbusn; + printf("Root Complex Event Collector Endpoint Association\n"); if (verbose < 2) return; @@ -644,9 +651,9 @@ cap_rcec(struct device *d, int where) if (!config_fetch(d, where, 12)) return; - u32 hdr = get_conf_long(d, where); - byte cap_ver = PCI_RCEC_EP_CAP_VER(hdr); - u32 bmap = get_conf_long(d, where + PCI_RCEC_RCIEP_BMAP); + hdr = get_conf_long(d, where); + cap_ver = PCI_RCEC_EP_CAP_VER(hdr); + bmap = get_conf_long(d, where + PCI_RCEC_RCIEP_BMAP); printf("\t\tRCiEPBitmap: "); if (bmap) { @@ -679,9 +686,9 @@ cap_rcec(struct device *d, int where) if (cap_ver < PCI_RCEC_BUSN_REG_VER) return; - u32 busn = get_conf_long(d, where + PCI_RCEC_BUSN_REG); - u8 lastbusn = BITS(busn, 16, 8); - u8 nextbusn = BITS(busn, 8, 8); + busn = get_conf_long(d, where + PCI_RCEC_BUSN_REG); + lastbusn = BITS(busn, 16, 8); + nextbusn = BITS(busn, 8, 8); if ((lastbusn == 0x00) && (nextbusn == 0xff)) printf("\t\tAssociatedBusNumbers: %s\n", (verbose > 2) ? "ff-00 [none]" : "[none]"); @@ -719,6 +726,12 @@ cap_dvsec_cxl(struct device *d, int where) static void cap_dvsec(struct device *d, int where) { + u32 hdr; + u16 vendor; + byte rev; + u16 len; + u16 id; + printf("Designated Vendor-Specific: "); if (!config_fetch(d, where + PCI_DVSEC_HEADER1, 8)) { @@ -726,12 +739,12 @@ cap_dvsec(struct device *d, int where) return; } - u32 hdr = get_conf_long(d, where + PCI_DVSEC_HEADER1); - u16 vendor = BITS(hdr, 0, 16); - byte rev = BITS(hdr, 16, 4); - u16 len = BITS(hdr, 20, 12); + hdr = get_conf_long(d, where + PCI_DVSEC_HEADER1); + vendor = BITS(hdr, 0, 16); + rev = BITS(hdr, 16, 4); + len = BITS(hdr, 20, 12); - u16 id = get_conf_long(d, where + PCI_DVSEC_HEADER2); + id = get_conf_long(d, where + PCI_DVSEC_HEADER2); printf("Vendor=%04x ID=%04x Rev=%d Len=%d", vendor, id, rev, len); if (vendor == PCI_DVSEC_VENDOR_ID_CXL && id == PCI_DVSEC_ID_CXL && len >= 16) diff --git a/ls-tree.c b/ls-tree.c index aaa1ee9..6d4e62b 100644 --- a/ls-tree.c +++ b/ls-tree.c @@ -169,12 +169,13 @@ tree_printf(char *line, char *p, char *fmt, ...) { va_list args; int space = line + LINE_BUF_SIZE - 1 - p; + int res; if (space <= 0) return p; va_start(args, fmt); - int res = vsnprintf(p, space, fmt, args); + res = vsnprintf(p, space, fmt, args); if (res < 0) { /* Ancient C libraries return -1 on overflow and they do not truncate the output properly. */