From f93c0dae5a837404a48ea7f3609c6c5c30691a7b Mon Sep 17 00:00:00 2001 From: zhanghongtao Date: Mon, 1 Aug 2022 15:28:14 +0800 Subject: [PATCH 1/4] Add parentheses to the macro definition Signed-off-by: zhanghongtao --- src/pci_tools.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pci_tools.h b/src/pci_tools.h index 3766890..47b121f 100644 --- a/src/pci_tools.h +++ b/src/pci_tools.h @@ -165,7 +165,7 @@ typedef struct pcitool_intr_get { #define PCITOOL_IGET_SIZE(num_devs) \ (sizeof (pcitool_intr_get_t) - \ sizeof (pcitool_intr_dev_t) + \ - (num_devs * sizeof (pcitool_intr_dev_t))) + ((num_devs) * sizeof (pcitool_intr_dev_t))) /* * Size and endian fields for acc_attr bitmask. @@ -175,12 +175,12 @@ typedef struct pcitool_intr_get { #define PCITOOL_ACC_ATTR_SIZE_2 0x1 #define PCITOOL_ACC_ATTR_SIZE_4 0x2 #define PCITOOL_ACC_ATTR_SIZE_8 0x3 -#define PCITOOL_ACC_ATTR_SIZE(x) (1 << (x & PCITOOL_ACC_ATTR_SIZE_MASK)) +#define PCITOOL_ACC_ATTR_SIZE(x) (1 << ((x) & PCITOOL_ACC_ATTR_SIZE_MASK)) #define PCITOOL_ACC_ATTR_ENDN_MASK 0x100 #define PCITOOL_ACC_ATTR_ENDN_LTL 0x0 #define PCITOOL_ACC_ATTR_ENDN_BIG 0x100 -#define PCITOOL_ACC_IS_BIG_ENDIAN(x) (x & PCITOOL_ACC_ATTR_ENDN_BIG) +#define PCITOOL_ACC_IS_BIG_ENDIAN(x) ((x) & PCITOOL_ACC_ATTR_ENDN_BIG) /* * Data structure to read and write to pci device registers. -- GitLab From b8de959615449fdf5b58ef08d881a77d397e86e2 Mon Sep 17 00:00:00 2001 From: zhanghongtao Date: Mon, 1 Aug 2022 15:53:57 +0800 Subject: [PATCH 2/4] pci_sys set NULL after free Signed-off-by: zhanghongtao --- src/freebsd_pci.c | 2 ++ src/netbsd_pci.c | 1 + 2 files changed, 3 insertions(+) diff --git a/src/freebsd_pci.c b/src/freebsd_pci.c index 3794328..709bfb6 100644 --- a/src/freebsd_pci.c +++ b/src/freebsd_pci.c @@ -663,12 +663,14 @@ pci_system_freebsd_create( void ) if ( ioctl( pcidev, PCIOCGETCONF, &pciconfio ) == -1) { free( pci_sys ); + pci_sys = NULL; close( pcidev ); return errno; } if (pciconfio.status == PCI_GETCONF_ERROR ) { free( pci_sys ); + pci_sys = NULL; close( pcidev ); return EINVAL; } diff --git a/src/netbsd_pci.c b/src/netbsd_pci.c index 1f3bcea..b6a5ccd 100644 --- a/src/netbsd_pci.c +++ b/src/netbsd_pci.c @@ -942,6 +942,7 @@ pci_system_netbsd_create(void) for (i = 0; i < nbuses; i++) close(buses[i].fd); free(pci_sys); + pci_sys = NULL; return ENOMEM; } -- GitLab From ab475c645ff9fc40e18af739eb4b81a5eb7f783c Mon Sep 17 00:00:00 2001 From: zhanghongtao Date: Mon, 1 Aug 2022 16:13:40 +0800 Subject: [PATCH 3/4] Add header protection macro in linux_devmem.h Signed-off-by: zhanghongtao --- src/linux_devmem.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/linux_devmem.h b/src/linux_devmem.h index e69557f..0ae5452 100644 --- a/src/linux_devmem.h +++ b/src/linux_devmem.h @@ -30,5 +30,10 @@ * \author Ian Romanick */ +#ifndef LINUX_DEVMEM_H +#define LINUX_DEVMEM_H + extern int pci_device_linux_devmem_read_rom(struct pci_device *dev, void *buffer); + +#endif -- GitLab From a8abf913ad6b60492ef7b6ae512c4f879604a6a7 Mon Sep 17 00:00:00 2001 From: zhanghongtao Date: Mon, 1 Aug 2022 16:20:28 +0800 Subject: [PATCH 4/4] Delete redundant symbols ';' Signed-off-by: zhanghongtao --- src/linux_sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/linux_sysfs.c b/src/linux_sysfs.c index d79404e..1b4051b 100644 --- a/src/linux_sysfs.c +++ b/src/linux_sysfs.c @@ -981,7 +981,7 @@ pci_device_linux_sysfs_map_legacy(struct pci_device *dev, pciaddr_t base, int ret=0; if (map_flags & PCI_DEV_MAP_FLAG_WRITABLE) { - flags = O_RDWR; /* O_RDWR != O_WRONLY | O_RDONLY */; + flags = O_RDWR; /* O_RDWR != O_WRONLY | O_RDONLY */ prot |= PROT_WRITE; } -- GitLab