From nobody Fri Sep 12 16:19:06 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 F0894C05027 for ; Wed, 8 Feb 2023 11:14:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230178AbjBHLOG (ORCPT ); Wed, 8 Feb 2023 06:14:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230362AbjBHLNx (ORCPT ); Wed, 8 Feb 2023 06:13:53 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F39B125BB8 for ; Wed, 8 Feb 2023 03:13:41 -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 98C97B81D46 for ; Wed, 8 Feb 2023 11:13:40 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B6C73C433EF; Wed, 8 Feb 2023 11:13:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1675854819; bh=sdzTtC9zNARFDh/vm8BmQmgIG2LMt8G7elj3RADg63I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T2/Zb3IkE1n5T63L4PSp9E+yQGx91uT0/EuqDAB+BqjvqWunfHa5lH5EhWIhm7tY7 v1tMhJkWc+7qP/mzEEZQTNz1yv8mxZQYSqwSZ/3XJmewMDGBRTjKlwvryR0VthJRlw J0Y7jvMsOI2yXSWPjlr2spyXA7ZElKXPV8IrXhac= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" Subject: [PATCH 01/21] driver core: add local subsys_get and subsys_put functions Date: Wed, 8 Feb 2023 12:13:10 +0100 Message-Id: <20230208111330.439504-2-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=1087; i=gregkh@linuxfoundation.org; h=from:subject; bh=sdzTtC9zNARFDh/vm8BmQmgIG2LMt8G7elj3RADg63I=; b=owGbwMvMwCRo6H6F97bub03G02pJDMmPm6/W90/+8qVyl26taqRiwt/2qNvma7ZKO2+SM22Z/OXv 2/n+HbEsDIJMDLJiiixftvEc3V9xSNHL0PY0zBxWJpAhDFycAjCRc1cZZrOc/+Oh8f2s5/WO0HqdKy x7fNPWfGNYcEnsrmLfBm7LeSvmJTbP+Hk082kQHwA= 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" We need to control the reference count of the subsys private structure instead of directly manipulating the kset reference count of it, so wrap that logic up in a subsys_get() and subsys_put() function to make it more obvious as to what is happening. Cc: "Rafael J. Wysocki" Signed-off-by: Greg Kroah-Hartman --- drivers/base/base.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/base/base.h b/drivers/base/base.h index 0e806f641079..9e06c18c7a64 100644 --- a/drivers/base/base.h +++ b/drivers/base/base.h @@ -57,6 +57,19 @@ struct subsys_private { }; #define to_subsys_private(obj) container_of_const(obj, struct subsys_priva= te, subsys.kobj) =20 +static inline struct subsys_private *subsys_get(struct subsys_private *sp) +{ + if (sp) + kset_get(&sp->subsys); + return sp; +} + +static inline void subsys_put(struct subsys_private *sp) +{ + if (sp) + kset_put(&sp->subsys); +} + struct driver_private { struct kobject kobj; struct klist klist_devices; --=20 2.39.1 From nobody Fri Sep 12 16:19:06 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 D3C2FC64EC6 for ; Wed, 8 Feb 2023 11:15:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229582AbjBHLPC (ORCPT ); Wed, 8 Feb 2023 06:15:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230389AbjBHLOU (ORCPT ); Wed, 8 Feb 2023 06:14:20 -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 5565525287 for ; Wed, 8 Feb 2023 03:14:19 -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 0DC58B81D46 for ; Wed, 8 Feb 2023 11:14:18 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 601A0C433EF; Wed, 8 Feb 2023 11:14:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1675854856; bh=w9Cbdmyoaf/JjLBQ3AYuTmJo0QBEtgY2/LDU7YMGqM0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VDO6knpCYdYAoJEPiZsetV8zbmyISrvcV1KILG9NVE1Ut82GnA+DFFpfiZqCiGSJ1 YCWhuJvETsoHsohDqHDXJWgNni9zoBEoV25vrSwFjRuKc/CSmN3p2rSZqahWCEKFNV 4Vdoi2BXRHSmQV/sM0ml0VIAKdZ+bHb9tXxFZYE0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" Subject: [PATCH 02/21] driver core: bus: implement bus_get/put() without the private pointer Date: Wed, 8 Feb 2023 12:13:11 +0100 Message-Id: <20230208111330.439504-3-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=3559; i=gregkh@linuxfoundation.org; h=from:subject; bh=w9Cbdmyoaf/JjLBQ3AYuTmJo0QBEtgY2/LDU7YMGqM0=; b=owGbwMvMwCRo6H6F97bub03G02pJDMmPm6/9nOOb+emMcd66ArG3Luu4nytyrk6//O7lg9tLZm+e kbzockcsC4MgE4OsmCLLl208R/dXHFL0MrQ9DTOHlQlkCAMXpwBMZNpXhgXtTGdfnEjZ9Va7V4mDS/ El14Jndi0MC/p+Z8vYB/p3O5SnedZ3N1+zfH7rGwA= 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" In the quest to make 'struct bus_type' constant and in read-only memory, we need to stop using the private pointer to the subsys_private structure. First step in doing this is to create a helper function that turns a 'struct bus_type' into 'struct subsys_private' called bus_to_subsys(). bus_to_subsys() walks the list of registered busses in the system and finds the matching one based on the pointer to the bus_type itself. As this is a short list, and this function is not on any fast path, it should not be noticable. Implement bus_get() and bus_put() using this new helper function. Cc: "Rafael J. Wysocki" Signed-off-by: Greg Kroah-Hartman --- drivers/base/bus.c | 61 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 8 deletions(-) diff --git a/drivers/base/bus.c b/drivers/base/bus.c index aa70b3a7d778..d346afa4645c 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -24,6 +24,9 @@ /* /sys/devices/system */ static struct kset *system_kset; =20 +/* /sys/bus */ +static struct kset *bus_kset; + #define to_bus_attr(_attr) container_of(_attr, struct bus_attribute, attr) =20 /* @@ -39,19 +42,63 @@ static struct kset *system_kset; static int __must_check bus_rescan_devices_helper(struct device *dev, void *data); =20 +/** + * bus_to_subsys - Turn a struct bus_type into a struct subsys_private + * + * @bus: pointer to the struct bus_type to look up + * + * The driver core internals needs to work on the subsys_private structure= , not + * the external struct bus_type pointer. This function walks the list of + * registered busses in the system and finds the matching one and returns = the + * internal struct subsys_private that relates to that bus. + * + * Note, the reference count of the return value is INCREMENTED if it is n= ot + * NULL. A call to subsys_put() must be done when finished with the point= er in + * order for it to be properly freed. + */ +static struct subsys_private *bus_to_subsys(const struct bus_type *bus) +{ + struct subsys_private *sp =3D NULL; + struct kobject *kobj; + + if (!bus) + return NULL; + + spin_lock(&bus_kset->list_lock); + + if (list_empty(&bus_kset->list)) + goto done; + + list_for_each_entry(kobj, &bus_kset->list, entry) { + struct kset *kset =3D container_of(kobj, struct kset, kobj); + + sp =3D container_of_const(kset, struct subsys_private, subsys); + if (sp->bus =3D=3D bus) + goto done; + } + sp =3D NULL; +done: + sp =3D subsys_get(sp); + spin_unlock(&bus_kset->list_lock); + return sp; +} + static struct bus_type *bus_get(struct bus_type *bus) { - if (bus) { - kset_get(&bus->p->subsys); + struct subsys_private *sp =3D bus_to_subsys(bus); + + if (sp) return bus; - } return NULL; } =20 -static void bus_put(struct bus_type *bus) +static void bus_put(const struct bus_type *bus) { - if (bus) - kset_put(&bus->p->subsys); + struct subsys_private *sp =3D bus_to_subsys(bus); + + /* two puts are required as the call to bus_to_subsys incremented it agai= n */ + subsys_put(sp); + subsys_put(sp); } =20 static ssize_t drv_attr_show(struct kobject *kobj, struct attribute *attr, @@ -177,8 +224,6 @@ static const struct kset_uevent_ops bus_uevent_ops =3D { .filter =3D bus_uevent_filter, }; =20 -static struct kset *bus_kset; - /* Manually detach a device from its associated driver. */ static ssize_t unbind_store(struct device_driver *drv, const char *buf, size_t count) --=20 2.39.1 From nobody Fri Sep 12 16:19:06 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 4B56AC636CC for ; Wed, 8 Feb 2023 11:15:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229728AbjBHLPL (ORCPT ); Wed, 8 Feb 2023 06:15:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230393AbjBHLO2 (ORCPT ); Wed, 8 Feb 2023 06:14:28 -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 4895D241C2 for ; Wed, 8 Feb 2023 03:14:27 -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 F0A55B81C6E for ; Wed, 8 Feb 2023 11:14:25 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5C963C433EF; Wed, 8 Feb 2023 11:14:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1675854864; bh=TOoBHRJOzCGVRVJMF+VNnmRGTtaa/I1PGR2BmvFohxQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IWzPXXYkxEU7IjiKwb3CX/jIiAIpbuFzGbwgc8dSKGaLmUqv+XqQBVW71YtDX6Uhw ynvkqAwqsz/O53/dOX7se79WltvCh7HJikeNULi3PmZwUSmAHxfO/QooX7EFnqkMOJ hOd2VWycIBPDAedbT1HDU1VtgzqVc+wWaTgEXXt4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" Subject: [PATCH 03/21] driver core: bus: constantify the bus_find_* functions Date: Wed, 8 Feb 2023 12:13:12 +0100 Message-Id: <20230208111330.439504-4-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=5718; i=gregkh@linuxfoundation.org; h=from:subject; bh=TOoBHRJOzCGVRVJMF+VNnmRGTtaa/I1PGR2BmvFohxQ=; b=owGbwMvMwCRo6H6F97bub03G02pJDMmPm69NOeolek3v2/csMc1bIh+rJ0kcVPhlKPfnZfH6Ty3u mSliHbEsDIJMDLJiiixftvEc3V9xSNHL0PY0zBxWJpAhDFycAjCRv7cY5pe9maZ+297zcvGNB2ytp6 6IBVzb3cowv/we74SDt9w39DR4zS6ySKx7KF1rAgA= 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" All of the bus find and iterator functions do not modify the struct bus_type passed to them, so mark them as constant to enforce this rule. Cc: "Rafael J. Wysocki" Signed-off-by: Greg Kroah-Hartman --- drivers/base/bus.c | 6 +++--- include/linux/device/bus.h | 20 ++++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/base/bus.c b/drivers/base/bus.c index d346afa4645c..7949302663f9 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -331,7 +331,7 @@ static struct device *next_device(struct klist_iter *i) * to retain this data, it should do so, and increment the reference * count in the supplied callback. */ -int bus_for_each_dev(struct bus_type *bus, struct device *start, +int bus_for_each_dev(const struct bus_type *bus, struct device *start, void *data, int (*fn)(struct device *, void *)) { struct klist_iter i; @@ -365,7 +365,7 @@ EXPORT_SYMBOL_GPL(bus_for_each_dev); * if it does. If the callback returns non-zero, this function will * return to the caller and not iterate over any more devices. */ -struct device *bus_find_device(struct bus_type *bus, +struct device *bus_find_device(const struct bus_type *bus, struct device *start, const void *data, int (*match)(struct device *dev, const void *data)) { @@ -416,7 +416,7 @@ static struct device_driver *next_driver(struct klist_i= ter *i) * in the callback. It must also be sure to increment the refcount * so it doesn't disappear before returning to the caller. */ -int bus_for_each_drv(struct bus_type *bus, struct device_driver *start, +int bus_for_each_drv(const struct bus_type *bus, struct device_driver *sta= rt, void *data, int (*fn)(struct device_driver *, void *)) { struct klist_iter i; diff --git a/include/linux/device/bus.h b/include/linux/device/bus.h index e3094db1e9fa..f0c8bf91b07a 100644 --- a/include/linux/device/bus.h +++ b/include/linux/device/bus.h @@ -149,9 +149,9 @@ int device_match_acpi_handle(struct device *dev, const = void *handle); int device_match_any(struct device *dev, const void *unused); =20 /* iterator helpers for buses */ -int bus_for_each_dev(struct bus_type *bus, struct device *start, void *dat= a, +int bus_for_each_dev(const struct bus_type *bus, struct device *start, voi= d *data, int (*fn)(struct device *dev, void *data)); -struct device *bus_find_device(struct bus_type *bus, struct device *start, +struct device *bus_find_device(const struct bus_type *bus, struct device *= start, const void *data, int (*match)(struct device *dev, const void *data)); /** @@ -161,7 +161,7 @@ struct device *bus_find_device(struct bus_type *bus, st= ruct device *start, * @start: Device to begin with * @name: name of the device to match */ -static inline struct device *bus_find_device_by_name(struct bus_type *bus, +static inline struct device *bus_find_device_by_name(const struct bus_type= *bus, struct device *start, const char *name) { @@ -175,7 +175,7 @@ static inline struct device *bus_find_device_by_name(st= ruct bus_type *bus, * @np: of_node of the device to match. */ static inline struct device * -bus_find_device_by_of_node(struct bus_type *bus, const struct device_node = *np) +bus_find_device_by_of_node(const struct bus_type *bus, const struct device= _node *np) { return bus_find_device(bus, NULL, np, device_match_of_node); } @@ -187,7 +187,7 @@ bus_find_device_by_of_node(struct bus_type *bus, const = struct device_node *np) * @fwnode: fwnode of the device to match. */ static inline struct device * -bus_find_device_by_fwnode(struct bus_type *bus, const struct fwnode_handle= *fwnode) +bus_find_device_by_fwnode(const struct bus_type *bus, const struct fwnode_= handle *fwnode) { return bus_find_device(bus, NULL, fwnode, device_match_fwnode); } @@ -198,7 +198,7 @@ bus_find_device_by_fwnode(struct bus_type *bus, const s= truct fwnode_handle *fwno * @bus: bus type * @devt: device type of the device to match. */ -static inline struct device *bus_find_device_by_devt(struct bus_type *bus, +static inline struct device *bus_find_device_by_devt(const struct bus_type= *bus, dev_t devt) { return bus_find_device(bus, NULL, &devt, device_match_devt); @@ -211,7 +211,7 @@ static inline struct device *bus_find_device_by_devt(st= ruct bus_type *bus, * @cur: device to begin the search with. */ static inline struct device * -bus_find_next_device(struct bus_type *bus,struct device *cur) +bus_find_next_device(const struct bus_type *bus,struct device *cur) { return bus_find_device(bus, cur, NULL, device_match_any); } @@ -226,19 +226,19 @@ struct acpi_device; * @adev: ACPI COMPANION device to match. */ static inline struct device * -bus_find_device_by_acpi_dev(struct bus_type *bus, const struct acpi_device= *adev) +bus_find_device_by_acpi_dev(const struct bus_type *bus, const struct acpi_= device *adev) { return bus_find_device(bus, NULL, adev, device_match_acpi_dev); } #else static inline struct device * -bus_find_device_by_acpi_dev(struct bus_type *bus, const void *adev) +bus_find_device_by_acpi_dev(const struct bus_type *bus, const void *adev) { return NULL; } #endif =20 -int bus_for_each_drv(struct bus_type *bus, struct device_driver *start, +int bus_for_each_drv(const struct bus_type *bus, struct device_driver *sta= rt, void *data, int (*fn)(struct device_driver *, void *)); void bus_sort_breadthfirst(struct bus_type *bus, int (*compare)(const struct device *a, --=20 2.39.1 From nobody Fri Sep 12 16:19:06 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 5E22DC636D7 for ; Wed, 8 Feb 2023 11:15:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230238AbjBHLPP (ORCPT ); Wed, 8 Feb 2023 06:15:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230396AbjBHLOa (ORCPT ); Wed, 8 Feb 2023 06:14:30 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E018E241C2 for ; Wed, 8 Feb 2023 03:14:29 -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 99662B81BA8 for ; Wed, 8 Feb 2023 11:14:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id EF0DEC433EF; Wed, 8 Feb 2023 11:14:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1675854867; bh=p5TTPOpWMWq5eEE+GU3lcGME3666+d2rAuul7YL7CAE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=zxvfNV5WPLQBgbzqn565uqsBJEha3bjIJ5kSEq+28IuUCP0JrWAIhot3mKdaAKJSP KJpOp1EwcJtemoqN5NAvNfdXal4jThM+crHRrpOt7CM8DNrs+RzR2NGCxPxP9we473 8tMTGcCS38FhWcKV7n8dW+AU1VDXJYtscfR2XvYE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" Subject: [PATCH 04/21] driver core: bus: convert bus_create/remove_file to be constant Date: Wed, 8 Feb 2023 12:13:13 +0100 Message-Id: <20230208111330.439504-5-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=2643; i=gregkh@linuxfoundation.org; h=from:subject; bh=p5TTPOpWMWq5eEE+GU3lcGME3666+d2rAuul7YL7CAE=; b=owGbwMvMwCRo6H6F97bub03G02pJDMmPm681v7OQLHOfuedP5eplAjdjXf+pxnafPv7tgaDCIuNS /ntmHbEsDIJMDLJiiixftvEc3V9xSNHL0PY0zBxWJpAhDFycAjARD0WGBY2J+16cZuhnmqX1l2068+ 7k8/+cdzEs2Je5X9BvT8nnq+tCU4oTfbi5t/TsAQA= 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" bus_create_file() and bus_remove_file() can be made to take a constant bus pointer, as it should not be modifying anything in the bus structure. Make this change and move the functions to use the internal subsys_get/put() logic as well, to prevent the use of the back-pointer in struct bus_type. Cc: "Rafael J. Wysocki" Signed-off-by: Greg Kroah-Hartman --- drivers/base/bus.c | 28 +++++++++++++++++----------- include/linux/device/bus.h | 5 ++--- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 7949302663f9..8debbe00b4ca 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -175,24 +175,30 @@ static const struct sysfs_ops bus_sysfs_ops =3D { .store =3D bus_attr_store, }; =20 -int bus_create_file(struct bus_type *bus, struct bus_attribute *attr) +int bus_create_file(const struct bus_type *bus, struct bus_attribute *attr) { + struct subsys_private *sp =3D bus_to_subsys(bus); int error; - if (bus_get(bus)) { - error =3D sysfs_create_file(&bus->p->subsys.kobj, &attr->attr); - bus_put(bus); - } else - error =3D -EINVAL; + + if (!sp) + return -EINVAL; + + error =3D sysfs_create_file(&sp->subsys.kobj, &attr->attr); + + subsys_put(sp); return error; } EXPORT_SYMBOL_GPL(bus_create_file); =20 -void bus_remove_file(struct bus_type *bus, struct bus_attribute *attr) +void bus_remove_file(const struct bus_type *bus, struct bus_attribute *att= r) { - if (bus_get(bus)) { - sysfs_remove_file(&bus->p->subsys.kobj, &attr->attr); - bus_put(bus); - } + struct subsys_private *sp =3D bus_to_subsys(bus); + + if (!sp) + return; + + sysfs_remove_file(&sp->subsys.kobj, &attr->attr); + subsys_put(sp); } EXPORT_SYMBOL_GPL(bus_remove_file); =20 diff --git a/include/linux/device/bus.h b/include/linux/device/bus.h index f0c8bf91b07a..f6537f5fc535 100644 --- a/include/linux/device/bus.h +++ b/include/linux/device/bus.h @@ -135,9 +135,8 @@ struct bus_attribute { #define BUS_ATTR_WO(_name) \ struct bus_attribute bus_attr_##_name =3D __ATTR_WO(_name) =20 -extern int __must_check bus_create_file(struct bus_type *, - struct bus_attribute *); -extern void bus_remove_file(struct bus_type *, struct bus_attribute *); +int __must_check bus_create_file(const struct bus_type *bus, struct bus_at= tribute *attr); +void bus_remove_file(const struct bus_type *bus, struct bus_attribute *att= r); =20 /* Generic device matching functions that all busses can use to match with= */ int device_match_name(struct device *dev, const void *name); --=20 2.39.1 From nobody Fri Sep 12 16:19:06 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 72BE0C636D6 for ; Wed, 8 Feb 2023 11:15:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230150AbjBHLPW (ORCPT ); Wed, 8 Feb 2023 06:15:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230397AbjBHLOb (ORCPT ); Wed, 8 Feb 2023 06:14:31 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E087425287 for ; Wed, 8 Feb 2023 03:14:30 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 7F0B76162D for ; Wed, 8 Feb 2023 11:14:30 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 90B16C433EF; Wed, 8 Feb 2023 11:14:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1675854869; bh=dwfsdtCQB9wF5zjMLcmqwTmUkhdi6CgIhDJfaECGFfY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yJmZWKqZc+wzwp3wqIbuHuCe5vAOlm66YuWNEFyLvjXLoZtrfzkO+TztC899j4IRw qK72rkKt6oeW4Ym3TJvGpBQ7SdMqm1Ab+SR4fhYMoUioH11B1duQEVqkrZgXg7pnQG bly1SV+lfaFDRn2RVax0J1/cH/CvdgGq+cyAYfbM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" Subject: [PATCH 05/21] driver core: bus: sysfs function cleanups Date: Wed, 8 Feb 2023 12:13:14 +0100 Message-Id: <20230208111330.439504-6-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=1967; i=gregkh@linuxfoundation.org; h=from:subject; bh=dwfsdtCQB9wF5zjMLcmqwTmUkhdi6CgIhDJfaECGFfY=; b=owGbwMvMwCRo6H6F97bub03G02pJDMmPm6/V3frZaXktJruDNf1+VE5udgZv4LZ/ws0t55L3qpwN PX6jI5aFQZCJQVZMkeXLNp6j+ysOKXoZ2p6GmcPKBDKEgYtTACYybQbDPEsZ0xpNrbo1//rLHD3v7/ Vv/XP8DMN8/40GWnMmL1p8WjW6/pfqFfvnQUyrAA== 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 drivers_autoprobe show/store and uevent sysfs callbacks 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 | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 8debbe00b4ca..f0d3ad41fd5e 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -277,16 +277,31 @@ static DRIVER_ATTR_IGNORE_LOCKDEP(bind, 0200, NULL, b= ind_store); =20 static ssize_t drivers_autoprobe_show(struct bus_type *bus, char *buf) { - return sysfs_emit(buf, "%d\n", bus->p->drivers_autoprobe); + struct subsys_private *sp =3D bus_to_subsys(bus); + int ret; + + if (!sp) + return -EINVAL; + + ret =3D sysfs_emit(buf, "%d\n", sp->drivers_autoprobe); + subsys_put(sp); + return ret; } =20 static ssize_t drivers_autoprobe_store(struct bus_type *bus, const char *buf, size_t count) { + struct subsys_private *sp =3D bus_to_subsys(bus); + + if (!sp) + return -EINVAL; + if (buf[0] =3D=3D '0') - bus->p->drivers_autoprobe =3D 0; + sp->drivers_autoprobe =3D 0; else - bus->p->drivers_autoprobe =3D 1; + sp->drivers_autoprobe =3D 1; + + subsys_put(sp); return count; } =20 @@ -769,10 +784,18 @@ static void klist_devices_put(struct klist_node *n) static ssize_t bus_uevent_store(struct bus_type *bus, const char *buf, size_t count) { - int rc; + struct subsys_private *sp =3D bus_to_subsys(bus); + int ret; =20 - rc =3D kobject_synth_uevent(&bus->p->subsys.kobj, buf, count); - return rc ? rc : count; + if (!sp) + return -EINVAL; + + ret =3D kobject_synth_uevent(&sp->subsys.kobj, buf, count); + subsys_put(sp); + + if (ret) + return ret; + return count; } /* * "open code" the old BUS_ATTR() macro here. We want to use BUS_ATTR_WO() --=20 2.39.1 From nobody Fri Sep 12 16:19:06 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 84A17C6379F for ; Wed, 8 Feb 2023 11:15:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230342AbjBHLP1 (ORCPT ); Wed, 8 Feb 2023 06:15:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230399AbjBHLOe (ORCPT ); Wed, 8 Feb 2023 06:14:34 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FC1125287 for ; Wed, 8 Feb 2023 03:14:33 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 1BFED61580 for ; Wed, 8 Feb 2023 11:14:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31EC7C433EF; Wed, 8 Feb 2023 11:14:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1675854872; bh=bOAbeWNZBH0+KrZBBH/F//OguII8S8sQl/vg+wkJb5k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pWtOCJN5TKrE+KJWWXOxMeNkpCTy2uQ+fmVyYVHS/kAJN2+pDmQrDlXfSO1KX3dvM luwLeIaNs1ZcNRFwHmBLNdMZyXJCLHsJphQF8bBoTclX4M7mn0XlbxMVQYnJpnv2FB YY/f1MmbR7TkmF+1BNN9h7GbrdMeD8KtwOgCO70E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" Subject: [PATCH 06/21] driver core: bus: bus_add/probe/remove_device() cleanups Date: Wed, 8 Feb 2023 12:13:15 +0100 Message-Id: <20230208111330.439504-7-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=4524; i=gregkh@linuxfoundation.org; h=from:subject; bh=bOAbeWNZBH0+KrZBBH/F//OguII8S8sQl/vg+wkJb5k=; b=owGbwMvMwCRo6H6F97bub03G02pJDMmPm6+lT5R4/kji7gp5/di3K3Vzjn2v/Oj9iO3sP8uOROmd kW80O2JZGASZGGTFFFm+bOM5ur/ikKKXoe1pmDmsTCBDGLg4BWAiHc8YFnQEb5kplBcbFuphv/53/7 nUG/qnmBjmWUcKmJt7PfNXdFqzIVS0TOHyX752AA== 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_add_device(), bus_probe_device(), and bus_remove_device() 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 | 87 ++++++++++++++++++++++++++++------------------ 1 file changed, 54 insertions(+), 33 deletions(-) diff --git a/drivers/base/bus.c b/drivers/base/bus.c index f0d3ad41fd5e..f4e4efd81b29 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -466,32 +466,46 @@ EXPORT_SYMBOL_GPL(bus_for_each_drv); */ int bus_add_device(struct device *dev) { - struct bus_type *bus =3D bus_get(dev->bus); - int error =3D 0; + struct subsys_private *sp =3D bus_to_subsys(dev->bus); + int error; =20 - if (bus) { - pr_debug("bus: '%s': add device %s\n", bus->name, dev_name(dev)); - error =3D device_add_groups(dev, bus->dev_groups); - if (error) - goto out_put; - error =3D sysfs_create_link(&bus->p->devices_kset->kobj, - &dev->kobj, dev_name(dev)); - if (error) - goto out_groups; - error =3D sysfs_create_link(&dev->kobj, - &dev->bus->p->subsys.kobj, "subsystem"); - if (error) - goto out_subsys; - klist_add_tail(&dev->p->knode_bus, &bus->p->klist_devices); + if (!sp) { + /* + * This is a normal operation for many devices that do not + * have a bus assigned to them, just say that all went + * well. + */ + return 0; } + + /* + * Reference in sp is now incremented and will be dropped when + * the device is removed from the bus + */ + + pr_debug("bus: '%s': add device %s\n", sp->bus->name, dev_name(dev)); + + error =3D device_add_groups(dev, sp->bus->dev_groups); + if (error) + goto out_put; + + error =3D sysfs_create_link(&sp->devices_kset->kobj, &dev->kobj, dev_name= (dev)); + if (error) + goto out_groups; + + error =3D sysfs_create_link(&dev->kobj, &sp->subsys.kobj, "subsystem"); + if (error) + goto out_subsys; + + klist_add_tail(&dev->p->knode_bus, &sp->klist_devices); return 0; =20 out_subsys: - sysfs_remove_link(&bus->p->devices_kset->kobj, dev_name(dev)); + sysfs_remove_link(&sp->devices_kset->kobj, dev_name(dev)); out_groups: - device_remove_groups(dev, bus->dev_groups); + device_remove_groups(dev, sp->bus->dev_groups); out_put: - bus_put(dev->bus); + subsys_put(sp); return error; } =20 @@ -503,20 +517,21 @@ int bus_add_device(struct device *dev) */ void bus_probe_device(struct device *dev) { - struct bus_type *bus =3D dev->bus; + struct subsys_private *sp =3D bus_to_subsys(dev->bus); struct subsys_interface *sif; =20 - if (!bus) + if (!sp) return; =20 - if (bus->p->drivers_autoprobe) + if (sp->drivers_autoprobe) device_initial_probe(dev); =20 - mutex_lock(&bus->p->mutex); - list_for_each_entry(sif, &bus->p->interfaces, node) + mutex_lock(&sp->mutex); + list_for_each_entry(sif, &sp->interfaces, node) if (sif->add_dev) sif->add_dev(dev, sif); - mutex_unlock(&bus->p->mutex); + mutex_unlock(&sp->mutex); + subsys_put(sp); } =20 /** @@ -531,21 +546,20 @@ void bus_probe_device(struct device *dev) */ void bus_remove_device(struct device *dev) { - struct bus_type *bus =3D dev->bus; + struct subsys_private *sp =3D bus_to_subsys(dev->bus); struct subsys_interface *sif; =20 - if (!bus) + if (!sp) return; =20 - mutex_lock(&bus->p->mutex); - list_for_each_entry(sif, &bus->p->interfaces, node) + mutex_lock(&sp->mutex); + list_for_each_entry(sif, &sp->interfaces, node) if (sif->remove_dev) sif->remove_dev(dev, sif); - mutex_unlock(&bus->p->mutex); + mutex_unlock(&sp->mutex); =20 sysfs_remove_link(&dev->kobj, "subsystem"); - sysfs_remove_link(&dev->bus->p->devices_kset->kobj, - dev_name(dev)); + sysfs_remove_link(&sp->devices_kset->kobj, dev_name(dev)); device_remove_groups(dev, dev->bus->dev_groups); if (klist_node_attached(&dev->p->knode_bus)) klist_del(&dev->p->knode_bus); @@ -553,7 +567,14 @@ void bus_remove_device(struct device *dev) pr_debug("bus: '%s': remove device %s\n", dev->bus->name, dev_name(dev)); device_release_driver(dev); - bus_put(dev->bus); + + /* + * Decrement the reference count twice, once for the bus_to_subsys() + * call in the start of this function, and the second one from the + * reference increment in bus_add_device() + */ + subsys_put(sp); + subsys_put(sp); } =20 static int __must_check add_bind_files(struct device_driver *drv) --=20 2.39.1 From nobody Fri Sep 12 16:19:06 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 95604C64EC6 for ; Wed, 8 Feb 2023 11:15:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230404AbjBHLPa (ORCPT ); Wed, 8 Feb 2023 06:15:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230025AbjBHLOo (ORCPT ); Wed, 8 Feb 2023 06:14:44 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB49529168 for ; Wed, 8 Feb 2023 03:14:38 -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 sin.source.kernel.org (Postfix) with ESMTPS id E4A8ACE200A for ; Wed, 8 Feb 2023 11:14:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BE356C433D2; Wed, 8 Feb 2023 11:14:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1675854875; bh=kLYTpgwUgcqgAgROchb8ltF/FmX41QTpwY3/jau5krQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I1hAZ8gYWnvg3WuhCq7o9zUMxxfqs1hGvBeisnhg444N7iYx0YwhtfskY2oUY4xp2 tt6Ldw1bVmk7EloGP+RwdB4wQmUssCqIDt+IB0ja32FSvmkoc6vV0YeEDIpPBYjLgV l4PieKCsVz5xSYWQ9l+coKlMgeJQ1z70jOB/fomQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" Subject: [PATCH 07/21] driver core: bus: bus_register/unregister() cleanups Date: Wed, 8 Feb 2023 12:13:16 +0100 Message-Id: <20230208111330.439504-8-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=4343; i=gregkh@linuxfoundation.org; h=from:subject; bh=kLYTpgwUgcqgAgROchb8ltF/FmX41QTpwY3/jau5krQ=; b=owGbwMvMwCRo6H6F97bub03G02pJDMmPm68vOM23MNcqs6Jtf+fb1pC6hOubTpY8WZIzaxvvlTlJ k+0PdsSyMAgyMciKKbJ82cZzdH/FIUUvQ9vTMHNYmUCGMHBxCsBEuNYxLOj/KjSF97nbO/85Ovcurl z1/sNuuQaGBTvWyG9ROWmXw27odjhypyHbjR+v/gAA 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_register() and bus_unregister() functions to use bus_to_subsys() and not use the back-pointer to the private structure. Because bus_add_groups() and bus_remove_groups() were only called in one place, remove those one-line-wrapper functions and call the real sysfs group function where it is needed instead, saving another layer of indirection. Cc: "Rafael J. Wysocki" Signed-off-by: Greg Kroah-Hartman --- drivers/base/bus.c | 54 ++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/drivers/base/bus.c b/drivers/base/bus.c index f4e4efd81b29..549e55dfbfda 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -774,18 +774,6 @@ int device_reprobe(struct device *dev) } EXPORT_SYMBOL_GPL(device_reprobe); =20 -static int bus_add_groups(struct bus_type *bus, - const struct attribute_group **groups) -{ - return sysfs_create_groups(&bus->p->subsys.kobj, groups); -} - -static void bus_remove_groups(struct bus_type *bus, - const struct attribute_group **groups) -{ - sysfs_remove_groups(&bus->p->subsys.kobj, groups); -} - static void klist_devices_get(struct klist_node *n) { struct device_private *dev_prv =3D to_device_private_bus(n); @@ -839,6 +827,7 @@ int bus_register(struct bus_type *bus) { int retval; struct subsys_private *priv; + struct kobject *bus_kobj; struct lock_class_key *key; =20 priv =3D kzalloc(sizeof(struct subsys_private), GFP_KERNEL); @@ -850,12 +839,13 @@ int bus_register(struct bus_type *bus) =20 BLOCKING_INIT_NOTIFIER_HEAD(&priv->bus_notifier); =20 - retval =3D kobject_set_name(&priv->subsys.kobj, "%s", bus->name); + bus_kobj =3D &priv->subsys.kobj; + retval =3D kobject_set_name(bus_kobj, "%s", bus->name); if (retval) goto out; =20 - priv->subsys.kobj.kset =3D bus_kset; - priv->subsys.kobj.ktype =3D &bus_ktype; + bus_kobj->kset =3D bus_kset; + bus_kobj->ktype =3D &bus_ktype; priv->drivers_autoprobe =3D 1; =20 retval =3D kset_register(&priv->subsys); @@ -866,15 +856,13 @@ int bus_register(struct bus_type *bus) if (retval) goto bus_uevent_fail; =20 - priv->devices_kset =3D kset_create_and_add("devices", NULL, - &priv->subsys.kobj); + priv->devices_kset =3D kset_create_and_add("devices", NULL, bus_kobj); if (!priv->devices_kset) { retval =3D -ENOMEM; goto bus_devices_fail; } =20 - priv->drivers_kset =3D kset_create_and_add("drivers", NULL, - &priv->subsys.kobj); + priv->drivers_kset =3D kset_create_and_add("drivers", NULL, bus_kobj); if (!priv->drivers_kset) { retval =3D -ENOMEM; goto bus_drivers_fail; @@ -891,7 +879,7 @@ int bus_register(struct bus_type *bus) if (retval) goto bus_probe_files_fail; =20 - retval =3D bus_add_groups(bus, bus->bus_groups); + retval =3D sysfs_create_groups(bus_kobj, bus->bus_groups); if (retval) goto bus_groups_fail; =20 @@ -901,15 +889,15 @@ int bus_register(struct bus_type *bus) bus_groups_fail: remove_probe_files(bus); bus_probe_files_fail: - kset_unregister(bus->p->drivers_kset); + kset_unregister(priv->drivers_kset); bus_drivers_fail: - kset_unregister(bus->p->devices_kset); + kset_unregister(priv->devices_kset); bus_devices_fail: bus_remove_file(bus, &bus_attr_uevent); bus_uevent_fail: - kset_unregister(&bus->p->subsys); + kset_unregister(&priv->subsys); out: - kfree(bus->p); + kfree(priv); bus->p =3D NULL; return retval; } @@ -924,15 +912,25 @@ EXPORT_SYMBOL_GPL(bus_register); */ void bus_unregister(struct bus_type *bus) { + struct subsys_private *sp =3D bus_to_subsys(bus); + struct kobject *bus_kobj; + + if (!sp) + return; + pr_debug("bus: '%s': unregistering\n", bus->name); if (bus->dev_root) device_unregister(bus->dev_root); - bus_remove_groups(bus, bus->bus_groups); + + bus_kobj =3D &sp->subsys.kobj; + sysfs_remove_groups(bus_kobj, bus->bus_groups); remove_probe_files(bus); - kset_unregister(bus->p->drivers_kset); - kset_unregister(bus->p->devices_kset); bus_remove_file(bus, &bus_attr_uevent); - kset_unregister(&bus->p->subsys); + + kset_unregister(sp->drivers_kset); + kset_unregister(sp->devices_kset); + kset_unregister(&sp->subsys); + subsys_put(sp); } EXPORT_SYMBOL_GPL(bus_unregister); =20 --=20 2.39.1 From nobody Fri Sep 12 16:19:06 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 B24BCC64EC5 for ; Wed, 8 Feb 2023 11:15:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230444AbjBHLPd (ORCPT ); Wed, 8 Feb 2023 06:15:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230451AbjBHLOs (ORCPT ); Wed, 8 Feb 2023 06:14:48 -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 93DFD303EB for ; Wed, 8 Feb 2023 03:14:40 -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 04676B81BA8 for ; Wed, 8 Feb 2023 11:14:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5B9A6C433D2; Wed, 8 Feb 2023 11:14:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1675854877; bh=STXBzYRIQwSf/bys2o0xrmcAJbSk00T8I4RBfKL6Zbo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=D/+lUkDZS9BnvFgRtMHh53lpSoh/LF/m65q1ZanJfF91f8ks3pLrH2mcmi5XqBxEY 8wBa4j5bZrlDaS9gAlv59+ZsHqTtfGRS4HtRG5IhhHbijLdWuPd33qi+OqjxqTor+r PhAypxQD/hcxq3KvbO2PvosWZVbRfCJbCDN3XXzc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" Subject: [PATCH 08/21] driver core: bus: subsys_interface_register/unregister() cleanups Date: Wed, 8 Feb 2023 12:13:17 +0100 Message-Id: <20230208111330.439504-9-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=3914; i=gregkh@linuxfoundation.org; h=from:subject; bh=STXBzYRIQwSf/bys2o0xrmcAJbSk00T8I4RBfKL6Zbo=; b=owGbwMvMwCRo6H6F97bub03G02pJDMmPm69/e/uvo3320WMf7+1pf3K50G6WgYls3LkZkna3b//6 +DphdkcsC4MgE4OsmCLLl208R/dXHFL0MrQ9DTOHlQlkCAMXpwBMRGohw4Jdu165tvP8YFbbH3P3bf GRrXdPRUUyzM/pCdLQ6I5mOni8mMv8oM4cgyUTswA= 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 subsys_interface_register and subsys_interface_unregister() functions to use bus_to_subsys() and not use the back-pointer to the private structure. This also requires changing the parameters on subsys_dev_iter_init() to iterate over the list properly. Cc: "Rafael J. Wysocki" Signed-off-by: Greg Kroah-Hartman --- drivers/base/bus.c | 45 +++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 549e55dfbfda..deed62509a62 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -1023,7 +1023,7 @@ struct subsys_dev_iter { /** * subsys_dev_iter_init - initialize subsys device iterator * @iter: subsys iterator to initialize - * @subsys: the subsys we wanna iterate over + * @sp: the subsys private (i.e. bus) we wanna iterate over * @start: the device to start iterating from, if any * @type: device_type of the devices to iterate over, NULL for all * @@ -1032,14 +1032,14 @@ struct subsys_dev_iter { * otherwise if it is NULL, the iteration starts at the beginning of * the list. */ -static void subsys_dev_iter_init(struct subsys_dev_iter *iter, struct bus_= type *subsys, +static void subsys_dev_iter_init(struct subsys_dev_iter *iter, struct subs= ys_private *sp, struct device *start, const struct device_type *type) { struct klist_node *start_knode =3D NULL; =20 if (start) start_knode =3D &start->p->knode_bus; - klist_iter_init_node(&subsys->p->klist_devices, &iter->ki, start_knode); + klist_iter_init_node(&sp->klist_devices, &iter->ki, start_knode); iter->type =3D type; } =20 @@ -1084,26 +1084,31 @@ static void subsys_dev_iter_exit(struct subsys_dev_= iter *iter) =20 int subsys_interface_register(struct subsys_interface *sif) { - struct bus_type *subsys; + struct subsys_private *sp; struct subsys_dev_iter iter; struct device *dev; =20 if (!sif || !sif->subsys) return -ENODEV; =20 - subsys =3D bus_get(sif->subsys); - if (!subsys) + sp =3D bus_to_subsys(sif->subsys); + if (!sp) return -EINVAL; =20 - mutex_lock(&subsys->p->mutex); - list_add_tail(&sif->node, &subsys->p->interfaces); + /* + * Reference in sp is now incremented and will be dropped when + * the interface is removed from the bus + */ + + mutex_lock(&sp->mutex); + list_add_tail(&sif->node, &sp->interfaces); if (sif->add_dev) { - subsys_dev_iter_init(&iter, subsys, NULL, NULL); + subsys_dev_iter_init(&iter, sp, NULL, NULL); while ((dev =3D subsys_dev_iter_next(&iter))) sif->add_dev(dev, sif); subsys_dev_iter_exit(&iter); } - mutex_unlock(&subsys->p->mutex); + mutex_unlock(&sp->mutex); =20 return 0; } @@ -1111,26 +1116,34 @@ EXPORT_SYMBOL_GPL(subsys_interface_register); =20 void subsys_interface_unregister(struct subsys_interface *sif) { - struct bus_type *subsys; + struct subsys_private *sp; struct subsys_dev_iter iter; struct device *dev; =20 if (!sif || !sif->subsys) return; =20 - subsys =3D sif->subsys; + sp =3D bus_to_subsys(sif->subsys); + if (!sp) + return; =20 - mutex_lock(&subsys->p->mutex); + mutex_lock(&sp->mutex); list_del_init(&sif->node); if (sif->remove_dev) { - subsys_dev_iter_init(&iter, subsys, NULL, NULL); + subsys_dev_iter_init(&iter, sp, NULL, NULL); while ((dev =3D subsys_dev_iter_next(&iter))) sif->remove_dev(dev, sif); subsys_dev_iter_exit(&iter); } - mutex_unlock(&subsys->p->mutex); + mutex_unlock(&sp->mutex); =20 - bus_put(subsys); + /* + * Decrement the reference count twice, once for the bus_to_subsys() + * call in the start of this function, and the second one from the + * reference increment in subsys_interface_register() + */ + subsys_put(sp); + subsys_put(sp); } EXPORT_SYMBOL_GPL(subsys_interface_unregister); =20 --=20 2.39.1 From nobody Fri Sep 12 16:19:06 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 C470EC64ED6 for ; Wed, 8 Feb 2023 11:15:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230476AbjBHLPe (ORCPT ); Wed, 8 Feb 2023 06:15:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231186AbjBHLO6 (ORCPT ); Wed, 8 Feb 2023 06:14:58 -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 0BD7D3669F for ; Wed, 8 Feb 2023 03:14:43 -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 B0103B81D4C for ; Wed, 8 Feb 2023 11:14:41 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 03748C433D2; Wed, 8 Feb 2023 11:14:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1675854880; bh=/Jfy0ZR86tMaNpwhqHvCr9+CtBj1NZD8CISYkm9vbio=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WjBx8BOvdpjGmXL6F0NX0feINLoBbn3tCD3u64ZH7dXqndFZTBFuxV1+ueA6/Jd2J PNb1ZUgouvQp9ch0a4LSJ8GwT55BpMvhtaM6X3n7lfA0ZEp379iYqaUWvgvBkeYCBe rEN6gCnM+nupIizpTWGjO8LmBkhtbodmgOqTNuQg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" Subject: [PATCH 09/21] driver core: bus: bus_get_kset() cleanup Date: Wed, 8 Feb 2023 12:13:18 +0100 Message-Id: <20230208111330.439504-10-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=875; i=gregkh@linuxfoundation.org; h=from:subject; bh=/Jfy0ZR86tMaNpwhqHvCr9+CtBj1NZD8CISYkm9vbio=; b=owGbwMvMwCRo6H6F97bub03G02pJDMmPm6+Hhv5XPJBlmHUrzOXrqpDCqsM9Nscvfryj8WL56m0G 0muCO2JZGASZGGTFFFm+bOM5ur/ikKKXoe1pmDmsTCBDGLg4BWAiXXUMC47eUcp5/fqZyGSVdwevOd 6fMyVR7hvDfN88jmWv5x2RZ7zAqH5eQKao7DlPOwA= 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_get_kset() function function 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 | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/base/bus.c b/drivers/base/bus.c index deed62509a62..90627c68d02b 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -956,7 +956,16 @@ void bus_notify(struct device *dev, enum bus_notifier_= event value) =20 struct kset *bus_get_kset(struct bus_type *bus) { - return &bus->p->subsys; + struct subsys_private *sp =3D bus_to_subsys(bus); + struct kset *kset; + + if (!sp) + return NULL; + + kset =3D &sp->subsys; + subsys_put(sp); + + return kset; } EXPORT_SYMBOL_GPL(bus_get_kset); =20 --=20 2.39.1 From nobody Fri Sep 12 16:19:06 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 202F9C636D7 for ; Wed, 8 Feb 2023 11:14:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230255AbjBHLOI (ORCPT ); Wed, 8 Feb 2023 06:14:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230368AbjBHLNy (ORCPT ); Wed, 8 Feb 2023 06:13:54 -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 018D1252A4 for ; Wed, 8 Feb 2023 03:13:49 -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 A83EAB81C6E for ; Wed, 8 Feb 2023 11:13:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 991A3C433EF; Wed, 8 Feb 2023 11:13:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1675854827; bh=cn5nHUc6lR7TQRKfGigfXa7oBZoUPrcprKiU8P3aMFs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=opPdyg+UFomBXvB6bMf4nHe1J/FNTBYbatakbLOabCVEFxgwDdCfnZCF6+iIwDQfr R/ZFq2Uep5ut7gx5An0AWTOnlWsuhTYUoxCXwiogTMpVfNhrwVuau977PU5pCSfyUR MP+B+MimUnMeDIkRxWd7M8a4BXtY99kaAMJBhyWg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" Subject: [PATCH 10/21] driver core: bus: bus_register/unregister_notifier() cleanups Date: Wed, 8 Feb 2023 12:13:19 +0100 Message-Id: <20230208111330.439504-11-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=1893; i=gregkh@linuxfoundation.org; h=from:subject; bh=cn5nHUc6lR7TQRKfGigfXa7oBZoUPrcprKiU8P3aMFs=; b=owGbwMvMwCRo6H6F97bub03G02pJDMmPm68zxU7NDt2zJsnreVJJreQyn0tv8rx+XFVxUa+um/vE e+aujlgWBkEmBlkxRZYv23iO7q84pOhlaHsaZg4rE8gQBi5OAZjIuo0M831jXu7/cpk/8iXHjp6/l3 5tPRPz8TbDgrW2N0M2ThO4peaUMD3ywS6vbDHxtQA= 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_register_notifier() and bus_unregister_notifier() public functions to use bus_to_subsys() and not use the back-pointer to the private structure as well as the bus_notify() function. Cc: "Rafael J. Wysocki" Signed-off-by: Greg Kroah-Hartman --- drivers/base/bus.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 90627c68d02b..f23c6f6306e2 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -936,22 +936,40 @@ EXPORT_SYMBOL_GPL(bus_unregister); =20 int bus_register_notifier(struct bus_type *bus, struct notifier_block *nb) { - return blocking_notifier_chain_register(&bus->p->bus_notifier, nb); + struct subsys_private *sp =3D bus_to_subsys(bus); + int retval; + + if (!sp) + return -EINVAL; + + retval =3D blocking_notifier_chain_register(&sp->bus_notifier, nb); + subsys_put(sp); + return retval; } EXPORT_SYMBOL_GPL(bus_register_notifier); =20 int bus_unregister_notifier(struct bus_type *bus, struct notifier_block *n= b) { - return blocking_notifier_chain_unregister(&bus->p->bus_notifier, nb); + struct subsys_private *sp =3D bus_to_subsys(bus); + int retval; + + if (!sp) + return -EINVAL; + retval =3D blocking_notifier_chain_unregister(&sp->bus_notifier, nb); + subsys_put(sp); + return retval; } EXPORT_SYMBOL_GPL(bus_unregister_notifier); =20 void bus_notify(struct device *dev, enum bus_notifier_event value) { - struct bus_type *bus =3D dev->bus; + struct subsys_private *sp =3D bus_to_subsys(dev->bus); =20 - if (bus) - blocking_notifier_call_chain(&bus->p->bus_notifier, value, dev); + if (!sp) + return; + + blocking_notifier_call_chain(&sp->bus_notifier, value, dev); + subsys_put(sp); } =20 struct kset *bus_get_kset(struct bus_type *bus) --=20 2.39.1 From nobody Fri Sep 12 16:19:06 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 319BEC636D6 for ; Wed, 8 Feb 2023 11:14:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230318AbjBHLOK (ORCPT ); Wed, 8 Feb 2023 06:14:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230376AbjBHLNz (ORCPT ); Wed, 8 Feb 2023 06:13:55 -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 4B84125B96 for ; Wed, 8 Feb 2023 03:13:53 -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 06840B81D49 for ; Wed, 8 Feb 2023 11:13:52 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 350EAC433EF; Wed, 8 Feb 2023 11:13:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1675854830; bh=IUemhhV+uquNHc+5QTYdLPOB48ArOdw5/SdNBdVRcS4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P5KEp92JhYFbCTCSKKEqaKsrvwd0ItkUCgsG/MB1yt3MeNG3SjSxDVkzvJ6eetZxb FQlBoVXuDmAFJsd5KjlCaDlADVC55WVs+PoGmnqsI58s1E3Yi2y3bw14eECDBK8Es1 bINuVOr3Wjz5ZzY44tUfMsHeCzZQjApq3h3nT4Xg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" Subject: [PATCH 11/21] driver core: bus: bus_add/remove_driver() cleanups Date: Wed, 8 Feb 2023 12:13:20 +0100 Message-Id: <20230208111330.439504-12-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=3455; i=gregkh@linuxfoundation.org; h=from:subject; bh=IUemhhV+uquNHc+5QTYdLPOB48ArOdw5/SdNBdVRcS4=; b=owGbwMvMwCRo6H6F97bub03G02pJDMmPm2+8r9cK1ZscbbHp/NKus8o/Lpdfvnhh4ldv79/vK54e 37OxsiOWhUGQiUFWTJHlyzaeo/srDil6GdqehpnDygQyhIGLUwAmIlDEsGDaxW+HzBkZD0dfOyb0mP 2Wocq2OYsZ5vBFbX9R9SHk4QTTFyeV+K7PSTTrsQEA 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_add_driver() and bus_remove_driver() 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 | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/drivers/base/bus.c b/drivers/base/bus.c index f23c6f6306e2..b594804c716d 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -636,15 +636,18 @@ static DRIVER_ATTR_WO(uevent); */ int bus_add_driver(struct device_driver *drv) { - struct bus_type *bus; + struct subsys_private *sp =3D bus_to_subsys(drv->bus); struct driver_private *priv; int error =3D 0; =20 - bus =3D bus_get(drv->bus); - if (!bus) + if (!sp) return -EINVAL; =20 - pr_debug("bus: '%s': add driver %s\n", bus->name, drv->name); + /* + * Reference in sp is now incremented and will be dropped when + * the driver is removed from the bus + */ + pr_debug("bus: '%s': add driver %s\n", sp->bus->name, drv->name); =20 priv =3D kzalloc(sizeof(*priv), GFP_KERNEL); if (!priv) { @@ -654,14 +657,14 @@ int bus_add_driver(struct device_driver *drv) klist_init(&priv->klist_devices, NULL, NULL); priv->driver =3D drv; drv->p =3D priv; - priv->kobj.kset =3D bus->p->drivers_kset; + priv->kobj.kset =3D sp->drivers_kset; error =3D kobject_init_and_add(&priv->kobj, &driver_ktype, NULL, "%s", drv->name); if (error) goto out_unregister; =20 - klist_add_tail(&priv->knode_bus, &bus->p->klist_drivers); - if (drv->bus->p->drivers_autoprobe) { + klist_add_tail(&priv->knode_bus, &sp->klist_drivers); + if (sp->drivers_autoprobe) { error =3D driver_attach(drv); if (error) goto out_del_list; @@ -673,7 +676,7 @@ int bus_add_driver(struct device_driver *drv) printk(KERN_ERR "%s: uevent attr (%s) failed\n", __func__, drv->name); } - error =3D driver_add_groups(drv, bus->drv_groups); + error =3D driver_add_groups(drv, sp->bus->drv_groups); if (error) { /* How the hell do we get out of this pickle? Give up */ printk(KERN_ERR "%s: driver_add_groups(%s) failed\n", @@ -698,7 +701,7 @@ int bus_add_driver(struct device_driver *drv) /* drv->p is freed in driver_release() */ drv->p =3D NULL; out_put_bus: - bus_put(bus); + subsys_put(sp); return error; } =20 @@ -712,19 +715,29 @@ int bus_add_driver(struct device_driver *drv) */ void bus_remove_driver(struct device_driver *drv) { - if (!drv->bus) + struct subsys_private *sp =3D bus_to_subsys(drv->bus); + + if (!sp) return; =20 + pr_debug("bus: '%s': remove driver %s\n", sp->bus->name, drv->name); + if (!drv->suppress_bind_attrs) remove_bind_files(drv); - driver_remove_groups(drv, drv->bus->drv_groups); + driver_remove_groups(drv, sp->bus->drv_groups); driver_remove_file(drv, &driver_attr_uevent); klist_remove(&drv->p->knode_bus); - pr_debug("bus: '%s': remove driver %s\n", drv->bus->name, drv->name); driver_detach(drv); module_remove_driver(drv); kobject_put(&drv->p->kobj); - bus_put(drv->bus); + + /* + * Decrement the reference count twice, once for the bus_to_subsys() + * call in the start of this function, and the second one from the + * reference increment in bus_add_driver() + */ + subsys_put(sp); + subsys_put(sp); } =20 /* Helper for bus_rescan_devices's iter */ --=20 2.39.1 From nobody Fri Sep 12 16:19:06 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 From nobody Fri Sep 12 16:19:06 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 53E9CC6379F for ; Wed, 8 Feb 2023 11:14:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230370AbjBHLON (ORCPT ); Wed, 8 Feb 2023 06:14:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230399AbjBHLN6 (ORCPT ); Wed, 8 Feb 2023 06:13:58 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C45A1252A4 for ; Wed, 8 Feb 2023 03:13:57 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 62A8761156 for ; Wed, 8 Feb 2023 11:13:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 702EFC433EF; Wed, 8 Feb 2023 11:13:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1675854836; bh=LMftmsNT9WQmQkGCTmoc3x+umeDLzNUWfcY25S5rOlg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h2d6QuMcOkG5vzLgxVR/9N9RylaIeEKl/bN/eHrBl06VNTyrpGx2kKaF4tYd2MMYJ /TbJkK1+bBiMBeHcswJpEeipw69067V6jx4KXiTDKrLIPqHVrNXIjXGA3DBEd5x+08 adzWUNZPoboBmRU0wv0J1OyFGsBOBo7qLJie62SA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" Subject: [PATCH 13/21] driver core: bus: clean up bus_sort_breadthfirst() Date: Wed, 8 Feb 2023 12:13:22 +0100 Message-Id: <20230208111330.439504-14-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=1797; i=gregkh@linuxfoundation.org; h=from:subject; bh=LMftmsNT9WQmQkGCTmoc3x+umeDLzNUWfcY25S5rOlg=; b=owGbwMvMwCRo6H6F97bub03G02pJDMmPm29sXFWgMVODe0+LS1yTXt7CmttzRZytevQa5LjW7TpU z3K1I5aFQZCJQVZMkeXLNp6j+ysOKXoZ2p6GmcPKBDKEgYtTACZSk82wYNbatgn/y1TnZhXUrwkqFN H39FQsZ5jNGnYmLmH7dt+L79c5X4sW+JA4W/wUAA== 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_sort_breadthfirst() function to use bus_to_subsys() and not use the back-pointer to the private structure. This also allows us to get rid of bus_get_device_klist() which was only being used by this one internal function. Cc: "Rafael J. Wysocki" Signed-off-by: Greg Kroah-Hartman --- drivers/base/bus.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/base/bus.c b/drivers/base/bus.c index c007524151d2..87e21aafe6e6 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -1006,11 +1006,6 @@ struct kset *bus_get_kset(struct bus_type *bus) } EXPORT_SYMBOL_GPL(bus_get_kset); =20 -static struct klist *bus_get_device_klist(struct bus_type *bus) -{ - return &bus->p->klist_devices; -} - /* * Yes, this forcibly breaks the klist abstraction temporarily. It * just wants to sort the klist, not change reference counts and @@ -1042,13 +1037,16 @@ void bus_sort_breadthfirst(struct bus_type *bus, int (*compare)(const struct device *a, const struct device *b)) { + struct subsys_private *sp =3D bus_to_subsys(bus); LIST_HEAD(sorted_devices); struct klist_node *n, *tmp; struct device_private *dev_prv; struct device *dev; struct klist *device_klist; =20 - device_klist =3D bus_get_device_klist(bus); + if (!sp) + return; + device_klist =3D &sp->klist_devices; =20 spin_lock(&device_klist->k_lock); list_for_each_entry_safe(n, tmp, &device_klist->k_list, n_node) { @@ -1058,6 +1056,7 @@ void bus_sort_breadthfirst(struct bus_type *bus, } list_splice(&sorted_devices, &device_klist->k_list); spin_unlock(&device_klist->k_lock); + subsys_put(sp); } EXPORT_SYMBOL_GPL(bus_sort_breadthfirst); =20 --=20 2.39.1 From nobody Fri Sep 12 16:19:06 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 6DDF7C636CC for ; Wed, 8 Feb 2023 11:15:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229648AbjBHLOj (ORCPT ); Wed, 8 Feb 2023 06:14:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229745AbjBHLOD (ORCPT ); Wed, 8 Feb 2023 06:14:03 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 688AE241C2 for ; Wed, 8 Feb 2023 03:14:02 -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 1FEA7B81BA8 for ; Wed, 8 Feb 2023 11:14:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 69FBEC433D2; Wed, 8 Feb 2023 11:13:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1675854839; bh=rwIGY1WYkAlAsKJ0FGrYBjNgl4bfna2Pv/jSrRTDqWA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VNvW8xAx+3A0fmXyJnO3GaUva2pjH6o9Nl5pKbiZTZfRdss+dHAMno+pXAeBGPWpi xAa8r14FT75p629t3rl6JTi6Qb+MwpGlntZqszJIenVwDPxBBhyxbqNSomyogBOJSY US8Vlux4ghXJHfY+8K1/TYq7MYE7wrYu6YjKC5xc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" Subject: [PATCH 14/21] driver core: move driver_find() to bus.c Date: Wed, 8 Feb 2023 12:13:23 +0100 Message-Id: <20230208111330.439504-15-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=2801; i=gregkh@linuxfoundation.org; h=from:subject; bh=rwIGY1WYkAlAsKJ0FGrYBjNgl4bfna2Pv/jSrRTDqWA=; b=owGbwMvMwCRo6H6F97bub03G02pJDMmPm28UVOjn3z6lGJ8nLv391RV2oz86TFVeH3KMNr+vMxL9 EjizI5aFQZCJQVZMkeXLNp6j+ysOKXoZ2p6GmcPKBDKEgYtTACbyZBLDgr5ymTtvJjR6WnRJhy0/GM fxaWXyOoZ5Rqt3OdxZ9V5f4RQD266QdIOG7657AQ== 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" This function really is a bus function, not a driver one, so move it from driver.c to bus.c so that we can clean up some internal bus logic easier. Cc: "Rafael J. Wysocki" Signed-off-by: Greg Kroah-Hartman --- drivers/base/bus.c | 27 +++++++++++++++++++++++++++ drivers/base/driver.c | 27 --------------------------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 87e21aafe6e6..727de4c36d59 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -1288,6 +1288,33 @@ int subsys_virtual_register(struct bus_type *subsys, } EXPORT_SYMBOL_GPL(subsys_virtual_register); =20 +/** + * driver_find - locate driver on a bus by its name. + * @name: name of the driver. + * @bus: bus to scan for the driver. + * + * Call kset_find_obj() to iterate over list of drivers on + * a bus to find driver by name. Return driver if found. + * + * This routine provides no locking to prevent the driver it returns + * from being unregistered or unloaded while the caller is using it. + * The caller is responsible for preventing this. + */ +struct device_driver *driver_find(const char *name, struct bus_type *bus) +{ + struct kobject *k =3D kset_find_obj(bus->p->drivers_kset, name); + struct driver_private *priv; + + if (k) { + /* Drop reference added by kset_find_obj() */ + kobject_put(k); + priv =3D to_driver(k); + return priv->driver; + } + return NULL; +} +EXPORT_SYMBOL_GPL(driver_find); + int __init buses_init(void) { bus_kset =3D kset_create_and_add("bus", &bus_uevent_ops, NULL); diff --git a/drivers/base/driver.c b/drivers/base/driver.c index 676b6275d5b5..aa5e5166a671 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c @@ -274,30 +274,3 @@ void driver_unregister(struct device_driver *drv) bus_remove_driver(drv); } EXPORT_SYMBOL_GPL(driver_unregister); - -/** - * driver_find - locate driver on a bus by its name. - * @name: name of the driver. - * @bus: bus to scan for the driver. - * - * Call kset_find_obj() to iterate over list of drivers on - * a bus to find driver by name. Return driver if found. - * - * This routine provides no locking to prevent the driver it returns - * from being unregistered or unloaded while the caller is using it. - * The caller is responsible for preventing this. - */ -struct device_driver *driver_find(const char *name, struct bus_type *bus) -{ - struct kobject *k =3D kset_find_obj(bus->p->drivers_kset, name); - struct driver_private *priv; - - if (k) { - /* Drop reference added by kset_find_obj() */ - kobject_put(k); - priv =3D to_driver(k); - return priv->driver; - } - return NULL; -} -EXPORT_SYMBOL_GPL(driver_find); --=20 2.39.1 From nobody Fri Sep 12 16:19:06 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 371C3C05027 for ; Wed, 8 Feb 2023 11:15:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229745AbjBHLOn (ORCPT ); Wed, 8 Feb 2023 06:14:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42050 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230196AbjBHLOG (ORCPT ); Wed, 8 Feb 2023 06:14:06 -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 741E2241C2 for ; Wed, 8 Feb 2023 03:14:05 -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 27EE7B81D46 for ; Wed, 8 Feb 2023 11:14:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7346EC433EF; Wed, 8 Feb 2023 11:14:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1675854842; bh=1mImGWOl1u7F0otEn6f4kIHAWLUXjPlgHYU4EGCoXk4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IK3TH3L/y3D6Bypj4TmyeSsp8/1KrmEHy0kKEtTBKkTgWIxoNUBpEtk7TsJrYGhP0 nQCmLmrBDHFWBUBDgav6gYDapZ+cCRtL2rJuiuozRd/6J83Njax7DAF/zk3dwDm7Cp YNlpAn0X0946xSruNtVVWOVE5e/fX8asQHVrS70s= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" Subject: [PATCH 15/21] driver core: bus: clean up driver_find() Date: Wed, 8 Feb 2023 12:13:24 +0100 Message-Id: <20230208111330.439504-16-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=1264; i=gregkh@linuxfoundation.org; h=from:subject; bh=1mImGWOl1u7F0otEn6f4kIHAWLUXjPlgHYU4EGCoXk4=; b=owGbwMvMwCRo6H6F97bub03G02pJDMmPm28I/ymI6ltkJLEx7u3c+92Bj1sDNNXEA9Q9tlS7NKiF H97TEcvCIMjEICumyPJlG8/R/RWHFL0MbU/DzGFlAhnCwMUpABOpeMuw4ESlRujkNddVvqWt03ny8J vP5vCiLwwLdtQftP1w+PzsGdy+bb+Np259xfYnAQA= 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 driver_find() function 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 | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 727de4c36d59..951d63c8e885 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -1302,16 +1302,23 @@ EXPORT_SYMBOL_GPL(subsys_virtual_register); */ struct device_driver *driver_find(const char *name, struct bus_type *bus) { - struct kobject *k =3D kset_find_obj(bus->p->drivers_kset, name); + struct subsys_private *sp =3D bus_to_subsys(bus); + struct kobject *k; struct driver_private *priv; =20 - if (k) { - /* Drop reference added by kset_find_obj() */ - kobject_put(k); - priv =3D to_driver(k); - return priv->driver; - } - return NULL; + if (!sp) + return NULL; + + k =3D kset_find_obj(sp->drivers_kset, name); + subsys_put(sp); + if (!k) + return NULL; + + priv =3D to_driver(k); + + /* Drop reference added by kset_find_obj() */ + kobject_put(k); + return priv->driver; } EXPORT_SYMBOL_GPL(driver_find); =20 --=20 2.39.1 From nobody Fri Sep 12 16:19:06 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 4FBC0C636D6 for ; Wed, 8 Feb 2023 11:15:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230430AbjBHLOq (ORCPT ); Wed, 8 Feb 2023 06:14:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230296AbjBHLOJ (ORCPT ); Wed, 8 Feb 2023 06:14:09 -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 455F1241C2 for ; Wed, 8 Feb 2023 03:14:08 -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 024B3B81C6E for ; Wed, 8 Feb 2023 11:14:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 732E0C433D2; Wed, 8 Feb 2023 11:14:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1675854845; bh=SwonsbMVauLlz2Qfx4QMXpUrMImp4HMvT+4bbVQGeDc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0ioFPoAW9tbBA31mPYsKrBpxey8vWpIFNivXce4IM5wU1xj51peaSlX5+XGLAJNff UBCLqcA5ijy4EyEZVKMq1Ekdf4mkRWW8fUgakP5LfmfUX9X9KEVtxJfawpFDtreX78 6c+jopLHqptxHRod1OzXXY4a+HKlOdksTu73aAPw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" Subject: [PATCH 16/21] driver core: create bus_is_registered() Date: Wed, 8 Feb 2023 12:13:25 +0100 Message-Id: <20230208111330.439504-17-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=2405; i=gregkh@linuxfoundation.org; h=from:subject; bh=SwonsbMVauLlz2Qfx4QMXpUrMImp4HMvT+4bbVQGeDc=; b=owGbwMvMwCRo6H6F97bub03G02pJDMmPm2+eO32Lh0Hjytdl/6fwXO/J9NrKVRBxk6kxZer9n9ej 5myp64hlYRBkYpAVU2T5so3n6P6KQ4pehranYeawMoEMYeDiFICJrFrGsKDbeYNA2KTee6pvJuzbfm q5UfKbxKcMcwXdBV8mh/Npqq5uv3X7NPvtzP/regA= 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" A local function to the driver core to determine if a bus really is registered with the kernel or not. To be used only by the driver core code, as part of the driver registration path as it's not really "safe" because the bus could be unregistered instantly after being called. Cc: "Rafael J. Wysocki" Signed-off-by: Greg Kroah-Hartman --- drivers/base/base.h | 1 + drivers/base/bus.c | 16 ++++++++++++++++ drivers/base/driver.c | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/drivers/base/base.h b/drivers/base/base.h index 9e06c18c7a64..726a12a244c0 100644 --- a/drivers/base/base.h +++ b/drivers/base/base.h @@ -146,6 +146,7 @@ extern int bus_add_device(struct device *dev); extern void bus_probe_device(struct device *dev); extern void bus_remove_device(struct device *dev); void bus_notify(struct device *dev, enum bus_notifier_event value); +bool bus_is_registered(const struct bus_type *bus); =20 extern int bus_add_driver(struct device_driver *drv); extern void bus_remove_driver(struct device_driver *drv); diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 951d63c8e885..481fb3f41a42 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -1322,6 +1322,22 @@ struct device_driver *driver_find(const char *name, = struct bus_type *bus) } EXPORT_SYMBOL_GPL(driver_find); =20 +/* + * Warning, the value could go to "removed" instantly after calling this f= unction, so be very + * careful when calling it... + */ +bool bus_is_registered(const struct bus_type *bus) +{ + struct subsys_private *sp =3D bus_to_subsys(bus); + bool is_initialized =3D false; + + if (sp) { + is_initialized =3D true; + subsys_put(sp); + } + return is_initialized; +} + int __init buses_init(void) { bus_kset =3D kset_create_and_add("bus", &bus_uevent_ops, NULL); diff --git a/drivers/base/driver.c b/drivers/base/driver.c index aa5e5166a671..c8436c26ed6a 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c @@ -224,7 +224,7 @@ int driver_register(struct device_driver *drv) int ret; struct device_driver *other; =20 - if (!drv->bus->p) { + if (!bus_is_registered(drv->bus)) { pr_err("Driver '%s' was unable to register with bus_type '%s' because th= e bus was not initialized.\n", drv->name, drv->bus->name); return -EINVAL; --=20 2.39.1 From nobody Fri Sep 12 16:19:06 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 61ECBC6379F for ; Wed, 8 Feb 2023 11:15:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230491AbjBHLOv (ORCPT ); Wed, 8 Feb 2023 06:14:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42064 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230352AbjBHLOM (ORCPT ); Wed, 8 Feb 2023 06:14:12 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38028241C2 for ; Wed, 8 Feb 2023 03:14:11 -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 DEB05B81BA8 for ; Wed, 8 Feb 2023 11:14:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F15CC4339B; Wed, 8 Feb 2023 11:14:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1675854848; bh=B7WITxVzELZ3wop+vrAk9NTxAUXnX7ba5996lVEFsFU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RVaV2kT6gNoihEJxAuOAnBYRCGOgnC9+WZOJSNBT5tJGyt2sOq4DTtipk5KNc5sPj S0WpZWO2XpEMRhuyx86ihS7rpKo9L6pgSsmMNKTwiWFtuu4KXjAzkH4PTfbi0aQcuS v1DXYosI8YEEPKJFtInKZHjeFonjZK5VqC7QIxGA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" Subject: [PATCH 17/21] driver core: remove private pointer from struct bus_type Date: Wed, 8 Feb 2023 12:13:26 +0100 Message-Id: <20230208111330.439504-18-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=2182; i=gregkh@linuxfoundation.org; h=from:subject; bh=B7WITxVzELZ3wop+vrAk9NTxAUXnX7ba5996lVEFsFU=; b=owGbwMvMwCRo6H6F97bub03G02pJDMmPm29uX7Khc97OT+/S58nqCRc9cW1xD1Z4Zb3zJrN0wPKZ 7ZH7O2JZGASZGGTFFFm+bOM5ur/ikKKXoe1pmDmsTCBDGLg4BWAiT4IZ5mdfFX5l2r7j8JWf2zkqnu eV3frLHMKwYF3KniDb6uBLLQ5zTbxTsi6fZPJxBgA= 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" Now that the driver code has been refactored to not rely on the pointer from a struct bus_type to the private structure it can be safely removed from the structure entirely. This will allow most bus_type structures to now be marked as const. Cc: "Rafael J. Wysocki" Signed-off-by: Greg Kroah-Hartman --- drivers/base/bus.c | 4 ---- include/linux/device/bus.h | 4 ---- 2 files changed, 8 deletions(-) diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 481fb3f41a42..76cfe9cbf3bd 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -205,11 +205,9 @@ EXPORT_SYMBOL_GPL(bus_remove_file); static void bus_release(struct kobject *kobj) { struct subsys_private *priv =3D to_subsys_private(kobj); - struct bus_type *bus =3D priv->bus; =20 lockdep_unregister_key(&priv->lock_key); kfree(priv); - bus->p =3D NULL; } =20 static struct kobj_type bus_ktype =3D { @@ -854,7 +852,6 @@ int bus_register(struct bus_type *bus) return -ENOMEM; =20 priv->bus =3D bus; - bus->p =3D priv; =20 BLOCKING_INIT_NOTIFIER_HEAD(&priv->bus_notifier); =20 @@ -917,7 +914,6 @@ int bus_register(struct bus_type *bus) kset_unregister(&priv->subsys); out: kfree(priv); - bus->p =3D NULL; return retval; } EXPORT_SYMBOL_GPL(bus_register); diff --git a/include/linux/device/bus.h b/include/linux/device/bus.h index f6537f5fc535..22bf63469275 100644 --- a/include/linux/device/bus.h +++ b/include/linux/device/bus.h @@ -66,8 +66,6 @@ struct fwnode_handle; * @iommu_ops: IOMMU specific operations for this bus, used to attach IOM= MU * driver implementations to a bus and allow the driver to do * bus-specific setup - * @p: The private data of the driver core, only the driver core can - * touch this. * @lock_key: Lock class key for use by the lock validator * @need_parent_lock: When probing or removing a device on this bus, the * device core should lock the device's parent. @@ -111,8 +109,6 @@ struct bus_type { =20 const struct iommu_ops *iommu_ops; =20 - struct subsys_private *p; - bool need_parent_lock; }; =20 --=20 2.39.1 From nobody Fri Sep 12 16:19:06 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 79A64C636D7 for ; Wed, 8 Feb 2023 11:15:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231165AbjBHLOz (ORCPT ); Wed, 8 Feb 2023 06:14:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230376AbjBHLOO (ORCPT ); Wed, 8 Feb 2023 06:14:14 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A7B02241C2 for ; Wed, 8 Feb 2023 03:14:12 -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 dfw.source.kernel.org (Postfix) with ESMTPS id E991E6162D for ; Wed, 8 Feb 2023 11:14:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 009D5C433D2; Wed, 8 Feb 2023 11:14:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1675854851; bh=USqXI1BLX58QBCywv7hi7/+sR7nE+ghRZg0Vc8aHKGI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=X/yPJn5c3IGJApVFTGbKk4hewPdijdSpqZFtbHRxG7ULDPthWZShSQsA+JeSZ9i7L MHJ3j8aEUyRhWPv0o+HVQd712swvlniSHml5ur1bFu6eTiktcCZZO864vADp5ijxfO KRRausvHe3nS4t59NWH8k/LZGqb7NHPxVwM5oaJ0= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" Subject: [PATCH 18/21] driver core: bus: constify bus_register/unregister_notifier() Date: Wed, 8 Feb 2023 12:13:27 +0100 Message-Id: <20230208111330.439504-19-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=1870; i=gregkh@linuxfoundation.org; h=from:subject; bh=USqXI1BLX58QBCywv7hi7/+sR7nE+ghRZg0Vc8aHKGI=; b=owGbwMvMwCRo6H6F97bub03G02pJDMmPm2/eX8CpZc+kK6WqM1vvxqmJws9ta8wKDd/dElR89nJt Y5BjRywLgyATg6yYIsuXbTxH91ccUvQytD0NM4eVCWQIAxenAExkxQKG+alz3893U4mK38++xt77iM DVI6F/dBnmZ3gnt8gdzs6333s+2ONypvW/gs5IAA== 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" The bus_register_notifier() and bus_unregister_notifier() functions should be taking a const * to bus_type, not just a * so fix that up. Cc: "Rafael J. Wysocki" Signed-off-by: Greg Kroah-Hartman --- drivers/base/bus.c | 4 ++-- include/linux/device/bus.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 76cfe9cbf3bd..e6043a2d9feb 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -949,7 +949,7 @@ void bus_unregister(struct bus_type *bus) } EXPORT_SYMBOL_GPL(bus_unregister); =20 -int bus_register_notifier(struct bus_type *bus, struct notifier_block *nb) +int bus_register_notifier(const struct bus_type *bus, struct notifier_bloc= k *nb) { struct subsys_private *sp =3D bus_to_subsys(bus); int retval; @@ -963,7 +963,7 @@ int bus_register_notifier(struct bus_type *bus, struct = notifier_block *nb) } EXPORT_SYMBOL_GPL(bus_register_notifier); =20 -int bus_unregister_notifier(struct bus_type *bus, struct notifier_block *n= b) +int bus_unregister_notifier(const struct bus_type *bus, struct notifier_bl= ock *nb) { struct subsys_private *sp =3D bus_to_subsys(bus); int retval; diff --git a/include/linux/device/bus.h b/include/linux/device/bus.h index 22bf63469275..c0a034ff59b7 100644 --- a/include/linux/device/bus.h +++ b/include/linux/device/bus.h @@ -246,9 +246,9 @@ void bus_sort_breadthfirst(struct bus_type *bus, */ struct notifier_block; =20 -extern int bus_register_notifier(struct bus_type *bus, +extern int bus_register_notifier(const struct bus_type *bus, struct notifier_block *nb); -extern int bus_unregister_notifier(struct bus_type *bus, +extern int bus_unregister_notifier(const struct bus_type *bus, struct notifier_block *nb); =20 /** --=20 2.39.1 From nobody Fri Sep 12 16:19:06 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 8AB9CC64EC5 for ; Wed, 8 Feb 2023 11:15:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231179AbjBHLO5 (ORCPT ); Wed, 8 Feb 2023 06:14:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230379AbjBHLOP (ORCPT ); Wed, 8 Feb 2023 06:14:15 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17D6125287 for ; Wed, 8 Feb 2023 03:14:15 -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 dfw.source.kernel.org (Postfix) with ESMTPS id A7A6761580 for ; Wed, 8 Feb 2023 11:14:14 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C01F0C433EF; Wed, 8 Feb 2023 11:14:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1675854854; bh=T/Gau1Y3toa9EdKaEOCfzmg5Z825+EFIEF/6VNE7kyI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=yA0nLXYQj+fx3znJk9ftO1Ji9w4vEd5UFEUhpCdSfIP4xSgQ5orsG5SFaOy6MQaPq QshulD59hguDCEbhAvjTSc4/jMjZrcnTwsHgatUrAB+poxpPGTl75b9EfCbSqAGElg lzcDbu+G5ih0liOuwn6revOKXNwfUL1O6GbsNAYU= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" Subject: [PATCH 19/21] driver core: bus: constify bus_get_kset() Date: Wed, 8 Feb 2023 12:13:28 +0100 Message-Id: <20230208111330.439504-20-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=1197; i=gregkh@linuxfoundation.org; h=from:subject; bh=T/Gau1Y3toa9EdKaEOCfzmg5Z825+EFIEF/6VNE7kyI=; b=owGbwMvMwCRo6H6F97bub03G02pJDMmPm2/Gyp+L/H8iY8dqY+WOU3Ma9GZdNdwvV1l9MmvHM2eb DwHRHbEsDIJMDLJiiixftvEc3V9xSNHL0PY0zBxWJpAhDFycAjCRlZ4MCzpbXbJnfJ40+Wli1NSJFn pt/J5lXxgWrL2gvUb5S1HNpbm/fnStNzj4PvTmTAA= 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" The bus_get_kset() function should be taking a const * to bus_type, not just a * so fix that up. Cc: "Rafael J. Wysocki" Signed-off-by: Greg Kroah-Hartman --- drivers/base/bus.c | 2 +- include/linux/device/bus.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/base/bus.c b/drivers/base/bus.c index e6043a2d9feb..815638bf63db 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -987,7 +987,7 @@ void bus_notify(struct device *dev, enum bus_notifier_e= vent value) subsys_put(sp); } =20 -struct kset *bus_get_kset(struct bus_type *bus) +struct kset *bus_get_kset(const struct bus_type *bus) { struct subsys_private *sp =3D bus_to_subsys(bus); struct kset *kset; diff --git a/include/linux/device/bus.h b/include/linux/device/bus.h index c0a034ff59b7..425d79d6cf69 100644 --- a/include/linux/device/bus.h +++ b/include/linux/device/bus.h @@ -281,6 +281,6 @@ enum bus_notifier_event { BUS_NOTIFY_DRIVER_NOT_BOUND, }; =20 -extern struct kset *bus_get_kset(struct bus_type *bus); +extern struct kset *bus_get_kset(const struct bus_type *bus); =20 #endif --=20 2.39.1 From nobody Fri Sep 12 16:19:06 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 C2596C636CC for ; Wed, 8 Feb 2023 11:15:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231232AbjBHLPA (ORCPT ); Wed, 8 Feb 2023 06:15:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230390AbjBHLOV (ORCPT ); Wed, 8 Feb 2023 06:14:21 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51926252A4 for ; Wed, 8 Feb 2023 03:14:20 -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 dfw.source.kernel.org (Postfix) with ESMTPS id E188F6162F for ; Wed, 8 Feb 2023 11:14:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F118CC433EF; Wed, 8 Feb 2023 11:14:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1675854859; bh=PZzGpl+8CjvP6M9qzHvZdlUXDvUpv1J5wQBWhMe4CgI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=caOzQcyWJosdreqxaNtSA06wmmTsdMF77U1XH7pEEiTLGKSlMp4btkoYWP6Miw/xO Xgb9S9H+mw/+5aTQ2Dpb5beTtgP1YqU5AuvdhGJWL4gSNiwaZMZ3FBw3Bkb7ALJrE6 gM4zRGM4hyPRMQ1ZjhBs7DINoDd0HnQVsvzHsyUA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" Subject: [PATCH 20/21] driver core: bus: constify some internal functions Date: Wed, 8 Feb 2023 12:13:29 +0100 Message-Id: <20230208111330.439504-21-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=1255; i=gregkh@linuxfoundation.org; h=from:subject; bh=PZzGpl+8CjvP6M9qzHvZdlUXDvUpv1J5wQBWhMe4CgI=; b=owGbwMvMwCRo6H6F97bub03G02pJDMmPm2+yXvoj8fPTsbNlkyYm3l/H1rSI17c8cpdZrHgll7+/ 73mdjlgWBkEmBlkxRZYv23iO7q84pOhlaHsaZg4rE8gQBi5OAZjIG1mG+bGyfVm3Nux9sjHmVaPfu9 zPX93snjEsWPbs94Zr7oKTewKWKd+s35uR+/iWOwA= 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" The functions add_probe_files() and remove_probe_files() should be taking a const * to bus_type, not just a *, so fix that up. These functions should really be removed entirely and an attribute group used instead, but for now, make this change so that other const work can continue. Cc: "Rafael J. Wysocki" Signed-off-by: Greg Kroah-Hartman --- drivers/base/bus.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 815638bf63db..a7aada8817ce 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -603,7 +603,7 @@ static void remove_bind_files(struct device_driver *drv) static BUS_ATTR_WO(drivers_probe); static BUS_ATTR_RW(drivers_autoprobe); =20 -static int add_probe_files(struct bus_type *bus) +static int add_probe_files(const struct bus_type *bus) { int retval; =20 @@ -618,7 +618,7 @@ static int add_probe_files(struct bus_type *bus) return retval; } =20 -static void remove_probe_files(struct bus_type *bus) +static void remove_probe_files(const struct bus_type *bus) { bus_remove_file(bus, &bus_attr_drivers_autoprobe); bus_remove_file(bus, &bus_attr_drivers_probe); --=20 2.39.1 From nobody Fri Sep 12 16:19:06 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 28194C05027 for ; Wed, 8 Feb 2023 11:15:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231318AbjBHLPF (ORCPT ); Wed, 8 Feb 2023 06:15:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230392AbjBHLOX (ORCPT ); Wed, 8 Feb 2023 06:14:23 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E191725287 for ; Wed, 8 Feb 2023 03:14:22 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 7DEE361491 for ; Wed, 8 Feb 2023 11:14:22 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9435CC433D2; Wed, 8 Feb 2023 11:14:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1675854861; bh=GvFijIBn90h98leK5sXJ9ygGvQHZQz+yMN3VbsMyDaU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZqY8FOf/9eFNEmO26vtRlfxXDpB42dNDfXFdfbB9wjSQ5KTK/R3YFgXwnEV6Jj0o9 P7/HoxIKRnJhuLxs2MWrPcibnV2wE5pTOGEyrr3Lt0yRmKTmR1c6if7k4tMqhHNQcI cFzozfiak5eJX0zLIKeT4IIzhLRIjdKuPdLDjawc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , "Rafael J. Wysocki" Subject: [PATCH 21/21] driver core: bus: constify bus_unregister() Date: Wed, 8 Feb 2023 12:13:30 +0100 Message-Id: <20230208111330.439504-22-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=1319; i=gregkh@linuxfoundation.org; h=from:subject; bh=GvFijIBn90h98leK5sXJ9ygGvQHZQz+yMN3VbsMyDaU=; b=owGbwMvMwCRo6H6F97bub03G02pJDMmPm2/teaZgmzN/V/p77drFT3RnnbkkYtnllizi7HGq3rCC aWdVRywLgyATg6yYIsuXbTxH91ccUvQytD0NM4eVCWQIAxenAExkmQnDgnmFzzp3Pd+oc9bX4mhIno p4cKzFDYb5fp+M374vMp9w6Xn61X7u2xYK0aEbAA== 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" The bus_unregister() function can now take a const * to bus_type, not just a * so fix that up. Cc: "Rafael J. Wysocki" Signed-off-by: Greg Kroah-Hartman --- drivers/base/bus.c | 2 +- include/linux/device/bus.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/base/bus.c b/drivers/base/bus.c index a7aada8817ce..4c85d264113a 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -925,7 +925,7 @@ EXPORT_SYMBOL_GPL(bus_register); * Unregister the child subsystems and the bus itself. * Finally, we call bus_put() to release the refcount */ -void bus_unregister(struct bus_type *bus) +void bus_unregister(const struct bus_type *bus) { struct subsys_private *sp =3D bus_to_subsys(bus); struct kobject *bus_kobj; diff --git a/include/linux/device/bus.h b/include/linux/device/bus.h index 425d79d6cf69..31be18608f83 100644 --- a/include/linux/device/bus.h +++ b/include/linux/device/bus.h @@ -114,7 +114,7 @@ struct bus_type { =20 extern int __must_check bus_register(struct bus_type *bus); =20 -extern void bus_unregister(struct bus_type *bus); +extern void bus_unregister(const struct bus_type *bus); =20 extern int __must_check bus_rescan_devices(struct bus_type *bus); =20 --=20 2.39.1