From 2d0f3c4a304f7a1265fa5df1f54fb6a036d154d3 Mon Sep 17 00:00:00 2001 From: nuttxs Date: Fri, 21 Feb 2025 12:57:05 +0800 Subject: [PATCH] arch/esp32_himemcdev: Multiple instances of struct file for the same file share the f_inode, ensuring that the mapping status is associated with the file entity rather than a single descriptor. Avoid redundant mapping operations caused by multiple descriptors operating on the same file. Signed-off-by: nuttxs --- arch/xtensa/src/esp32/esp32_himem_chardev.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/arch/xtensa/src/esp32/esp32_himem_chardev.c b/arch/xtensa/src/esp32/esp32_himem_chardev.c index 0138b96d55de9..ea8dd3ece6320 100644 --- a/arch/xtensa/src/esp32/esp32_himem_chardev.c +++ b/arch/xtensa/src/esp32/esp32_himem_chardev.c @@ -62,7 +62,7 @@ static size_t g_ram_offset; /* used by himem map/unmap */ static void *g_himem_ptr; /* mapped himem pointer */ -static struct file *g_mapped_filep; /* for multi device */ +static struct inode *g_mapped_inode; /* for multi device */ /**************************************************************************** * Priavte Functions @@ -120,7 +120,8 @@ static int himem_chardev_read_write(int is_write, struct file *filep, length, dev->size); goto err; } - if ((mmap_offset != g_ram_offset) || (g_mapped_filep != filep)) + if ((mmap_offset != g_ram_offset) || \ + (g_mapped_inode != filep->f_inode)) { if (g_ram_offset != HIMEM_UNMAPPED) { @@ -134,7 +135,7 @@ static int himem_chardev_read_write(int is_write, struct file *filep, goto err; } g_ram_offset = HIMEM_UNMAPPED; - g_mapped_filep = NULL; + g_mapped_inode = NULL; } ret = esp_himem_map(dev->mem_handle, g_range_handle, mmap_offset * ESP_HIMEM_BLKSZ, @@ -145,7 +146,7 @@ static int himem_chardev_read_write(int is_write, struct file *filep, goto err; } g_ram_offset = mmap_offset; - g_mapped_filep = filep; + g_mapped_inode = filep->f_inode; } himem_ptr = g_himem_ptr + priv->offset % ESP_HIMEM_BLKSZ; copy_range = ESP_HIMEM_BLKSZ - priv->offset % ESP_HIMEM_BLKSZ; @@ -273,7 +274,7 @@ int himem_chardev_init(void) } g_ram_offset = HIMEM_UNMAPPED; - g_mapped_filep = NULL; + g_mapped_inode = NULL; return ret; } @@ -382,7 +383,7 @@ int himem_chardev_unregister(char *name) } g_ram_offset = HIMEM_UNMAPPED; - g_mapped_filep = NULL; + g_mapped_inode = NULL; } ret = esp_himem_free(dev->mem_handle);