From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4C09E77F39 for ; Fri, 24 Apr 2026 16:03:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777046632; cv=none; b=kUjRY1AgMHr43p1s1cNlFc9LDEJ48FTc7gRr+8dSCFgHalZyIRe+3u8jEGrFZdiRIqQtuqd4E5FWMrC3QqMYKdgWrnchUGli2HPIgUUEyGfwwn7e9HD0Topt8gi3zp4TDj1CBj1fSKXYtO++nI28Z4j11IDW0inkh6mw7wpXy74= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777046632; c=relaxed/simple; bh=HgtVi8OJ+/vIrStnMhO7W57bp79LE5Df42vhHHfdxpc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rxeoooVqQUIynZXI+MPymBZCATLLeloAgkmsHspBvuhlk+9mPieluJJx/bD98cNVe6yPxitAI2Qm/GVmGEN5HPJuQOv99OluCyIqpIjFSJIBdyo4qKHCsv8roL2nDr5Oy9EtOpMHtxWtaFh5kD7cpPVSs3h7Wn3JJIkYGIfcPQM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=hEBhmvJT; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="hEBhmvJT" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F0621C2BCB6; Fri, 24 Apr 2026 16:03:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777046632; bh=HgtVi8OJ+/vIrStnMhO7W57bp79LE5Df42vhHHfdxpc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hEBhmvJTHXvQyJNp44YCnJZdKEP4UG5PFKRk75M19GsVhhMcH5E4nrHgVOPb+qeYD fzYCaz14564Tkrulxn2oOzAEYVzviqEDq7VkaTKGdh8tY5OFhps/ybTui0rPuqMFV2 fBCyWBDQU7SlJfJSADfgYHrtlQemdwnjq6FRePMVT7hakj4KqgPGI7Nz2qXFJYHk6Z FC4VKzDpsPiLPFhwUxLy3Ji4OFXIqJOaAbsboz+Vq/P7RZu+uqxRWr0/OVq7J4xDRi WBn2F7wFm9Se5/81BzPHPN+JBjpmxuyuiooRyAn61DFsAffY+8LqPiafGXxaQdKSrV Fbca3UoWcgPIw== Received: from johan by xi.lan with local (Exim 4.98.2) (envelope-from ) id 1wGJ0P-0000000BDJf-3JTr; Fri, 24 Apr 2026 18:03:49 +0200 From: Johan Hovold To: Geoff Levand , Madhavan Srinivasan , Michael Ellerman Cc: Nicholas Piggin , Christophe Leroy , Greg Kroah-Hartman , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Johan Hovold Subject: [PATCH v2 2/3] powerpc/pseries: switch to dynamic ibmebus root device Date: Fri, 24 Apr 2026 18:02:58 +0200 Message-ID: <20260424160259.2672722-3-johan@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260424160259.2672722-1-johan@kernel.org> References: <20260424160259.2672722-1-johan@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Driver core expects devices to be dynamically allocated and will, for example, complain loudly if a device that lacks a release function is ever freed. Use root_device_register() to allocate and register the root device instead of open coding using a static device. Also add the missing sanity check when registering ibmebus devices to avoid use-after-free if the bus failed to register (which would previously have triggered a bunch of use-after-free warnings). Signed-off-by: Johan Hovold --- arch/powerpc/platforms/pseries/ibmebus.c | 39 ++++++++++++++---------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/arch/powerpc/platforms/pseries/ibmebus.c b/arch/powerpc/platforms/pseries/ibmebus.c index cad2deb7e70d..f2064e0b975d 100644 --- a/arch/powerpc/platforms/pseries/ibmebus.c +++ b/arch/powerpc/platforms/pseries/ibmebus.c @@ -51,9 +51,7 @@ #include #include -static struct device ibmebus_bus_device = { /* fake "parent" device */ - .init_name = "ibmebus", -}; +static struct device *ibmebus_bus_device; /* fake "parent" device */ const struct bus_type ibmebus_bus_type; @@ -171,7 +169,10 @@ static int ibmebus_create_device(struct device_node *dn) struct platform_device *dev; int ret; - dev = of_device_alloc(dn, NULL, &ibmebus_bus_device); + if (!ibmebus_bus_device) + return -ENOENT; + + dev = of_device_alloc(dn, NULL, ibmebus_bus_device); if (!dev) return -ENOMEM; @@ -447,6 +448,7 @@ EXPORT_SYMBOL(ibmebus_bus_type); static int __init ibmebus_bus_init(void) { + struct device *root; int err; printk(KERN_INFO "IBM eBus Device Driver\n"); @@ -458,23 +460,28 @@ static int __init ibmebus_bus_init(void) return err; } - err = device_register(&ibmebus_bus_device); - if (err) { - printk(KERN_WARNING "%s: device_register returned %i\n", + root = root_device_register("ibmebus"); + if (IS_ERR(root)) { + err = PTR_ERR(root); + printk(KERN_WARNING "%s: root_device_register returned %i\n", __func__, err); - put_device(&ibmebus_bus_device); - bus_unregister(&ibmebus_bus_type); - - return err; + goto err_deregister_bus; } + ibmebus_bus_device = root; + err = ibmebus_create_devices(ibmebus_matches); - if (err) { - device_unregister(&ibmebus_bus_device); - bus_unregister(&ibmebus_bus_type); - return err; - } + if (err) + goto err_deregister_root; return 0; + +err_deregister_root: + ibmebus_bus_device = NULL; + root_device_unregister(root); +err_deregister_bus: + bus_unregister(&ibmebus_bus_type); + + return err; } machine_postcore_initcall(pseries, ibmebus_bus_init); -- 2.53.0