From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-arm@nongnu.org, qemu-devel@nongnu.org
Cc: patches@linaro.org,
Clement Deschamps <clement.deschamps@antfield.fr>,
Paolo Bonzini <pbonzini@redhat.com>
Subject: [Qemu-devel] [PATCH 1/4] qdev: Have qdev_set_parent_bus() handle devices already on a bus
Date: Tue, 28 Feb 2017 14:55:08 +0000 [thread overview]
Message-ID: <1488293711-14195-2-git-send-email-peter.maydell@linaro.org> (raw)
In-Reply-To: <1488293711-14195-1-git-send-email-peter.maydell@linaro.org>
Instead of qdev_set_parent_bus() silently doing the wrong
thing if it's handed a device that's already on a bus,
have it remove the device from the old bus and add it to
the new one. This is useful for the raspi2 sdcard.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
hw/core/qdev.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index 06ba02e..923e626 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -102,9 +102,23 @@ static void bus_add_child(BusState *bus, DeviceState *child)
void qdev_set_parent_bus(DeviceState *dev, BusState *bus)
{
+ bool replugging = dev->parent_bus != NULL;
+
+ if (replugging) {
+ /* Keep a reference to the device while it's not plugged into
+ * any bus, to avoid it potentially evaporating when it is
+ * dereffed in bus_remove_child().
+ */
+ object_ref(OBJECT(dev));
+ bus_remove_child(dev->parent_bus, dev);
+ object_unref(OBJECT(dev->parent_bus));
+ }
dev->parent_bus = bus;
object_ref(OBJECT(bus));
bus_add_child(bus, dev);
+ if (replugging) {
+ object_unref(OBJECT(dev));
+ }
}
/* Create a new device. This only initializes the device state
--
2.7.4
next prev parent reply other threads:[~2017-02-28 14:55 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-02-28 14:55 [Qemu-devel] [PATCH 0/4] handle reparenting of SD cards for rpi2 Peter Maydell
2017-02-28 14:55 ` Peter Maydell [this message]
2017-02-28 15:55 ` [Qemu-devel] [PATCH 1/4] qdev: Have qdev_set_parent_bus() handle devices already on a bus Igor Mammedov
2017-02-28 14:55 ` [Qemu-devel] [PATCH 2/4] hw/sd: add card-reparenting function Peter Maydell
2017-02-28 14:55 ` [Qemu-devel] [PATCH 3/4] bcm2835_gpio: add bcm2835 gpio controller Peter Maydell
2017-02-28 14:55 ` [Qemu-devel] [PATCH 4/4] bcm2835: add sdhost and gpio controllers Peter Maydell
2017-02-28 15:59 ` [Qemu-devel] [PATCH 0/4] handle reparenting of SD cards for rpi2 Paolo Bonzini
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=1488293711-14195-2-git-send-email-peter.maydell@linaro.org \
--to=peter.maydell@linaro.org \
--cc=clement.deschamps@antfield.fr \
--cc=patches@linaro.org \
--cc=pbonzini@redhat.com \
--cc=qemu-arm@nongnu.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).