This is an automated email from Gerrit.

"Steve Marple <stevemar...@googlemail.com>" just uploaded a new patch set to 
Gerrit, which you can find at https://review.openocd.org/c/openocd/+/7047

-- gerrit

commit 8d9e161d97612ef41afef843768fec3670c7e817
Author: Steve Marple <stevemar...@googlemail.com>
Date:   Wed Jun 22 15:43:51 2022 +0100

    drivers/am335xgpio: Release resources on error and when quitting
    
    The /dev/mem file descriptor can be closed without invalidating the
    mappings so close as soon as possible.
    
    munmap() all memory, either on error or from quit.
    
    Change-Id: I9466edd2f43791e64f2dce719957c67728f3ec06
    Signed-off-by: Steve Marple <stevemar...@googlemail.com>

diff --git a/src/jtag/drivers/am335xgpio.c b/src/jtag/drivers/am335xgpio.c
index 617784245f..a3bb438cbd 100644
--- a/src/jtag/drivers/am335xgpio.c
+++ b/src/jtag/drivers/am335xgpio.c
@@ -388,6 +388,13 @@ static bool am335xgpio_swd_mode_possible(void)
        return true;
 }
 
+static void am335xgpio_munmap(void)
+{
+       for (unsigned int i = 0; i < AM335XGPIO_NUM_GPIO_CHIPS && 
am335xgpio_gpio_chip_mmap_addr[i] != MAP_FAILED; ++i)
+               if (munmap((void *)am335xgpio_gpio_chip_mmap_addr[i], 
sysconf(_SC_PAGE_SIZE)) < 0)
+                       LOG_ERROR("Cannot unmap GPIO memory for chip %d: %s", 
i, strerror(errno));
+}
+
 static int am335xgpio_init(void)
 {
        LOG_INFO("AM335x GPIO JTAG/SWD bitbang driver");
@@ -421,10 +428,12 @@ static int am335xgpio_init(void)
 
                if (am335xgpio_gpio_chip_mmap_addr[i] == MAP_FAILED) {
                        LOG_ERROR("mmap: %s", strerror(errno));
+                       am335xgpio_munmap();
                        close(dev_mem_fd);
                        return ERROR_JTAG_INIT_FAILED;
                }
        }
+       close(dev_mem_fd);
 
        /* Configure JTAG/SWD signals. Default directions and initial states 
are handled
         * by adapter.c and "adapter gpio" command.
@@ -487,6 +496,8 @@ static int am335xgpio_quit(void)
        restore_gpio(ADAPTER_GPIO_IDX_SRST);
        restore_gpio(ADAPTER_GPIO_IDX_LED);
 
+       am335xgpio_munmap();
+
        return ERROR_OK;
 }
 

-- 

Reply via email to