From patchwork Wed Feb 8 11:13:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg KH X-Patchwork-Id: 54394 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp3393535wrn; Wed, 8 Feb 2023 03:16:00 -0800 (PST) X-Google-Smtp-Source: AK7set/jHxfmCcvo6kcFJJ74YB4y+kcqUtqOPnwZF7ZA7t9QVB/YL5pQmaz8eTMPoEGhO3D4FUO5 X-Received: by 2002:a17:906:1d2:b0:893:526b:c77b with SMTP id 18-20020a17090601d200b00893526bc77bmr7115438ejj.7.1675854960254; Wed, 08 Feb 2023 03:16:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675854960; cv=none; d=google.com; s=arc-20160816; b=oAVkERjc1FSe9Pmubl/rfwpFnoqkImil2hpNIdhOeMkzrUIgMyijiRBBxkspgV11Ve 2OiezGtW4Tjb6/+3jbPbuIJuNcOdD4mabvKFRRwV8V8KuDF/dk2vVGq15rYvTIKi+Jfk vxIoSYB9mra10D2Yn5xtgZpniYzB9BV9sS4D2+X/c8iJb+Rc8E3hFoKfEq6u+0ifTeVZ /8/43SSEm0MKQrxbagcU/W8n/sWbytw70mzr7N0rbXC7c7VS9T/G99vGFII97qmdqKQl o164f6AecsCxCd/5pWg9g7Iplm3qFw4kbXxU51o9R2QVZN61kMAhtTVNxbwESEMygh/a FtJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=sfhGZ7hNYQZAbyv2ugFjf6+QGM1zQQfDpjc0UIgUnYo=; b=i8tBmIgsNGI5CQHJuCyUVH2NMWsB5014deY6xRRxKqhh0ciUXXDRsGEH8KjEJ3s1r8 6CmtVXZJOLLtEFrFkns6h7ztl8Prxy6fAaa8vp/9fdtC5XTD0c4ElEPGFuG3SYHW3UtU j2miVrkt6YMfdNBR6Hm8mXm9AnHzHBnEH6SaoFcr1GPYjO4ZtmvIXJ0eFYE9XPzLMFxj cfNMEt84wKVfgkSDi/DWrjyqxQ6oQ/EbDCU2MxhnJotCTAl9aCl63RcOIznUdFbI2M6v O28xXmrJDLALvRNdkea+4Ha1M3VApSaNEYHdMa3U3Ss+2evBB0hLTfOAsNSG56cHKTCo zM9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dSjFDmhs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z23-20020a170906435700b0084cbde35b49si18589788ejm.990.2023.02.08.03.15.37; Wed, 08 Feb 2023 03:16:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=dSjFDmhs; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230347AbjBHLOL (ORCPT + 99 others); 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 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757261291039626947?= X-GMAIL-MSGID: =?utf-8?q?1757261291039626947?= 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 = bus_to_subsys(bus); struct klist_iter i; struct device *dev; int error = 0; - if (!bus || !bus->p) + if (!sp) return -EINVAL; - 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 = next_device(&i))) error = 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 = bus_to_subsys(bus); struct klist_iter i; struct device *dev; - if (!bus || !bus->p) + if (!sp) return NULL; - 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 = 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 *start, void *data, int (*fn)(struct device_driver *, void *)) { + struct subsys_private *sp = bus_to_subsys(bus); struct klist_iter i; struct device_driver *drv; int error = 0; - if (!bus) + if (!sp) return -EINVAL; - 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 = next_driver(&i)) && !error) error = fn(drv, data); klist_iter_exit(&i); + subsys_put(sp); return error; } EXPORT_SYMBOL_GPL(bus_for_each_drv);