From nobody Fri Sep 12 18:12:24 2025 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4230AC64EC5 for ; Wed, 8 Feb 2023 11:14:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230351AbjBHLOL (ORCPT ); Wed, 8 Feb 2023 06:14:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230396AbjBHLN5 (ORCPT ); Wed, 8 Feb 2023 06:13:57 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A89D241C2 for ; Wed, 8 Feb 2023 03:13:56 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 06D83B81D46 for ; Wed, 8 Feb 2023 11:13:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 22BADC433EF; Wed, 8 Feb 2023 11:13:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1675854833; bh=ychY1J5WSesr6sQtBQnxVfi2sV70iiUsiWGPmVif1VU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dSjFDmhsDRvMOxUhEZWiJFylPlTqVyX8IOgD+FhB9HC7NbIP0kYpCCK8OXTaYcj9v 8so4eeW/i66cxK0Lr4ecSPKX+Vl1kzb6/1tsaYaSWpGfTKuvW0xf5/Iwqpi4d3hPUA I3BY6GRgWmT8mP3V/9jxJg7TuibMZExeS76g64Dg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" Subject: [PATCH 12/21] driver core: bus: bus iterator cleanups Date: Wed, 8 Feb 2023 12:13:21 +0100 Message-Id: <20230208111330.439504-13-gregkh@linuxfoundation.org> X-Mailer: git-send-email 2.39.1 In-Reply-To: <20230208111330.439504-1-gregkh@linuxfoundation.org> References: <20230208111330.439504-1-gregkh@linuxfoundation.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2685; i=gregkh@linuxfoundation.org; h=from:subject; bh=ychY1J5WSesr6sQtBQnxVfi2sV70iiUsiWGPmVif1VU=; b=owGbwMvMwCRo6H6F97bub03G02pJDMmPm29Evz5zy2YWW5b2vfquX9KWs+NYsz7wcBxWYLK2dBX/ ULKrI5aFQZCJQVZMkeXLNp6j+ysOKXoZ2p6GmcPKBDKEgYtTACbiwsWwYHfaodlrHB8vZXz69fhmmw bJCO7D1xkWHOe6a7d2XcFsPs54Z6cdTb7WQfp1AA== X-Developer-Key: i=gregkh@linuxfoundation.org; a=openpgp; fpr=F4B60CC5BF78C2214A313DCB3147D40DDB2DFB29 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Convert the bus_for_each_dev(), bus_find_device, and bus_for_each_drv() functions to use bus_to_subsys() and not use the back-pointer to the private structure. Cc: "Rafael J. Wysocki" Signed-off-by: Greg Kroah-Hartman --- drivers/base/bus.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/drivers/base/bus.c b/drivers/base/bus.c index b594804c716d..c007524151d2 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -355,18 +355,20 @@ static struct device *next_device(struct klist_iter *= i) int bus_for_each_dev(const struct bus_type *bus, struct device *start, void *data, int (*fn)(struct device *, void *)) { + struct subsys_private *sp =3D bus_to_subsys(bus); struct klist_iter i; struct device *dev; int error =3D 0; =20 - if (!bus || !bus->p) + if (!sp) return -EINVAL; =20 - klist_iter_init_node(&bus->p->klist_devices, &i, + klist_iter_init_node(&sp->klist_devices, &i, (start ? &start->p->knode_bus : NULL)); while (!error && (dev =3D next_device(&i))) error =3D fn(dev, data); klist_iter_exit(&i); + subsys_put(sp); return error; } EXPORT_SYMBOL_GPL(bus_for_each_dev); @@ -390,18 +392,20 @@ struct device *bus_find_device(const struct bus_type = *bus, struct device *start, const void *data, int (*match)(struct device *dev, const void *data)) { + struct subsys_private *sp =3D bus_to_subsys(bus); struct klist_iter i; struct device *dev; =20 - if (!bus || !bus->p) + if (!sp) return NULL; =20 - klist_iter_init_node(&bus->p->klist_devices, &i, + klist_iter_init_node(&sp->klist_devices, &i, (start ? &start->p->knode_bus : NULL)); while ((dev =3D next_device(&i))) if (match(dev, data) && get_device(dev)) break; klist_iter_exit(&i); + subsys_put(sp); return dev; } EXPORT_SYMBOL_GPL(bus_find_device); @@ -440,18 +444,20 @@ static struct device_driver *next_driver(struct klist= _iter *i) int bus_for_each_drv(const struct bus_type *bus, struct device_driver *sta= rt, void *data, int (*fn)(struct device_driver *, void *)) { + struct subsys_private *sp =3D bus_to_subsys(bus); struct klist_iter i; struct device_driver *drv; int error =3D 0; =20 - if (!bus) + if (!sp) return -EINVAL; =20 - klist_iter_init_node(&bus->p->klist_drivers, &i, + klist_iter_init_node(&sp->klist_drivers, &i, start ? &start->p->knode_bus : NULL); while ((drv =3D next_driver(&i)) && !error) error =3D fn(drv, data); klist_iter_exit(&i); + subsys_put(sp); return error; } EXPORT_SYMBOL_GPL(bus_for_each_drv); --=20 2.39.1