pc-dimm: use same mechanism for [get|set]_addr
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
@@ -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
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_PROPfor this field and use this mechanism inset_addr, it would be more proper to use the same mechanism inset_addr.This patch uses
object_property_get_uint()to replace the direct memory access to make [get|set]_addr with the same mechanism.Signed-off-by Wei Yang <[email protected]>--- hw/mem/pc-dimm.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)hw/mem/pc-dimm.c +0
-0
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,
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_PROPfor this field and use this mechanism inset_addr, it would be more proper to use the same mechanism inset_addr.This patch uses
object_property_get_uint()to replace the direct memory access to make [get|set]_addr with the same mechanism.Signed-off-by Wei Yang <[email protected]>--- hw/mem/pc-dimm.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)hw/mem/pc-dimm.c +0
-0hw/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
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_PROPfor this field and use this mechanism inset_addr, it would be more proper to use the same mechanism inset_addr.This patch uses
object_property_get_uint()to replace the direct memory access to make [get|set]_addr with the same mechanism.Signed-off-by Wei Yang <[email protected]>--- hw/mem/pc-dimm.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)hw/mem/pc-dimm.c +0
-0hw/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,