Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists1p.gnu.org (lists1p.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id EFB55C43458 for ; Tue, 7 Jul 2026 09:18:56 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists1p.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1wh1x1-0000b7-8a; Tue, 07 Jul 2026 05:18:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists1p.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wh1wy-0000ZQ-Bk for qemu-arm@nongnu.org; Tue, 07 Jul 2026 05:18:44 -0400 Received: from smtp2-g21.free.fr ([212.27.42.2]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1wh1ww-00042l-UL for qemu-arm@nongnu.org; Tue, 07 Jul 2026 05:18:44 -0400 Received: from localhost (unknown [89.92.102.124]) (Authenticated sender: emmanuel.blot@free.fr) by smtp2-g21.free.fr (Postfix) with ESMTPSA id 856A52003C1; Tue, 7 Jul 2026 11:18:25 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=free.fr; s=smtp-20201208; t=1783415921; bh=TbsHXIpTGmI5+nMjMBIO4u9fckm7Tr64Y/vnv7oGexM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ae3eva53kivLkI9D9aKsycSt21OYklAhKxY5kXdJCDzE9AnmV/ir6IyEXJgCGctb4 qbdzqLifAsOXE1BqAPFMEg4KA7R/5Q4tNqBQGwmUyghWK0JNbznDsf8IPZn6MRXOwD 329j3LMvhzsyz4OOS44dPXnpL1soHYTLL6/Nw/nbLp7kgyYzHjQeqF2xHo+DTcfhJZ yKecDO0to34vvq69h0MmrM5MDwZWzPAuWVG/YA9fXYLAmF+DLLuTLPUw6S2i/DgxvM D7yxobMSpphtJHPvz5S9CGY6lT4nb2ot+T0ekskUn3XRMIVhuVQlcLiWEPTlEXcep3 Bb7fXWjOjJn+w== From: Emmanuel Blot To: Cc: Paolo Bonzini , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Fabiano Rosas , Laurent Vivier , Peter Maydell , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Steven Lee , Troy Lee , Jamin Lin , Kane Chen , Andrew Jeffery , Joel Stanley , Alexander Hansen , William de Abreu Pinho , Emmanuel Blot , qemu-arm@nongnu.org Subject: [PATCH v6 6/9] hw/i2c: parent slaves created with i2c_slave_create_simple Date: Tue, 7 Jul 2026 11:15:59 +0200 Message-ID: <20260707091609.97759-7-emmanuel.blot@free.fr> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260707091609.97759-1-emmanuel.blot@free.fr> References: <20260707091609.97759-1-emmanuel.blot@free.fr> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=212.27.42.2; envelope-from=emmanuel.blot@free.fr; helo=smtp2-g21.free.fr X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-arm@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-arm-bounces+qemu-arm=archiver.kernel.org@nongnu.org Sender: qemu-arm-bounces+qemu-arm=archiver.kernel.org@nongnu.org Slaves created with i2c_slave_create_simple() were left unparented and showed up under /machine/unattached with no stable QOM path. Add each slave as a QOM child of its bus, named after its I2C address, so it has a deterministic and addressable QOM path. Reviewed-by: Cédric Le Goater Signed-off-by: Emmanuel Blot --- hw/i2c/core.c | 3 +++ include/hw/i2c/i2c.h | 7 +++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/hw/i2c/core.c b/hw/i2c/core.c index 54f6bdca88..0bbce45d48 100644 --- a/hw/i2c/core.c +++ b/hw/i2c/core.c @@ -382,6 +382,9 @@ I2CSlave *i2c_slave_create_simple(I2CBus *bus, const char *name, uint8_t addr) { I2CSlave *dev = i2c_slave_new(name, addr); + g_autofree char *childname = g_strdup_printf("0x%02x", addr); + object_property_add_child(OBJECT(bus), childname, OBJECT(dev)); + i2c_slave_realize_and_unref(dev, bus, &error_abort); return dev; diff --git a/include/hw/i2c/i2c.h b/include/hw/i2c/i2c.h index dd5930f4b5..dc557bbf3f 100644 --- a/include/hw/i2c/i2c.h +++ b/include/hw/i2c/i2c.h @@ -166,13 +166,16 @@ bool i2c_scan_bus(I2CBus *bus, uint8_t address, bool broadcast, I2CSlave *i2c_slave_new(const char *name, uint8_t addr); /** - * Create and realize an I2C slave device on the heap. + * Create and realize an I2C slave device on the heap, add the device as a + * child of its parent bus. + * * @bus: I2C bus to put it on * @name: I2C slave device type name * @addr: I2C address of the slave when put on a bus * * Create the device state structure, initialize it, put it on the - * specified @bus, and drop the reference to it (the device is realized). + * specified @bus, parent it, and drop the reference to it (the device is + * realized). */ I2CSlave *i2c_slave_create_simple(I2CBus *bus, const char *name, uint8_t addr); -- 2.50.1