linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Max Kellermann <max.kellermann@ionos.com>
To: linux-kernel@vger.kernel.org
Cc: Max Kellermann <max.kellermann@ionos.com>
Subject: [PATCH v2 07/35] sysfs.h: move declarations to sysfs_types.h
Date: Fri,  9 Feb 2024 17:39:59 +0100	[thread overview]
Message-ID: <20240209164027.2582906-8-max.kellermann@ionos.com> (raw)
In-Reply-To: <20240209164027.2582906-1-max.kellermann@ionos.com>

By providing declarations in a lean header, we can reduce header
dependencies.

Signed-off-by: Max Kellermann <max.kellermann@ionos.com>
---
 drivers/firmware/dmi-sysfs.c    |  1 +
 drivers/firmware/memmap.c       |  1 +
 drivers/input/vivaldi-fmap.c    |  1 +
 include/linux/device/bus.h      |  2 +-
 include/linux/iio/buffer_impl.h |  3 +-
 include/linux/kobject.h         |  2 +-
 include/linux/module.h          |  2 +-
 include/linux/perf_event.h      |  2 +-
 include/linux/sysfs.h           | 63 +----------------------
 include/linux/sysfs_types.h     | 89 +++++++++++++++++++++++++++++++++
 include/linux/thermal.h         |  2 +-
 include/net/netdev_rx_queue.h   |  2 +-
 include/rdma/ib_sysfs.h         |  2 +-
 kernel/kheaders.c               |  1 +
 lib/kobject.c                   |  1 +
 mm/cma_sysfs.c                  |  1 +
 16 files changed, 105 insertions(+), 70 deletions(-)
 create mode 100644 include/linux/sysfs_types.h

diff --git a/drivers/firmware/dmi-sysfs.c b/drivers/firmware/dmi-sysfs.c
index b6a72128e818..158cc26a0331 100644
--- a/drivers/firmware/dmi-sysfs.c
+++ b/drivers/firmware/dmi-sysfs.c
@@ -25,6 +25,7 @@
 #include <linux/dmi.h>
 #include <linux/capability.h>
 #include <linux/slab.h>
+#include <linux/sysfs.h>
 #include <linux/list.h>
 #include <linux/io.h>
 #include <asm/dmi.h>
diff --git a/drivers/firmware/memmap.c b/drivers/firmware/memmap.c
index 4cf473815372..a188b204a012 100644
--- a/drivers/firmware/memmap.c
+++ b/drivers/firmware/memmap.c
@@ -14,6 +14,7 @@
 #include <linux/types.h>
 #include <linux/memblock.h>
 #include <linux/slab.h>
+#include <linux/sysfs.h>
 #include <linux/mm.h>
 
 /*
diff --git a/drivers/input/vivaldi-fmap.c b/drivers/input/vivaldi-fmap.c
index 0d29ec014e2f..72845c0720f2 100644
--- a/drivers/input/vivaldi-fmap.c
+++ b/drivers/input/vivaldi-fmap.c
@@ -9,6 +9,7 @@
 #include <linux/input/vivaldi-fmap.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
+#include <linux/sysfs.h>
 #include <linux/types.h>
 
 /**
diff --git a/include/linux/device/bus.h b/include/linux/device/bus.h
index bdd8ac64f629..a6fc75a825a3 100644
--- a/include/linux/device/bus.h
+++ b/include/linux/device/bus.h
@@ -16,7 +16,7 @@
 
 #include <linux/klist.h>
 #include <linux/pm.h>
-#include <linux/sysfs.h> // for struct attribute
+#include <linux/sysfs_types.h> // for struct attribute
 
 struct device_driver;
 struct device_node;
diff --git a/include/linux/iio/buffer_impl.h b/include/linux/iio/buffer_impl.h
index 184f8c399854..df4cad6a8c8e 100644
--- a/include/linux/iio/buffer_impl.h
+++ b/include/linux/iio/buffer_impl.h
@@ -1,7 +1,8 @@
 /* SPDX-License-Identifier: GPL-2.0 */
 #ifndef _IIO_BUFFER_GENERIC_IMPL_H_
 #define _IIO_BUFFER_GENERIC_IMPL_H_
-#include <linux/sysfs.h>
+
+#include <linux/sysfs_types.h> // for struct attribute_group
 #include <linux/kref_types.h>
 
 #ifdef CONFIG_IIO_BUFFER
diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index cd29809a05e4..462a2d604b03 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -18,7 +18,7 @@
 #include <linux/kobject_types.h>
 #include <linux/types.h>
 #include <linux/list.h>
-#include <linux/sysfs.h>
+#include <linux/sysfs_types.h> // for struct attribute
 #include <linux/compiler.h>
 #include <linux/container_of.h>
 #include <linux/spinlock_types.h>
diff --git a/include/linux/module.h b/include/linux/module.h
index 426d3bdf83bb..ba3c0d129cb5 100644
--- a/include/linux/module.h
+++ b/include/linux/module.h
@@ -27,7 +27,7 @@
 #include <linux/tracepoint-defs.h>
 #include <linux/srcu.h>
 #include <linux/static_call_types.h>
-#include <linux/sysfs.h> // for struct attribute
+#include <linux/sysfs_types.h> // for struct attribute
 #include <linux/dynamic_debug.h>
 
 #include <linux/percpu.h>
diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
index eaf5d5f76e0e..b3aec977b0e4 100644
--- a/include/linux/perf_event.h
+++ b/include/linux/perf_event.h
@@ -55,7 +55,7 @@ struct perf_guest_info_callbacks {
 #include <linux/static_key.h>
 #include <linux/jump_label_ratelimit.h>
 #include <linux/atomic.h>
-#include <linux/sysfs.h>
+#include <linux/sysfs_types.h>
 #include <linux/perf_regs.h>
 #include <linux/cgroup.h>
 #include <linux/refcount_types.h>
diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
index 6fed6884d2e6..0500b023b5cc 100644
--- a/include/linux/sysfs.h
+++ b/include/linux/sysfs.h
@@ -13,6 +13,7 @@
 #ifndef _SYSFS_H_
 #define _SYSFS_H_
 
+#include <linux/sysfs_types.h>
 #include <linux/kernfs.h>
 #include <linux/kernel.h> // for VERIFY_OCTAL_PERMISSIONS()
 #include <linux/compiler.h>
@@ -23,16 +24,6 @@ struct kobject;
 struct module;
 struct bin_attribute;
 
-struct attribute {
-	const char		*name;
-	umode_t			mode;
-#ifdef CONFIG_DEBUG_LOCK_ALLOC
-	bool			ignore_lockdep:1;
-	struct lock_class_key	*key;
-	struct lock_class_key	skey;
-#endif
-};
-
 /**
  *	sysfs_attr_init - initialize a dynamically allocated sysfs attribute
  *	@attr: struct attribute to initialize
@@ -54,39 +45,6 @@ do {							\
 #define sysfs_attr_init(attr) do {} while (0)
 #endif
 
-/**
- * struct attribute_group - data structure used to declare an attribute group.
- * @name:	Optional: Attribute group name
- *		If specified, the attribute group will be created in
- *		a new subdirectory with this name.
- * @is_visible:	Optional: Function to return permissions associated with an
- *		attribute of the group. Will be called repeatedly for each
- *		non-binary attribute in the group. Only read/write
- *		permissions as well as SYSFS_PREALLOC are accepted. Must
- *		return 0 if an attribute is not visible. The returned value
- *		will replace static permissions defined in struct attribute.
- * @is_bin_visible:
- *		Optional: Function to return permissions associated with a
- *		binary attribute of the group. Will be called repeatedly
- *		for each binary attribute in the group. Only read/write
- *		permissions as well as SYSFS_PREALLOC are accepted. Must
- *		return 0 if a binary attribute is not visible. The returned
- *		value will replace static permissions defined in
- *		struct bin_attribute.
- * @attrs:	Pointer to NULL terminated list of attributes.
- * @bin_attrs:	Pointer to NULL terminated list of binary attributes.
- *		Either attrs or bin_attrs or both must be provided.
- */
-struct attribute_group {
-	const char		*name;
-	umode_t			(*is_visible)(struct kobject *,
-					      struct attribute *, int);
-	umode_t			(*is_bin_visible)(struct kobject *,
-						  struct bin_attribute *, int);
-	struct attribute	**attrs;
-	struct bin_attribute	**bin_attrs;
-};
-
 /*
  * Use these macros to make defining attributes easier.
  * See include/linux/device.h for examples..
@@ -164,25 +122,6 @@ static const struct attribute_group _name##_group = {		\
 };								\
 __ATTRIBUTE_GROUPS(_name)
 
-struct file;
-struct vm_area_struct;
-struct address_space;
-
-struct bin_attribute {
-	struct attribute	attr;
-	size_t			size;
-	void			*private;
-	struct address_space *(*f_mapping)(void);
-	ssize_t (*read)(struct file *, struct kobject *, struct bin_attribute *,
-			char *, loff_t, size_t);
-	ssize_t (*write)(struct file *, struct kobject *, struct bin_attribute *,
-			 char *, loff_t, size_t);
-	loff_t (*llseek)(struct file *, struct kobject *, struct bin_attribute *,
-			 loff_t, int);
-	int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
-		    struct vm_area_struct *vma);
-};
-
 /**
  *	sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
  *	@attr: struct bin_attribute to initialize
diff --git a/include/linux/sysfs_types.h b/include/linux/sysfs_types.h
new file mode 100644
index 000000000000..2840a1935ea1
--- /dev/null
+++ b/include/linux/sysfs_types.h
@@ -0,0 +1,89 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * sysfs.h - definitions for the device driver filesystem
+ *
+ * Copyright (c) 2001,2002 Patrick Mochel
+ * Copyright (c) 2004 Silicon Graphics, Inc.
+ * Copyright (c) 2007 SUSE Linux Products GmbH
+ * Copyright (c) 2007 Tejun Heo <teheo@suse.de>
+ *
+ * Please see Documentation/filesystems/sysfs.rst for more information.
+ */
+
+#ifndef _SYSFS_TYPES_H_
+#define _SYSFS_TYPES_H_
+
+#include <linux/types.h>
+#include <linux/lockdep_types.h>
+
+struct kobject;
+struct module;
+struct bin_attribute;
+
+struct attribute {
+	const char		*name;
+	umode_t			mode;
+#ifdef CONFIG_DEBUG_LOCK_ALLOC
+	bool			ignore_lockdep:1;
+	struct lock_class_key	*key;
+	struct lock_class_key	skey;
+#endif
+};
+
+/**
+ * struct attribute_group - data structure used to declare an attribute group.
+ * @name:	Optional: Attribute group name
+ *		If specified, the attribute group will be created in
+ *		a new subdirectory with this name.
+ * @is_visible:	Optional: Function to return permissions associated with an
+ *		attribute of the group. Will be called repeatedly for each
+ *		non-binary attribute in the group. Only read/write
+ *		permissions as well as SYSFS_PREALLOC are accepted. Must
+ *		return 0 if an attribute is not visible. The returned value
+ *		will replace static permissions defined in struct attribute.
+ * @is_bin_visible:
+ *		Optional: Function to return permissions associated with a
+ *		binary attribute of the group. Will be called repeatedly
+ *		for each binary attribute in the group. Only read/write
+ *		permissions as well as SYSFS_PREALLOC are accepted. Must
+ *		return 0 if a binary attribute is not visible. The returned
+ *		value will replace static permissions defined in
+ *		struct bin_attribute.
+ * @attrs:	Pointer to NULL terminated list of attributes.
+ * @bin_attrs:	Pointer to NULL terminated list of binary attributes.
+ *		Either attrs or bin_attrs or both must be provided.
+ */
+struct attribute_group {
+	const char		*name;
+	umode_t			(*is_visible)(struct kobject *,
+					      struct attribute *, int);
+	umode_t			(*is_bin_visible)(struct kobject *,
+						  struct bin_attribute *, int);
+	struct attribute	**attrs;
+	struct bin_attribute	**bin_attrs;
+};
+
+struct file;
+struct vm_area_struct;
+struct address_space;
+
+struct bin_attribute {
+	struct attribute	attr;
+	size_t			size;
+#ifdef __cplusplus
+	void			*private_;
+#else
+	void			*private;
+#endif
+	struct address_space *(*f_mapping)(void);
+	ssize_t (*read)(struct file *, struct kobject *, struct bin_attribute *,
+			char *, loff_t, size_t);
+	ssize_t (*write)(struct file *, struct kobject *, struct bin_attribute *,
+			 char *, loff_t, size_t);
+	loff_t (*llseek)(struct file *, struct kobject *, struct bin_attribute *,
+			 loff_t, int);
+	int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
+		    struct vm_area_struct *vma);
+};
+
+#endif /* _SYSFS_TYPES_H_ */
diff --git a/include/linux/thermal.h b/include/linux/thermal.h
index e0bdda259a29..14450673bd8b 100644
--- a/include/linux/thermal.h
+++ b/include/linux/thermal.h
@@ -12,7 +12,7 @@
 
 #include <linux/idr.h>
 #include <linux/device.h>
-#include <linux/sysfs.h>
+#include <linux/sysfs_types.h>
 #include <linux/workqueue_types.h>
 #include <uapi/linux/thermal.h>
 
diff --git a/include/net/netdev_rx_queue.h b/include/net/netdev_rx_queue.h
index 4841ec031857..7122cb4b7e44 100644
--- a/include/net/netdev_rx_queue.h
+++ b/include/net/netdev_rx_queue.h
@@ -4,7 +4,7 @@
 
 #include <linux/kobject_types.h>
 #include <linux/netdevice.h>
-#include <linux/sysfs.h>
+#include <linux/sysfs_types.h>
 #include <net/xdp.h>
 
 /* This structure contains an instance of an RX queue. */
diff --git a/include/rdma/ib_sysfs.h b/include/rdma/ib_sysfs.h
index 3b77cfd74d9a..ece1b920c690 100644
--- a/include/rdma/ib_sysfs.h
+++ b/include/rdma/ib_sysfs.h
@@ -5,7 +5,7 @@
 #ifndef DEF_RDMA_IB_SYSFS_H
 #define DEF_RDMA_IB_SYSFS_H
 
-#include <linux/sysfs.h>
+#include <linux/sysfs_types.h>
 
 struct ib_device;
 
diff --git a/kernel/kheaders.c b/kernel/kheaders.c
index 42163c9e94e5..b48bd8a23cda 100644
--- a/kernel/kheaders.c
+++ b/kernel/kheaders.c
@@ -10,6 +10,7 @@
 #include <linux/module.h>
 #include <linux/kobject.h>
 #include <linux/init.h>
+#include <linux/sysfs.h>
 
 /*
  * Define kernel_headers_data and kernel_headers_data_end, within which the
diff --git a/lib/kobject.c b/lib/kobject.c
index 48ba445604f8..f53564596438 100644
--- a/lib/kobject.c
+++ b/lib/kobject.c
@@ -22,6 +22,7 @@
 #include <linux/uidgid.h>
 #include <linux/workqueue.h>
 #include <linux/kref.h>
+#include <linux/sysfs.h>
 
 /**
  * kobject_namespace() - Return @kobj's namespace tag.
diff --git a/mm/cma_sysfs.c b/mm/cma_sysfs.c
index f50db3973171..2c75ea0827c4 100644
--- a/mm/cma_sysfs.c
+++ b/mm/cma_sysfs.c
@@ -8,6 +8,7 @@
 #include <linux/cma.h>
 #include <linux/kernel.h>
 #include <linux/slab.h>
+#include <linux/sysfs.h>
 
 #include "cma.h"
 
-- 
2.39.2


  parent reply	other threads:[~2024-02-09 16:40 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-09 16:39 [PATCH v2 00/35] Fast kernel headers: reduce header dependencies Max Kellermann
2024-02-09 16:39 ` [PATCH v2 01/35] include: add missing includes Max Kellermann
2024-02-09 16:39 ` [PATCH v2 02/35] include: remove unnecessary #include directives Max Kellermann
2024-02-10 12:36   ` kernel test robot
2024-02-10 12:58   ` kernel test robot
2024-02-09 16:39 ` [PATCH v2 03/35] include: reduce header dependencies by using "*_types.h" Max Kellermann
2024-02-09 16:39 ` [PATCH v2 04/35] workqueue.h: move struct delayed_work to workqueue_types.h Max Kellermann
2024-02-09 16:39 ` [PATCH v2 05/35] kref.h: move declarations to kref_types.h Max Kellermann
2024-02-09 16:39 ` [PATCH v2 06/35] kobject.h: move declarations to kobject_types.h Max Kellermann
2024-02-09 16:39 ` Max Kellermann [this message]
2024-02-09 16:40 ` [PATCH v2 08/35] maple_tree.h: move declarations to maple_tree_types.h Max Kellermann
2024-02-09 16:40 ` [PATCH v2 09/35] rwsem.h: move declarations to rwsem_types.h Max Kellermann
2024-02-09 16:40 ` [PATCH v2 10/35] uprobes.h: move declarations to uprobes_types.h Max Kellermann
2024-02-09 16:40 ` [PATCH v2 11/35] percpu_counter.h: move declarations to percpu_counter_types.h Max Kellermann
2024-02-09 16:40 ` [PATCH v2 12/35] bvec.h: move declarations to bvec_types.h Max Kellermann
2024-02-09 16:40 ` [PATCH v2 13/35] wait.h: move declarations to wait_types.h Max Kellermann
2024-02-09 16:40 ` [PATCH v2 14/35] swait.h: move declarations to swait_types.h Max Kellermann
2024-02-09 16:40 ` [PATCH v2 15/35] completion.h: move declarations to completion_types.h Max Kellermann
2024-02-09 16:40 ` [PATCH v2 16/35] device.h: move declarations to device_types.h Max Kellermann
2024-02-09 16:40 ` [PATCH v2 17/35] xarray.h: move declarations to xarray_types.h Max Kellermann
2024-02-09 16:40 ` [PATCH v2 18/35] blkdev.h: move blk_op_is_passthrough() to blk_types.h Max Kellermann
2024-02-09 16:40 ` [PATCH v2 19/35] bio.h: move bio_has_data() and bio_no_advance_iter() " Max Kellermann
2024-02-09 16:40 ` [PATCH v2 20/35] bio.h: move declarations to bio_types.h Max Kellermann
2024-02-09 16:40 ` [PATCH v2 21/35] percpu-refcount.h: move declarations to percpu-refcount_types.h Max Kellermann
2024-02-09 16:40 ` [PATCH v2 22/35] blkdev.h: move declarations to blkdev_types.h Max Kellermann
2024-02-09 16:40 ` [PATCH v2 23/35] sbitmap.h: move declarations to sbitmap_types.h Max Kellermann
2024-02-09 16:40 ` [PATCH v2 24/35] list_lru.h: move declarations to list_lru_types.h Max Kellermann
2024-02-09 16:40 ` [PATCH v2 25/35] list_bl.h: move declarations to list_bl_types.h Max Kellermann
2024-02-09 16:40 ` [PATCH v2 26/35] percpu-rwsem.h: move declarations to percpu-rwsem_types.h Max Kellermann
2024-02-09 16:40 ` [PATCH v2 27/35] quota.h: move declarations to quota_types.h Max Kellermann
2024-02-09 16:40 ` [PATCH v2 28/35] radix-tree.h: move declarations to radix-tree_types.h Max Kellermann
2024-02-09 16:40 ` [PATCH v2 29/35] linux/random.h: reduce dependencies on linux/kernel.h Max Kellermann
2024-02-09 16:40 ` [PATCH v2 30/35] linux/kernel.h: move might_sleep(), ... to sched/debug_atomic_sleep.h Max Kellermann
2024-02-09 16:40 ` [PATCH v2 31/35] linux/kernel.h: move READ and WRITE to direction.h Max Kellermann
2024-02-09 16:40 ` [PATCH v2 32/35] linux/kernel.h: move VERIFY_OCTAL_PERMISSIONS() to octal_permissions.h Max Kellermann
2024-02-09 16:40 ` [PATCH v2 33/35] linux/kernel.h: move upper/lower_*_bits macros to wordpart.h Max Kellermann
2024-02-09 16:40 ` [PATCH v2 34/35] linux/kernel.h: move PTR_IF() to ptr_util.h Max Kellermann
2024-02-09 16:40 ` [PATCH v2 35/35] include: remove lots of unnecessary <linux/kernel.h> includes Max Kellermann
2024-02-10 12:26   ` kernel test robot
2024-03-25 13:05 ` [PATCH v2 00/35] Fast kernel headers: reduce header dependencies Andy Shevchenko
2024-03-29 13:31   ` Max Kellermann

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=20240209164027.2582906-8-max.kellermann@ionos.com \
    --to=max.kellermann@ionos.com \
    --cc=linux-kernel@vger.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;
as well as URLs for NNTP newsgroup(s).