public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Rafael J. Wysocki" <rafael@kernel.org>
Subject: [PATCH 04/21] driver core: bus: convert bus_create/remove_file to be constant
Date: Wed,  8 Feb 2023 12:13:13 +0100	[thread overview]
Message-ID: <20230208111330.439504-5-gregkh@linuxfoundation.org> (raw)
In-Reply-To: <20230208111330.439504-1-gregkh@linuxfoundation.org>

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" <rafael@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 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 = {
 	.store	= bus_attr_store,
 };
 
-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 = bus_to_subsys(bus);
 	int error;
-	if (bus_get(bus)) {
-		error = sysfs_create_file(&bus->p->subsys.kobj, &attr->attr);
-		bus_put(bus);
-	} else
-		error = -EINVAL;
+
+	if (!sp)
+		return -EINVAL;
+
+	error = sysfs_create_file(&sp->subsys.kobj, &attr->attr);
+
+	subsys_put(sp);
 	return error;
 }
 EXPORT_SYMBOL_GPL(bus_create_file);
 
-void bus_remove_file(struct bus_type *bus, struct bus_attribute *attr)
+void bus_remove_file(const struct bus_type *bus, struct bus_attribute *attr)
 {
-	if (bus_get(bus)) {
-		sysfs_remove_file(&bus->p->subsys.kobj, &attr->attr);
-		bus_put(bus);
-	}
+	struct subsys_private *sp = bus_to_subsys(bus);
+
+	if (!sp)
+		return;
+
+	sysfs_remove_file(&sp->subsys.kobj, &attr->attr);
+	subsys_put(sp);
 }
 EXPORT_SYMBOL_GPL(bus_remove_file);
 
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 = __ATTR_WO(_name)
 
-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_attribute *attr);
+void bus_remove_file(const struct bus_type *bus, struct bus_attribute *attr);
 
 /* Generic device matching functions that all busses can use to match with */
 int device_match_name(struct device *dev, const void *name);
-- 
2.39.1


  parent reply	other threads:[~2023-02-08 11:15 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-08 11:13 [PATCH 00/21] driver core: bus: remove private "backpointer" from struct bus_type Greg Kroah-Hartman
2023-02-08 11:13 ` [PATCH 01/21] driver core: add local subsys_get and subsys_put functions Greg Kroah-Hartman
2023-02-08 11:13 ` [PATCH 02/21] driver core: bus: implement bus_get/put() without the private pointer Greg Kroah-Hartman
2023-02-08 11:13 ` [PATCH 03/21] driver core: bus: constantify the bus_find_* functions Greg Kroah-Hartman
2023-02-08 11:13 ` Greg Kroah-Hartman [this message]
2023-02-08 11:13 ` [PATCH 05/21] driver core: bus: sysfs function cleanups Greg Kroah-Hartman
2023-02-08 11:13 ` [PATCH 06/21] driver core: bus: bus_add/probe/remove_device() cleanups Greg Kroah-Hartman
2023-02-08 11:13 ` [PATCH 07/21] driver core: bus: bus_register/unregister() cleanups Greg Kroah-Hartman
2023-02-08 11:13 ` [PATCH 08/21] driver core: bus: subsys_interface_register/unregister() cleanups Greg Kroah-Hartman
2023-02-08 11:13 ` [PATCH 09/21] driver core: bus: bus_get_kset() cleanup Greg Kroah-Hartman
2023-02-08 11:13 ` [PATCH 10/21] driver core: bus: bus_register/unregister_notifier() cleanups Greg Kroah-Hartman
2023-02-08 11:13 ` [PATCH 11/21] driver core: bus: bus_add/remove_driver() cleanups Greg Kroah-Hartman
2023-02-08 11:13 ` [PATCH 12/21] driver core: bus: bus iterator cleanups Greg Kroah-Hartman
2023-02-21 12:54   ` Geert Uytterhoeven
2023-02-08 11:13 ` [PATCH 13/21] driver core: bus: clean up bus_sort_breadthfirst() Greg Kroah-Hartman
2023-02-08 11:13 ` [PATCH 14/21] driver core: move driver_find() to bus.c Greg Kroah-Hartman
2023-02-08 11:13 ` [PATCH 15/21] driver core: bus: clean up driver_find() Greg Kroah-Hartman
2023-02-08 11:13 ` [PATCH 16/21] driver core: create bus_is_registered() Greg Kroah-Hartman
2023-02-08 11:13 ` [PATCH 17/21] driver core: remove private pointer from struct bus_type Greg Kroah-Hartman
2023-02-08 11:13 ` [PATCH 18/21] driver core: bus: constify bus_register/unregister_notifier() Greg Kroah-Hartman
2023-02-08 11:13 ` [PATCH 19/21] driver core: bus: constify bus_get_kset() Greg Kroah-Hartman
2023-02-08 11:13 ` [PATCH 20/21] driver core: bus: constify some internal functions Greg Kroah-Hartman
2023-02-08 11:13 ` [PATCH 21/21] driver core: bus: constify bus_unregister() Greg Kroah-Hartman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230208111330.439504-5-gregkh@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rafael@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox