From d4fa85688d19faad548d46bc478d93089f8bfb0d Mon Sep 17 00:00:00 2001 From: joevt Date: Tue, 27 Feb 2024 02:56:18 -0800 Subject: [PATCH] atirage: Check both offset and size. When checking if a particular byte of a register is accessed, check both the starting position (offset) and ending position (offset + size) of the bytes being access. --- devices/video/atirage.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/devices/video/atirage.cpp b/devices/video/atirage.cpp index 714deee..0b382b6 100644 --- a/devices/video/atirage.cpp +++ b/devices/video/atirage.cpp @@ -221,7 +221,7 @@ uint32_t ATIRage::read_reg(uint32_t reg_offset, uint32_t size) { switch (reg_num) { case ATI_CLOCK_CNTL: - if ((offset + size - 1) >= 2) { + if (offset <= 2 && offset + size > 2) { uint8_t pll_addr = extract_bits(result, ATI_PLL_ADDR, ATI_PLL_ADDR_size); insert_bits(result, this->plls[pll_addr], ATI_PLL_DATA, ATI_PLL_DATA_size); } @@ -313,7 +313,7 @@ void ATIRage::write_reg(uint32_t reg_offset, uint32_t value, uint32_t size) { break; case ATI_GP_IO: new_value = value; - if (offset < 2 && (offset + size - 1) >= 1) { + if (offset <= 1 && offset + size > 1) { uint8_t gpio_levels = (new_value >> 8) & 0xFFU; gpio_levels = ((gpio_levels & 0x30) >> 3) | (gpio_levels & 1); uint8_t gpio_dirs = (new_value >> 24) & 0xFFU; @@ -325,7 +325,7 @@ void ATIRage::write_reg(uint32_t reg_offset, uint32_t value, uint32_t size) { break; case ATI_CLOCK_CNTL: new_value = value; - if ((offset + size - 1) >= 2 && bit_set(new_value, ATI_PLL_WR_EN)) { + if (offset <= 2 && offset + size > 2 && bit_set(new_value, ATI_PLL_WR_EN)) { uint8_t pll_addr = extract_bits(new_value, ATI_PLL_ADDR, ATI_PLL_ADDR_size); uint8_t pll_data = extract_bits(new_value, ATI_PLL_DATA, ATI_PLL_DATA_size); this->plls[pll_addr] = pll_data;