Seemed to be a better alternative than making flatview_for_each_range pass non-const
pointers.
Signed-off-by: Mohamed Mediouni <mohamed@unpredictable.fr>
---
include/system/memory.h | 14 +++++++-------
system/memory.c | 6 +++---
2 files changed, 10 insertions(+), 10 deletions(-)
diff --git a/include/system/memory.h b/include/system/memory.h
index 0562af3136..1a140ef203 100644
--- a/include/system/memory.h
+++ b/include/system/memory.h
@@ -1339,7 +1339,7 @@ void memory_region_init(MemoryRegion *mr,
*
* @mr: the #MemoryRegion
*/
-void memory_region_ref(MemoryRegion *mr);
+void memory_region_ref(const MemoryRegion *mr);
/**
* memory_region_unref: Remove 1 to a memory region's reference count
@@ -1765,7 +1765,7 @@ uint64_t memory_region_size(MemoryRegion *mr);
*
* @mr: the memory region being queried
*/
-static inline bool memory_region_is_ram(MemoryRegion *mr)
+static inline bool memory_region_is_ram(const MemoryRegion *mr)
{
return mr->ram;
}
@@ -1777,7 +1777,7 @@ static inline bool memory_region_is_ram(MemoryRegion *mr)
*
* @mr: the memory region being queried
*/
-bool memory_region_is_ram_device(MemoryRegion *mr);
+bool memory_region_is_ram_device(const MemoryRegion *mr);
/**
* memory_region_is_romd: check whether a memory region is in ROMD mode
@@ -1787,7 +1787,7 @@ bool memory_region_is_ram_device(MemoryRegion *mr);
*
* @mr: the memory region being queried
*/
-static inline bool memory_region_is_romd(MemoryRegion *mr)
+static inline bool memory_region_is_romd(const MemoryRegion *mr)
{
return mr->rom_device && mr->romd_mode;
}
@@ -2071,7 +2071,7 @@ MemoryRegion *memory_region_from_host(void *ptr, ram_addr_t *offset);
*
* @mr: the memory region being queried.
*/
-void *memory_region_get_ram_ptr(MemoryRegion *mr);
+void *memory_region_get_ram_ptr(const MemoryRegion *mr);
/* memory_region_ram_resize: Resize a RAM region.
*
@@ -2967,7 +2967,7 @@ void *qemu_map_ram_ptr(RAMBlock *ram_block, ram_addr_t addr);
int memory_access_size(MemoryRegion *mr, unsigned l, hwaddr addr);
bool prepare_mmio_access(MemoryRegion *mr);
-static inline bool memory_region_supports_direct_access(MemoryRegion *mr)
+static inline bool memory_region_supports_direct_access(const MemoryRegion *mr)
{
/* ROM DEVICE regions only allow direct access if in ROMD mode. */
if (memory_region_is_romd(mr)) {
@@ -2984,7 +2984,7 @@ static inline bool memory_region_supports_direct_access(MemoryRegion *mr)
return !memory_region_is_ram_device(mr);
}
-static inline bool memory_access_is_direct(MemoryRegion *mr, bool is_write,
+static inline bool memory_access_is_direct(const MemoryRegion *mr, bool is_write,
MemTxAttrs attrs)
{
if (!memory_region_supports_direct_access(mr)) {
diff --git a/system/memory.c b/system/memory.c
index c51d0798a8..eb515fbee4 100644
--- a/system/memory.c
+++ b/system/memory.c
@@ -1825,7 +1825,7 @@ Object *memory_region_owner(MemoryRegion *mr)
return obj->parent;
}
-void memory_region_ref(MemoryRegion *mr)
+void memory_region_ref(const MemoryRegion *mr)
{
/* MMIO callbacks most likely will access data that belongs
* to the owner, hence the need to ref/unref the owner whenever
@@ -1866,7 +1866,7 @@ const char *memory_region_name(const MemoryRegion *mr)
return mr->name;
}
-bool memory_region_is_ram_device(MemoryRegion *mr)
+bool memory_region_is_ram_device(const MemoryRegion *mr)
{
return mr->ram_device;
}
@@ -2415,7 +2415,7 @@ int memory_region_get_fd(MemoryRegion *mr)
return mr->ram_block->fd;
}
-void *memory_region_get_ram_ptr(MemoryRegion *mr)
+void *memory_region_get_ram_ptr(const MemoryRegion *mr)
{
uint64_t offset = 0;
--
2.50.1 (Apple Git-155)
On 2026/03/07 13:46, Mohamed Mediouni wrote:
> Seemed to be a better alternative than making flatview_for_each_range pass non-const
> pointers.
>
> Signed-off-by: Mohamed Mediouni <mohamed@unpredictable.fr>
> ---
> include/system/memory.h | 14 +++++++-------
> system/memory.c | 6 +++---
> 2 files changed, 10 insertions(+), 10 deletions(-)
>
> diff --git a/include/system/memory.h b/include/system/memory.h
> index 0562af3136..1a140ef203 100644
> --- a/include/system/memory.h
> +++ b/include/system/memory.h
> @@ -1339,7 +1339,7 @@ void memory_region_init(MemoryRegion *mr,
> *
> * @mr: the #MemoryRegion
> */
> -void memory_region_ref(MemoryRegion *mr);
> +void memory_region_ref(const MemoryRegion *mr);
I don't firmly oppose this, but I feel a bit uneasy about this change.
You are right that this should be const in principle: this function does
not modify mr in any way.
However, we can also consider the current implement as "abusing" the
const qualifier to express that we are not going to ref/unref. It is an
abuse, but I think it is practically makes sense.
Regards,
Akihiko Odaki
>
> /**
> * memory_region_unref: Remove 1 to a memory region's reference count
> @@ -1765,7 +1765,7 @@ uint64_t memory_region_size(MemoryRegion *mr);
> *
> * @mr: the memory region being queried
> */
> -static inline bool memory_region_is_ram(MemoryRegion *mr)
> +static inline bool memory_region_is_ram(const MemoryRegion *mr)
> {
> return mr->ram;
> }
> @@ -1777,7 +1777,7 @@ static inline bool memory_region_is_ram(MemoryRegion *mr)
> *
> * @mr: the memory region being queried
> */
> -bool memory_region_is_ram_device(MemoryRegion *mr);
> +bool memory_region_is_ram_device(const MemoryRegion *mr);
>
> /**
> * memory_region_is_romd: check whether a memory region is in ROMD mode
> @@ -1787,7 +1787,7 @@ bool memory_region_is_ram_device(MemoryRegion *mr);
> *
> * @mr: the memory region being queried
> */
> -static inline bool memory_region_is_romd(MemoryRegion *mr)
> +static inline bool memory_region_is_romd(const MemoryRegion *mr)
> {
> return mr->rom_device && mr->romd_mode;
> }
> @@ -2071,7 +2071,7 @@ MemoryRegion *memory_region_from_host(void *ptr, ram_addr_t *offset);
> *
> * @mr: the memory region being queried.
> */
> -void *memory_region_get_ram_ptr(MemoryRegion *mr);
> +void *memory_region_get_ram_ptr(const MemoryRegion *mr);
>
> /* memory_region_ram_resize: Resize a RAM region.
> *
> @@ -2967,7 +2967,7 @@ void *qemu_map_ram_ptr(RAMBlock *ram_block, ram_addr_t addr);
> int memory_access_size(MemoryRegion *mr, unsigned l, hwaddr addr);
> bool prepare_mmio_access(MemoryRegion *mr);
>
> -static inline bool memory_region_supports_direct_access(MemoryRegion *mr)
> +static inline bool memory_region_supports_direct_access(const MemoryRegion *mr)
> {
> /* ROM DEVICE regions only allow direct access if in ROMD mode. */
> if (memory_region_is_romd(mr)) {
> @@ -2984,7 +2984,7 @@ static inline bool memory_region_supports_direct_access(MemoryRegion *mr)
> return !memory_region_is_ram_device(mr);
> }
>
> -static inline bool memory_access_is_direct(MemoryRegion *mr, bool is_write,
> +static inline bool memory_access_is_direct(const MemoryRegion *mr, bool is_write,
> MemTxAttrs attrs)
> {
> if (!memory_region_supports_direct_access(mr)) {
> diff --git a/system/memory.c b/system/memory.c
> index c51d0798a8..eb515fbee4 100644
> --- a/system/memory.c
> +++ b/system/memory.c
> @@ -1825,7 +1825,7 @@ Object *memory_region_owner(MemoryRegion *mr)
> return obj->parent;
> }
>
> -void memory_region_ref(MemoryRegion *mr)
> +void memory_region_ref(const MemoryRegion *mr)
> {
> /* MMIO callbacks most likely will access data that belongs
> * to the owner, hence the need to ref/unref the owner whenever
> @@ -1866,7 +1866,7 @@ const char *memory_region_name(const MemoryRegion *mr)
> return mr->name;
> }
>
> -bool memory_region_is_ram_device(MemoryRegion *mr)
> +bool memory_region_is_ram_device(const MemoryRegion *mr)
> {
> return mr->ram_device;
> }
> @@ -2415,7 +2415,7 @@ int memory_region_get_fd(MemoryRegion *mr)
> return mr->ram_block->fd;
> }
>
> -void *memory_region_get_ram_ptr(MemoryRegion *mr)
> +void *memory_region_get_ram_ptr(const MemoryRegion *mr)
> {
> uint64_t offset = 0;
>
© 2016 - 2026 Red Hat, Inc.