[PATCH umr 3/4] Various cleanups found by static analysis. (v2)
Tom St Denis
tom.stdenis at amd.com
Tue Jul 25 17:23:23 UTC 2017
Signed-off-by: Tom St Denis <tom.stdenis at amd.com>
Acked-by: Alex Deucher <alexander.deucher at amd.com>
(v2): Updated enumerate to not stop on other AMD PCI devices
---
src/app/enum.c | 4 +---
src/lib/create_asic_helper.c | 5 +++++
src/lib/discover.c | 9 +++++++--
src/lib/mmio.c | 8 ++++++++
4 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/src/app/enum.c b/src/app/enum.c
index 2c4b7695e3cb..1c56fe643616 100644
--- a/src/app/enum.c
+++ b/src/app/enum.c
@@ -55,7 +55,6 @@ void umr_enumerate_devices(void)
return;
}
do {
- x = 0;
do {
pdevice = pci_device_next(pci_iter);
} while (pdevice && pdevice->vendor_id != 0x1002);
@@ -64,12 +63,11 @@ void umr_enumerate_devices(void)
asics[devices].instance = -1;
asics[devices].asic->pci.pdevice = &asics[devices].pcopy;
asics[devices++].pcopy = *pdevice;
- x = 1;
}
} while (pdevice && devices < MAX_DEV);
// now try to match devices against instances
- for (y = 0; y < MAX_DEV; y++) {
+ for (y = 0; y < devices; y++) {
snprintf(path, sizeof(path)-1, "/sys/kernel/debug/dri/%d/name", y);
dri = fopen(path, "r");
if (dri) {
diff --git a/src/lib/create_asic_helper.c b/src/lib/create_asic_helper.c
index d0ee34ac951e..ffca35d7af93 100644
--- a/src/lib/create_asic_helper.c
+++ b/src/lib/create_asic_helper.c
@@ -48,6 +48,11 @@ struct umr_asic *umr_create_asic_helper(char *name, int family, ...)
}
va_end(ap);
+ if (!asic->no_blocks) {
+ free(asic);
+ return NULL;
+ }
+
asic->blocks = calloc(asic->no_blocks, sizeof(struct umr_ip_block *));
if (!asic->blocks) {
free(asic);
diff --git a/src/lib/discover.c b/src/lib/discover.c
index 0c4ee1c09ad8..0fc053712e37 100644
--- a/src/lib/discover.c
+++ b/src/lib/discover.c
@@ -269,20 +269,25 @@ struct umr_asic *umr_discover_asic(struct umr_options *options)
goto err_pci;
}
pci_iterator_destroy(pci_iter);
+
+ // enable device if kernel module isn't present
+ if (asic->options.no_kernel)
+ pci_device_enable(asic->pci.pdevice);
+
pci_device_probe(asic->pci.pdevice);
use_region = 6;
// try to detect based on ASIC family
if (asic->family <= FAMILY_SI) {
// try region 2 for SI
- if ( asic->pci.pdevice->regions[2].is_64 == 0 &&
+ if (asic->pci.pdevice->regions[2].is_64 == 0 &&
asic->pci.pdevice->regions[2].is_prefetchable == 0 &&
asic->pci.pdevice->regions[2].is_IO == 0) {
use_region = 2;
}
} else if (asic->family <= FAMILY_VI) {
// try region 5 for CIK..VI
- if ( asic->pci.pdevice->regions[5].is_64 == 0 &&
+ if (asic->pci.pdevice->regions[5].is_64 == 0 &&
asic->pci.pdevice->regions[5].is_prefetchable == 0 &&
asic->pci.pdevice->regions[5].is_IO == 0) {
use_region = 5;
diff --git a/src/lib/mmio.c b/src/lib/mmio.c
index 987704cb9944..47e5150d3201 100644
--- a/src/lib/mmio.c
+++ b/src/lib/mmio.c
@@ -88,6 +88,10 @@ uint32_t umr_read_reg(struct umr_asic *asic, uint64_t addr, enum regclass type)
if (addr == 0xFFFFFFFF)
fprintf(stderr, "[BUG]: reading from addr==0xFFFFFFFF is likely a bug\n");
+ // lop off top bits in no-kernel mode
+ if (asic->options.no_kernel)
+ addr &= 0xFFFFFF;
+
switch (type) {
case REG_MMIO:
if (asic->pci.mem && !(addr & ~0xFFFFFULL)) { // only use pci if enabled and not using high bits
@@ -113,6 +117,10 @@ int umr_write_reg(struct umr_asic *asic, uint64_t addr, uint32_t value, enum reg
if (addr == 0xFFFFFFFF)
fprintf(stderr, "[BUG]: reading from addr==0xFFFFFFFF is likely a bug\n");
+ // lop off top bits in no-kernel mode
+ if (asic->options.no_kernel)
+ addr &= 0xFFFFFF;
+
switch (type) {
case REG_MMIO:
if (asic->pci.mem && !(addr & ~0xFFFFFULL)) {
--
2.12.0
More information about the amd-gfx
mailing list