diff options
author | Pali Rohár <pali@kernel.org> | 2023-05-18 21:34:49 +0200 |
---|---|---|
committer | Martin Mares <mj@ucw.cz> | 2023-12-29 14:30:02 +0100 |
commit | d4d889711556eaea294ca52a9a1d539a7d505d93 (patch) | |
tree | ea43fb504ef77db26da62c940e1d10646d982105 | |
parent | f2a77d0c820da6b8d7f9b425c96e4d2462900933 (diff) | |
download | pciutils-d4d889711556eaea294ca52a9a1d539a7d505d93.tar.gz |
libpci: ecam: Deduplicate get_bus_addr() code for calculating bus address
Move duplicate code block into helper function calculate_bus_addr().
-rw-r--r-- | lib/ecam.c | 34 |
1 files changed, 17 insertions, 17 deletions
@@ -619,6 +619,21 @@ validate_addrs(const char *addrs) } static int +calculate_bus_addr(u8 start_bus, off_t start_addr, u32 total_length, u8 bus, off_t *addr, u32 *length) +{ + u32 offset; + + offset = 32*8*4096 * (bus - start_bus); + if (offset >= total_length) + return 0; + + *addr = start_addr + offset; + *length = total_length - offset; + + return 1; +} + +static int get_bus_addr(struct acpi_mcfg *mcfg, const char *addrs, int domain, u8 bus, off_t *addr, u32 *length) { int cur_domain; @@ -626,7 +641,6 @@ get_bus_addr(struct acpi_mcfg *mcfg, const char *addrs, int domain, u8 bus, off_ u8 end_bus; off_t start_addr; u32 total_length; - u32 offset; int i, count; if (mcfg) @@ -636,14 +650,7 @@ get_bus_addr(struct acpi_mcfg *mcfg, const char *addrs, int domain, u8 bus, off_ { get_mcfg_allocation(mcfg, i, &cur_domain, &start_bus, &end_bus, &start_addr, &total_length); if (domain == cur_domain && bus >= start_bus && bus <= end_bus) - { - offset = 32*8*4096 * (bus - start_bus); - if (offset >= total_length) - return 0; - *addr = start_addr + offset; - *length = total_length - offset; - return 1; - } + return calculate_bus_addr(start_bus, start_addr, total_length, bus, addr, length); } return 0; } @@ -654,14 +661,7 @@ get_bus_addr(struct acpi_mcfg *mcfg, const char *addrs, int domain, u8 bus, off_ if (!parse_next_addrs(addrs, &addrs, &cur_domain, &start_bus, &end_bus, &start_addr, &total_length)) return 0; if (domain == cur_domain && bus >= start_bus && bus <= end_bus) - { - offset = 32*8*4096 * (bus - start_bus); - if (offset >= total_length) - return 0; - *addr = start_addr + offset; - *length = total_length - offset; - return 1; - } + return calculate_bus_addr(start_bus, start_addr, total_length, bus, addr, length); } return 0; } |