]> Git Repo - qemu.git/commitdiff
qom: fix objects with improper parent type
authorPaolo Bonzini <[email protected]>
Wed, 7 Oct 2020 16:23:56 +0000 (12:23 -0400)
committerPaolo Bonzini <[email protected]>
Mon, 12 Oct 2020 15:50:22 +0000 (11:50 -0400)
Some objects accidentally inherit ObjectClass instead of Object.
They compile silently but may crash after downcasting.

In this patch, we introduce a coccinelle script to find broken
declarations and fix them manually with proper base type.

Signed-off-by: Sergey Nizovtsev <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
MAINTAINERS
include/hw/acpi/vmgenid.h
include/hw/misc/vmcoreinfo.h
include/net/can_host.h
scripts/coccinelle/qom-parent-type.cocci [new file with mode: 0644]

index 7ef459a33c7e4ec2ba55d923332f6c7792f410ed..fcb2c03c2bd9e7572f65e78dec61165307263551 100644 (file)
@@ -2462,6 +2462,7 @@ F: include/monitor/qdev.h
 F: include/qom/
 F: qapi/qom.json
 F: qapi/qdev.json
+F: scripts/coccinelle/qom-parent-type.cocci
 F: softmmu/qdev-monitor.c
 F: qom/
 F: tests/check-qom-interface.c
index d50fbacb8e12a39de3979bdbd85c8a0fcf07ade2..cb4ad37fc5b35f08f9b261443a28878b46fbfb23 100644 (file)
@@ -19,7 +19,7 @@
 OBJECT_DECLARE_SIMPLE_TYPE(VmGenIdState, VMGENID)
 
 struct VmGenIdState {
-    DeviceClass parent_obj;
+    DeviceState parent_obj;
     QemuUUID guid;                /* The 128-bit GUID seen by the guest */
     uint8_t vmgenid_addr_le[8];   /* Address of the GUID (little-endian) */
 };
index ebada6617a76714fce894a31eebcd4189645d8be..0b7b55d400a009c535eb8887526efd9f7c58260e 100644 (file)
@@ -24,7 +24,7 @@ DECLARE_INSTANCE_CHECKER(VMCoreInfoState, VMCOREINFO,
 typedef struct fw_cfg_vmcoreinfo FWCfgVMCoreInfo;
 
 struct VMCoreInfoState {
-    DeviceClass parent_obj;
+    DeviceState parent_obj;
 
     bool has_vmcoreinfo;
     FWCfgVMCoreInfo vmcoreinfo;
index 4e3ce3f9541f27ccf5716ecf0bc3f7beab5d421c..caab71bdda8bb3365b84423e19ec915523344079 100644 (file)
@@ -35,7 +35,7 @@
 OBJECT_DECLARE_TYPE(CanHostState, CanHostClass, CAN_HOST)
 
 struct CanHostState {
-    ObjectClass oc;
+    Object oc;
 
     CanBusState *bus;
     CanBusClientState bus_client;
diff --git a/scripts/coccinelle/qom-parent-type.cocci b/scripts/coccinelle/qom-parent-type.cocci
new file mode 100644 (file)
index 0000000..9afb3ed
--- /dev/null
@@ -0,0 +1,26 @@
+// Highlight object declarations that don't look like object class but
+// accidentally inherit from it.
+
+@match@
+identifier obj_t, fld;
+type parent_t =~ ".*Class$";
+@@
+struct obj_t {
+    parent_t fld;
+    ...
+};
+
+@script:python filter depends on match@
+obj_t << match.obj_t;
+@@
+is_class_obj = obj_t.endswith('Class')
+cocci.include_match(not is_class_obj)
+
+@replacement depends on filter@
+identifier match.obj_t, match.fld;
+type match.parent_t;
+@@
+struct obj_t {
+*   parent_t fld;
+    ...
+};
This page took 0.051854 seconds and 4 git commands to generate.