Skip to contentSkip to conversation

hw/riscv/sifive_e: Fix inheritance of SiFiveEState

PATCH Applied Bernhard Beschow 3 participants 3 messages Sep 22, 2022 – Sep 23, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/riscv/sifive_e: Fix inheritance of SiFiveEState

SiFiveEState inherits from SysBusDevice while it's TypeInfo claims it to inherit from TYPE_MACHINE. This is an inconsistency which can cause undefined behavior such as memory corruption.

Change SiFiveEState to inherit from MachineState since it is registered as a machine.

Fixes 0869490b1c ("riscv: sifive_e: Manually define the machine")
---
 include/hw/riscv/sifive_e.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/hw/riscv/sifive_e.h +2 -1
index 83604da805..d738745925 100644
@@ -22,6 +22,7 @@
 #include "hw/riscv/riscv_hart.h"
 #include "hw/riscv/sifive_cpu.h"
 #include "hw/gpio/sifive_gpio.h"
+#include "hw/boards.h"
 
 #define TYPE_RISCV_E_SOC "riscv.sifive.e.soc"
 #define RISCV_E_SOC(obj) \
@@ -41,7 +42,7 @@ typedef struct SiFiveESoCState {
 
 typedef struct SiFiveEState {
     /*< private >*/
-    SysBusDevice parent_obj;
+    MachineState parent_obj;
 
     /*< public >*/
     SiFiveESoCState soc;
Signature · 1 line
2.37.3
#1 lore raw

Hi Bernhard,

I think there's already a similar patch for this bug fix:
https://www.mail-archive.com/[email protected]/msg905424.html

Regards,
Frank Chang

Quoted 42 lines · Bernhard Beschow

SiFiveEState inherits from SysBusDevice while it's TypeInfo claims it to inherit from TYPE_MACHINE. This is an inconsistency which can cause undefined behavior such as memory corruption.

Change SiFiveEState to inherit from MachineState since it is registered as a machine.

Fixes 0869490b1c ("riscv: sifive_e: Manually define the machine")
---
 include/hw/riscv/sifive_e.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/hw/riscv/sifive_e.h +2 -2
index 83604da805..d738745925 100644
@@ -22,6 +22,7 @@
 #include "hw/riscv/riscv_hart.h"
 #include "hw/riscv/sifive_cpu.h"
 #include "hw/gpio/sifive_gpio.h"
+#include "hw/boards.h"
 
 #define TYPE_RISCV_E_SOC "riscv.sifive.e.soc"
 #define RISCV_E_SOC(obj) \
@@ -41,7 +42,7 @@ typedef struct SiFiveESoCState {
 
 typedef struct SiFiveEState {
     /*< private >*/
-    SysBusDevice parent_obj;
+    MachineState parent_obj;
 
     /*< public >*/
     SiFiveESoCState soc;
--

2.37.3

#2 lore raw
In reply to Bernhard Beschow
Quoted 5 lines · Bernhard Beschow

SiFiveEState inherits from SysBusDevice while it's TypeInfo claims it to inherit from TYPE_MACHINE. This is an inconsistency which can cause undefined behavior such as memory corruption.

Quoted 8 lines

Change SiFiveEState to inherit from MachineState since it is registered as a machine.

Fixes 0869490b1c ("riscv: sifive_e: Manually define the machine")

Thanks!

Applied to riscv-to-apply.next

Alistair

Quoted 29 lines
---
 include/hw/riscv/sifive_e.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
include/hw/riscv/sifive_e.h +2 -2
index 83604da805..d738745925 100644
@@ -22,6 +22,7 @@
 #include "hw/riscv/riscv_hart.h"
 #include "hw/riscv/sifive_cpu.h"
 #include "hw/gpio/sifive_gpio.h"
+#include "hw/boards.h"
 
 #define TYPE_RISCV_E_SOC "riscv.sifive.e.soc"
 #define RISCV_E_SOC(obj) \
@@ -41,7 +42,7 @@ typedef struct SiFiveESoCState {
 
 typedef struct SiFiveEState {
     /*< private >*/
-    SysBusDevice parent_obj;
+    MachineState parent_obj;
 
     /*< public >*/
     SiFiveESoCState soc;
--

2.37.3