Skip to contentSkip to conversation

pc-dimm: use same mechanism for [get|set]_addr

PATCH Superseded Wei Yang 3 participants 4 messages Feb 1, 2019 – Feb 7, 2019

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Wei Yang

author
#0 lore raw

PATCH 1/1 pc-dimm: use same mechanism for [get|set]_addr

[get|set]_addr are two counterpart to access PCDIMMDevice.addr.

Since we have already set up a property PC_DIMM_ADDR_PROP for this field and use this mechanism in set_addr, it would be more proper to use the same mechanism in set_addr.

This patch uses object_property_get_uint() to replace the direct memory access to make [get|set]_addr with the same mechanism.

---
 hw/mem/pc-dimm.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
hw/mem/pc-dimm.c +1 -3
index 0c9b9e8292..c0658b9b88 100644
@@ -204,9 +204,7 @@ static MemoryRegion *pc_dimm_get_memory_region(PCDIMMDevice *dimm, Error **errp)
 
 static uint64_t pc_dimm_md_get_addr(const MemoryDeviceState *md)
 {
-    const PCDIMMDevice *dimm = PC_DIMM(md);
-
-    return dimm->addr;
+    return object_property_get_uint(OBJECT(md), PC_DIMM_ADDR_PROP, NULL);
 }
 
 static void pc_dimm_md_set_addr(MemoryDeviceState *md, uint64_t addr,
Signature · 1 line
2.19.1
#1 lore raw
Quoted 19 lines · On Fri, 1 Feb 2019 09:08:37 +0800 Wei Yang <[email protected]>…

[get|set]_addr are two counterpart to access PCDIMMDevice.addr.

Since we have already set up a property PC_DIMM_ADDR_PROP for this field and use this mechanism in set_addr, it would be more proper to use the same mechanism in set_addr.

This patch uses object_property_get_uint() to replace the direct memory access to make [get|set]_addr with the same mechanism.

---
 hw/mem/pc-dimm.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
hw/mem/pc-dimm.c +0 -0
index 0c9b9e8292..c0658b9b88 100644

hw/mem/pc-dimm.c static MemoryRegion *pc_dimm_get_memory_region(PCDIMMDevice *dimm, Error **errp) · line 207

Quoted 7 lines
hw/mem/pc-dimm.c +1 -3
@@ -204,9 +204,7 @@ static MemoryRegion *pc_dimm_get_memory_region(PCDIMMDevice *dimm, Error **errp)
 
 static uint64_t pc_dimm_md_get_addr(const MemoryDeviceState *md)
 {
-    const PCDIMMDevice *dimm = PC_DIMM(md);
-
-    return dimm->addr;
+    return object_property_get_uint(OBJECT(md), PC_DIMM_ADDR_PROP, NULL);

it's not good to ignore errors

s/NULL/error_abort/

so we would notice if error ever happened.

Quoted 3 lines
hw/mem/pc-dimm.c +0 -0
 }
 
 static void pc_dimm_md_set_addr(MemoryDeviceState *md, uint64_t addr,
#2 lore raw
Quoted 31 lines · Igor Mammedov
Quoted 19 lines · On Fri, 1 Feb 2019 09:08:37 +0800 Wei Yang <[email protected]>…

[get|set]_addr are two counterpart to access PCDIMMDevice.addr.

Since we have already set up a property PC_DIMM_ADDR_PROP for this field and use this mechanism in set_addr, it would be more proper to use the same mechanism in set_addr.

This patch uses object_property_get_uint() to replace the direct memory access to make [get|set]_addr with the same mechanism.

---
 hw/mem/pc-dimm.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
hw/mem/pc-dimm.c +0 -0
index 0c9b9e8292..c0658b9b88 100644

hw/mem/pc-dimm.c static MemoryRegion *pc_dimm_get_memory_region(PCDIMMDevice *dimm, Error **errp) · line 207

Quoted 7 lines
hw/mem/pc-dimm.c +1 -3
@@ -204,9 +204,7 @@ static MemoryRegion *pc_dimm_get_memory_region(PCDIMMDevice *dimm, Error **errp)
 
 static uint64_t pc_dimm_md_get_addr(const MemoryDeviceState *md)
 {
-    const PCDIMMDevice *dimm = PC_DIMM(md);
-
-    return dimm->addr;
+    return object_property_get_uint(OBJECT(md), PC_DIMM_ADDR_PROP, NULL);

it's not good to ignore errors

Quoted 3 lines

s/NULL/error_abort/

so we would notice if error ever happened.

You mean something like this?

	Error *err;
	uint64_t addr;

	addr = object_property_get_uint(OBJECT(md), PC_DIMM_ADDR_PROP, &err);

	if (err) {
		warn_report_err(&err);
		return 0;
	}

	return addr;
Quoted 5 lines
Quoted 4 lines
hw/mem/pc-dimm.c +0 -0
 }
 
 static void pc_dimm_md_set_addr(MemoryDeviceState *md, uint64_t addr,
Signature · 2 lines
Wei Yang
Help you, Help me
#3 lore raw
Quoted 34 lines · On Wed, 6 Feb 2019 23:55:15 +0000 Wei Yang <[email protected]> wrote:
Quoted 33 lines · Igor Mammedov
Quoted 19 lines · On Fri, 1 Feb 2019 09:08:37 +0800 Wei Yang <[email protected]>…

[get|set]_addr are two counterpart to access PCDIMMDevice.addr.

Since we have already set up a property PC_DIMM_ADDR_PROP for this field and use this mechanism in set_addr, it would be more proper to use the same mechanism in set_addr.

This patch uses object_property_get_uint() to replace the direct memory access to make [get|set]_addr with the same mechanism.

---
 hw/mem/pc-dimm.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
hw/mem/pc-dimm.c +0 -0
index 0c9b9e8292..c0658b9b88 100644

hw/mem/pc-dimm.c static MemoryRegion *pc_dimm_get_memory_region(PCDIMMDevice *dimm, Error **errp) · line 207

Quoted 7 lines
hw/mem/pc-dimm.c +1 -3
@@ -204,9 +204,7 @@ static MemoryRegion *pc_dimm_get_memory_region(PCDIMMDevice *dimm, Error **errp)
 
 static uint64_t pc_dimm_md_get_addr(const MemoryDeviceState *md)
 {
-    const PCDIMMDevice *dimm = PC_DIMM(md);
-
-    return dimm->addr;
+    return object_property_get_uint(OBJECT(md), PC_DIMM_ADDR_PROP, NULL);

it's not good to ignore errors

s/NULL/error_abort/

Quoted 8 lines
Quoted 1 line

so we would notice if error ever happened.

You mean something like this?

	Error *err;
	uint64_t addr;

	addr = object_property_get_uint(OBJECT(md), PC_DIMM_ADDR_PROP, &err);

see how error_abort is used in QEMU,
point is if there is a error that should never happen it is programming error so QEMU should crash and we should fix it.

Quoted 14 lines
	if (err) {
		warn_report_err(&err);
		return 0;
	}

	return addr;
Quoted 5 lines
Quoted 4 lines
hw/mem/pc-dimm.c +0 -0
 }
 
 static void pc_dimm_md_set_addr(MemoryDeviceState *md, uint64_t addr,