From: Eduardo Habkost <ehabkost@redhat.com>
To: qemu-devel@nongnu.org, Peter Maydell <peter.maydell@linaro.org>
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Marcel Apfelbaum <marcel@redhat.com>
Subject: [Qemu-devel] [PULL 1/2] qdev: Use GList for global properties
Date: Thu, 16 Jun 2016 14:06:17 -0300 [thread overview]
Message-ID: <1466096778-13248-2-git-send-email-ehabkost@redhat.com> (raw)
In-Reply-To: <1466096778-13248-1-git-send-email-ehabkost@redhat.com>
If the same GlobalProperty struct is registered twice, the list
entry gets corrupted, making tqe_next points to itself, and
qdev_prop_set_globals() gets stuck in a loop. The bug can be
easily reproduced by running:
$ qemu-system-x86_64 -rtc-td-hack -rtc-td-hack
Change global_props to use GList instead of queue.h, making the
code simpler and able to deal with properties being registered
twice.
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
hw/core/qdev-properties.c | 15 ++++++++-------
include/hw/qdev-core.h | 1 -
2 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
index 737d29c..e3b2184 100644
--- a/hw/core/qdev-properties.c
+++ b/hw/core/qdev-properties.c
@@ -1020,12 +1020,11 @@ void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value)
*ptr = value;
}
-static QTAILQ_HEAD(, GlobalProperty) global_props =
- QTAILQ_HEAD_INITIALIZER(global_props);
+static GList *global_props;
void qdev_prop_register_global(GlobalProperty *prop)
{
- QTAILQ_INSERT_TAIL(&global_props, prop, next);
+ global_props = g_list_append(global_props, prop);
}
void qdev_prop_register_global_list(GlobalProperty *props)
@@ -1039,10 +1038,11 @@ void qdev_prop_register_global_list(GlobalProperty *props)
int qdev_prop_check_globals(void)
{
- GlobalProperty *prop;
+ GList *l;
int ret = 0;
- QTAILQ_FOREACH(prop, &global_props, next) {
+ for (l = global_props; l; l = l->next) {
+ GlobalProperty *prop = l->data;
ObjectClass *oc;
DeviceClass *dc;
if (prop->used) {
@@ -1073,9 +1073,10 @@ int qdev_prop_check_globals(void)
static void qdev_prop_set_globals_for_type(DeviceState *dev,
const char *typename)
{
- GlobalProperty *prop;
+ GList *l;
- QTAILQ_FOREACH(prop, &global_props, next) {
+ for (l = global_props; l; l = l->next) {
+ GlobalProperty *prop = l->data;
Error *err = NULL;
if (strcmp(typename, prop->driver) != 0) {
diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h
index 1ce02b2..24aa0a7 100644
--- a/include/hw/qdev-core.h
+++ b/include/hw/qdev-core.h
@@ -266,7 +266,6 @@ typedef struct GlobalProperty {
const char *value;
bool user_provided;
bool used;
- QTAILQ_ENTRY(GlobalProperty) next;
} GlobalProperty;
/*** Board API. This should go away once we have a machine config file. ***/
--
2.5.5
next prev parent reply other threads:[~2016-06-16 17:06 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-16 17:06 [Qemu-devel] [PULL 0/2] Machine queue, 2016-06-16 Eduardo Habkost
2016-06-16 17:06 ` Eduardo Habkost [this message]
2016-06-16 17:06 ` [Qemu-devel] [PULL 2/2] vnc: Wrap vnc initialization code with CONFIG_VNC Eduardo Habkost
2016-06-17 10:19 ` [Qemu-devel] [PULL 0/2] Machine queue, 2016-06-16 Peter Maydell
2016-06-17 13:47 ` Eduardo Habkost
2016-06-17 15:16 ` Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1466096778-13248-2-git-send-email-ehabkost@redhat.com \
--to=ehabkost@redhat.com \
--cc=marcel@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).