Blame SOURCES/kvm-qobject-Ensure-base-is-at-offset-0.patch

1bdc94
From 94cd049b8c81e2b58113db7cc289218f8925d27d Mon Sep 17 00:00:00 2001
1bdc94
From: Markus Armbruster <armbru@redhat.com>
1bdc94
Date: Mon, 18 Jun 2018 08:43:09 +0200
1bdc94
Subject: [PATCH 02/54] qobject: Ensure base is at offset 0
1bdc94
MIME-Version: 1.0
1bdc94
Content-Type: text/plain; charset=UTF-8
1bdc94
Content-Transfer-Encoding: 8bit
1bdc94
1bdc94
RH-Author: Markus Armbruster <armbru@redhat.com>
1bdc94
Message-id: <20180618084330.30009-3-armbru@redhat.com>
1bdc94
Patchwork-id: 80724
1bdc94
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH 02/23] qobject: Ensure base is at offset 0
1bdc94
Bugzilla: 1557995
1bdc94
RH-Acked-by: Max Reitz <mreitz@redhat.com>
1bdc94
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
1bdc94
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
1bdc94
1bdc94
From: Marc-André Lureau <marcandre.lureau@redhat.com>
1bdc94
1bdc94
All QObject types have the base QObject as their first field. This
1bdc94
allows the simplification of qobject_to().
1bdc94
1bdc94
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
1bdc94
Reviewed-by: Eric Blake <eblake@redhat.com>
1bdc94
Message-Id: <20180419150145.24795-2-marcandre.lureau@redhat.com>
1bdc94
Reviewed-by: Markus Armbruster <armbru@redhat.com>
1bdc94
[Commit message paragraph on type casts dropped, to avoid giving the
1bdc94
impression type casting would be okay]
1bdc94
Signed-off-by: Markus Armbruster <armbru@redhat.com>
1bdc94
(cherry picked from commit 7ee9edfdb117da47c86c9764d90f0be11a648666)
1bdc94
1bdc94
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
1bdc94
---
1bdc94
 include/qapi/qmp/qobject.h | 5 ++---
1bdc94
 qobject/qobject.c          | 9 +++++++++
1bdc94
 2 files changed, 11 insertions(+), 3 deletions(-)
1bdc94
1bdc94
diff --git a/include/qapi/qmp/qobject.h b/include/qapi/qmp/qobject.h
1bdc94
index e022707..5206ff9 100644
1bdc94
--- a/include/qapi/qmp/qobject.h
1bdc94
+++ b/include/qapi/qmp/qobject.h
1bdc94
@@ -61,9 +61,8 @@ struct QObject {
1bdc94
 QEMU_BUILD_BUG_MSG(QTYPE__MAX != 7,
1bdc94
                    "The QTYPE_CAST_TO_* list needs to be extended");
1bdc94
 
1bdc94
-#define qobject_to(type, obj) ({ \
1bdc94
-    QObject *_tmp = qobject_check_type(obj, glue(QTYPE_CAST_TO_, type)); \
1bdc94
-    _tmp ? container_of(_tmp, type, base) : (type *)NULL; })
1bdc94
+#define qobject_to(type, obj)                                       \
1bdc94
+    ((type *)qobject_check_type(obj, glue(QTYPE_CAST_TO_, type)))
1bdc94
 
1bdc94
 /* Initialize an object to default values */
1bdc94
 static inline void qobject_init(QObject *obj, QType type)
1bdc94
diff --git a/qobject/qobject.c b/qobject/qobject.c
1bdc94
index 23600aa..87649c5 100644
1bdc94
--- a/qobject/qobject.c
1bdc94
+++ b/qobject/qobject.c
1bdc94
@@ -16,6 +16,15 @@
1bdc94
 #include "qapi/qmp/qlist.h"
1bdc94
 #include "qapi/qmp/qstring.h"
1bdc94
 
1bdc94
+QEMU_BUILD_BUG_MSG(
1bdc94
+    offsetof(QNull, base) != 0 ||
1bdc94
+    offsetof(QNum, base) != 0 ||
1bdc94
+    offsetof(QString, base) != 0 ||
1bdc94
+    offsetof(QDict, base) != 0 ||
1bdc94
+    offsetof(QList, base) != 0 ||
1bdc94
+    offsetof(QBool, base) != 0,
1bdc94
+    "base qobject must be at offset 0");
1bdc94
+
1bdc94
 static void (*qdestroy[QTYPE__MAX])(QObject *) = {
1bdc94
     [QTYPE_NONE] = NULL,               /* No such object exists */
1bdc94
     [QTYPE_QNULL] = NULL,              /* qnull_ is indestructible */
1bdc94
-- 
1bdc94
1.8.3.1
1bdc94