From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51070) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VhFhz-00025z-1i for qemu-devel@nongnu.org; Fri, 15 Nov 2013 04:29:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VhFhu-0005f1-B7 for qemu-devel@nongnu.org; Fri, 15 Nov 2013 04:28:58 -0500 Received: from mx1.redhat.com ([209.132.183.28]:22030) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VhFhu-0005eq-2q for qemu-devel@nongnu.org; Fri, 15 Nov 2013 04:28:54 -0500 From: Markus Armbruster References: <201311151701366579617@cn.fujitsu.com> Date: Fri, 15 Nov 2013 10:28:40 +0100 In-Reply-To: <201311151701366579617@cn.fujitsu.com> (Zhou Yuan's message of "Fri, 15 Nov 2013 17:01:38 +0800") Message-ID: <87k3gaggjb.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH] hw/i2c/core.c: add the id property of i2c_slaver when created in the QEMUMachine's initialization List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Zhou Yuan Cc: qemu-devel "Zhou Yuan" writes: > From: zhouy > Date: Fri, 15 Nov 2013 15:50:52 -0500 > Subject: [PATCH] add the id property of i2c_slaver when created in the > QEMUMachine's initialization > > Signed-off-by: zhouy > --- > qemu-master/hw/i2c/core.c | 8 +++++++- > 1 files changed, 7 insertions(+), 1 deletions(-) > > diff --git a/qemu-master/hw/i2c/core.c b/qemu-master/hw/i2c/core.c > index c97e7f7..ea3e59d 100644 > --- a/qemu-master/hw/i2c/core.c > +++ b/qemu-master/hw/i2c/core.c > @@ -213,10 +213,16 @@ static int i2c_slave_qdev_init(DeviceState *dev) > DeviceState *i2c_create_slave(i2c_bus *bus, const char *name, uint8_t addr) > { > DeviceState *dev; > - > + static unsigned int seq_num; > + char *id = g_malloc0(20); > + snprintf(id, 20, "%s-%d", name, seq_num); > dev = qdev_create(&bus->qbus, name); > qdev_prop_set_uint8(dev, "address", addr); > + dev->id = id; > + object_property_add_child(container_get(qdev_get_machine(), "/peripheral"), > + dev->id, OBJECT(dev), NULL); > qdev_init_nofail(dev); > + seq_num++; > return dev; > } Why is this needed? In general, property "id" / DeviceState member id is strictly for the user, and should never be set automatically. Exceptions exist in convenience options, mostly for historical reasons.