Skip to contentSkip to conversation

device.h: split up into smaller pieces

PATCH In review Greg Kroah-Hartman 2 participants 8 messages Dec 9, 2019 Driver core

lore
Share & tools
lore

Greg Kroah-Hartman

author maintainer
#0 lore raw

cover device.h: split up into smaller pieces

During the 5.4-rc merge Linus complained about the size of device.h and how it can be a pain to merge things into at times. It's also become kind of a "kitchen sink" for anything related to drivers / devices / busses / classes and is the 10th largest include/linux/*.h file by size.

So let's split it up into smaller pieces, moving things out by logical parts where it can be.

Greg Kroah-Hartman (6):
drivers/base: base.h: add proper copyright and header info device.h: move devtmpfs prototypes out of the file device.h: move dev_printk()-like functions to dev_printk.h device.h: move 'struct bus' stuff out to device/bus.h device.h: move 'struct class' stuff out to device/class.h device.h: move 'struct driver' stuff out to device/driver.h

 drivers/base/base.h           |  19 +
 drivers/base/bus.c            |   1 +
 drivers/base/class.c          |   1 +
 drivers/base/driver.c         |   1 +
 include/linux/dev_printk.h    | 235 ++++++++
 include/linux/device.h        | 999 +---------------------------------
 include/linux/device/bus.h    | 288 ++++++++++
 include/linux/device/class.h  | 266 +++++++++
 include/linux/device/driver.h | 292 ++++++++++
 init/main.c                   |   2 +-
 10 files changed, 1108 insertions(+), 996 deletions(-)
 create mode 100644 include/linux/dev_printk.h
 create mode 100644 include/linux/device/bus.h
 create mode 100644 include/linux/device/class.h
 create mode 100644 include/linux/device/driver.h
Signature · 1 line
2.24.0
author maintainer
#1 lore raw

PATCH 1/6 drivers/base: base.h: add proper copyright and header info

base.h didn't have any copyright information in it, so update it with the correct information.

Cc "Rafael J. Wysocki" <[email protected]>
---
 drivers/base/base.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/base/base.h +11 -0
index 0d32544b6f91..80598b312940 100644
@@ -1,4 +1,15 @@
 /* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (c) 2001-2003 Patrick Mochel <[email protected]>
+ * Copyright (c) 2004-2009 Greg Kroah-Hartman <[email protected]>
+ * Copyright (c) 2008-2012 Novell Inc.
+ * Copyright (c) 2012-2019 Greg Kroah-Hartman <[email protected]>
+ * Copyright (c) 2012-2019 Linux Foundation
+ *
+ * Core driver model functions and structures that should not be
+ * shared outside of the drivers/base/ directory.
+ *
+ */
 #include <linux/notifier.h>
 
 /**
Signature · 1 line
2.24.0
author maintainer
#2 lore raw

PATCH 2/6 device.h: move devtmpfs prototypes out of the file

In reply to Greg Kroah-Hartman

The devtmpfs functions do not need to be in device.h as only the driver core uses them, so move them to the private .h file for the driver core.

Cc "Rafael J. Wysocki" <[email protected]>
Cc Suzuki K Poulose <[email protected]>
Cc Saravana Kannan <[email protected]>
Cc Heikki Krogerus <[email protected]>
---
 drivers/base/base.h    | 8 ++++++++
 include/linux/device.h | 4 ----
 2 files changed, 8 insertions(+), 4 deletions(-)
drivers/base/base.h +8 -0
index 80598b312940..40fb069a8a7e 100644
@@ -186,3 +186,11 @@ extern void device_links_unbind_consumers(struct device *dev);
 
 /* device pm support */
 void device_pm_move_to_tail(struct device *dev);
+
+#ifdef CONFIG_DEVTMPFS
+int devtmpfs_create_node(struct device *dev);
+int devtmpfs_delete_node(struct device *dev);
+#else
+static inline int devtmpfs_create_node(struct device *dev) { return 0; }
+static inline int devtmpfs_delete_node(struct device *dev) { return 0; }
+#endif
include/linux/device.h +0 -4
index e226030c1df3..3daec3af1753 100644
@@ -1664,12 +1664,8 @@ extern void put_device(struct device *dev);
 extern bool kill_device(struct device *dev);
 
 #ifdef CONFIG_DEVTMPFS
-extern int devtmpfs_create_node(struct device *dev);
-extern int devtmpfs_delete_node(struct device *dev);
 extern int devtmpfs_mount(const char *mntdir);
 #else
-static inline int devtmpfs_create_node(struct device *dev) { return 0; }
-static inline int devtmpfs_delete_node(struct device *dev) { return 0; }
 static inline int devtmpfs_mount(const char *mountpoint) { return 0; }
 #endif
 
Signature · 1 line
2.24.0
author maintainer
#3 lore raw

PATCH 3/6 device.h: move dev_printk()-like functions to dev_printk.h

In reply to Greg Kroah-Hartman

device.h has everything and the kitchen sink when it comes to struct device things, so split out the printk-specific things to a separate .h file to make things easier to maintain and manage over time.

Cc Suzuki K Poulose <[email protected]>
Cc "Rafael J. Wysocki" <[email protected]>
Cc Saravana Kannan <[email protected]>
Cc Heikki Krogerus <[email protected]>
---
 include/linux/dev_printk.h | 235 +++++++++++++++++++++++++++++++++++++
 include/linux/device.h     | 217 +---------------------------------
 2 files changed, 236 insertions(+), 216 deletions(-)
 create mode 100644 include/linux/dev_printk.h
include/linux/dev_printk.h new file +235 -0
new file mode 100644
index 000000000000..5aad06b4ca7b
@@ -0,0 +1,235 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * dev_printk.h - printk messages helpers for devices
+ *
+ * Copyright (c) 2001-2003 Patrick Mochel <[email protected]>
+ * Copyright (c) 2004-2009 Greg Kroah-Hartman <[email protected]>
+ * Copyright (c) 2008-2009 Novell Inc.
+ *
+ */
+
+#ifndef _DEVICE_PRINTK_H_
+#define _DEVICE_PRINTK_H_
+
+#include <linux/compiler.h>
+#include <linux/types.h>
+#include <linux/ratelimit.h>
+
+#ifndef dev_fmt
+#define dev_fmt(fmt) fmt
+#endif
+
+struct device;
+
+#ifdef CONFIG_PRINTK
+
+__printf(3, 0) __cold
+int dev_vprintk_emit(int level, const struct device *dev,
+		     const char *fmt, va_list args);
+__printf(3, 4) __cold
+int dev_printk_emit(int level, const struct device *dev, const char *fmt, ...);
+
+__printf(3, 4) __cold
+void dev_printk(const char *level, const struct device *dev,
+		const char *fmt, ...);
+__printf(2, 3) __cold
+void _dev_emerg(const struct device *dev, const char *fmt, ...);
+__printf(2, 3) __cold
+void _dev_alert(const struct device *dev, const char *fmt, ...);
+__printf(2, 3) __cold
+void _dev_crit(const struct device *dev, const char *fmt, ...);
+__printf(2, 3) __cold
+void _dev_err(const struct device *dev, const char *fmt, ...);
+__printf(2, 3) __cold
+void _dev_warn(const struct device *dev, const char *fmt, ...);
+__printf(2, 3) __cold
+void _dev_notice(const struct device *dev, const char *fmt, ...);
+__printf(2, 3) __cold
+void _dev_info(const struct device *dev, const char *fmt, ...);
+
+#else
+
+static inline __printf(3, 0)
+int dev_vprintk_emit(int level, const struct device *dev,
+		     const char *fmt, va_list args)
+{ return 0; }
+static inline __printf(3, 4)
+int dev_printk_emit(int level, const struct device *dev, const char *fmt, ...)
+{ return 0; }
+
+static inline void __dev_printk(const char *level, const struct device *dev,
+				struct va_format *vaf)
+{}
+static inline __printf(3, 4)
+void dev_printk(const char *level, const struct device *dev,
+		 const char *fmt, ...)
+{}
+
+static inline __printf(2, 3)
+void _dev_emerg(const struct device *dev, const char *fmt, ...)
+{}
+static inline __printf(2, 3)
+void _dev_crit(const struct device *dev, const char *fmt, ...)
+{}
+static inline __printf(2, 3)
+void _dev_alert(const struct device *dev, const char *fmt, ...)
+{}
+static inline __printf(2, 3)
+void _dev_err(const struct device *dev, const char *fmt, ...)
+{}
+static inline __printf(2, 3)
+void _dev_warn(const struct device *dev, const char *fmt, ...)
+{}
+static inline __printf(2, 3)
+void _dev_notice(const struct device *dev, const char *fmt, ...)
+{}
+static inline __printf(2, 3)
+void _dev_info(const struct device *dev, const char *fmt, ...)
+{}
+
+#endif
+
+/*
+ * #defines for all the dev_<level> macros to prefix with whatever
+ * possible use of #define dev_fmt(fmt) ...
+ */
+
+#define dev_emerg(dev, fmt, ...)					\
+	_dev_emerg(dev, dev_fmt(fmt), ##__VA_ARGS__)
+#define dev_crit(dev, fmt, ...)						\
+	_dev_crit(dev, dev_fmt(fmt), ##__VA_ARGS__)
+#define dev_alert(dev, fmt, ...)					\
+	_dev_alert(dev, dev_fmt(fmt), ##__VA_ARGS__)
+#define dev_err(dev, fmt, ...)						\
+	_dev_err(dev, dev_fmt(fmt), ##__VA_ARGS__)
+#define dev_warn(dev, fmt, ...)						\
+	_dev_warn(dev, dev_fmt(fmt), ##__VA_ARGS__)
+#define dev_notice(dev, fmt, ...)					\
+	_dev_notice(dev, dev_fmt(fmt), ##__VA_ARGS__)
+#define dev_info(dev, fmt, ...)						\
+	_dev_info(dev, dev_fmt(fmt), ##__VA_ARGS__)
+
+#if defined(CONFIG_DYNAMIC_DEBUG)
+#define dev_dbg(dev, fmt, ...)						\
+	dynamic_dev_dbg(dev, dev_fmt(fmt), ##__VA_ARGS__)
+#elif defined(DEBUG)
+#define dev_dbg(dev, fmt, ...)						\
+	dev_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__)
+#else
+#define dev_dbg(dev, fmt, ...)						\
+({									\
+	if (0)								\
+		dev_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__); \
+})
+#endif
+
+#ifdef CONFIG_PRINTK
+#define dev_level_once(dev_level, dev, fmt, ...)			\
+do {									\
+	static bool __print_once __read_mostly;				\
+									\
+	if (!__print_once) {						\
+		__print_once = true;					\
+		dev_level(dev, fmt, ##__VA_ARGS__);			\
+	}								\
+} while (0)
+#else
+#define dev_level_once(dev_level, dev, fmt, ...)			\
+do {									\
+	if (0)								\
+		dev_level(dev, fmt, ##__VA_ARGS__);			\
+} while (0)
+#endif
+
+#define dev_emerg_once(dev, fmt, ...)					\
+	dev_level_once(dev_emerg, dev, fmt, ##__VA_ARGS__)
+#define dev_alert_once(dev, fmt, ...)					\
+	dev_level_once(dev_alert, dev, fmt, ##__VA_ARGS__)
+#define dev_crit_once(dev, fmt, ...)					\
+	dev_level_once(dev_crit, dev, fmt, ##__VA_ARGS__)
+#define dev_err_once(dev, fmt, ...)					\
+	dev_level_once(dev_err, dev, fmt, ##__VA_ARGS__)
+#define dev_warn_once(dev, fmt, ...)					\
+	dev_level_once(dev_warn, dev, fmt, ##__VA_ARGS__)
+#define dev_notice_once(dev, fmt, ...)					\
+	dev_level_once(dev_notice, dev, fmt, ##__VA_ARGS__)
+#define dev_info_once(dev, fmt, ...)					\
+	dev_level_once(dev_info, dev, fmt, ##__VA_ARGS__)
+#define dev_dbg_once(dev, fmt, ...)					\
+	dev_level_once(dev_dbg, dev, fmt, ##__VA_ARGS__)
+
+#define dev_level_ratelimited(dev_level, dev, fmt, ...)			\
+do {									\
+	static DEFINE_RATELIMIT_STATE(_rs,				\
+				      DEFAULT_RATELIMIT_INTERVAL,	\
+				      DEFAULT_RATELIMIT_BURST);		\
+	if (__ratelimit(&_rs))						\
+		dev_level(dev, fmt, ##__VA_ARGS__);			\
+} while (0)
+
+#define dev_emerg_ratelimited(dev, fmt, ...)				\
+	dev_level_ratelimited(dev_emerg, dev, fmt, ##__VA_ARGS__)
+#define dev_alert_ratelimited(dev, fmt, ...)				\
+	dev_level_ratelimited(dev_alert, dev, fmt, ##__VA_ARGS__)
+#define dev_crit_ratelimited(dev, fmt, ...)				\
+	dev_level_ratelimited(dev_crit, dev, fmt, ##__VA_ARGS__)
+#define dev_err_ratelimited(dev, fmt, ...)				\
+	dev_level_ratelimited(dev_err, dev, fmt, ##__VA_ARGS__)
+#define dev_warn_ratelimited(dev, fmt, ...)				\
+	dev_level_ratelimited(dev_warn, dev, fmt, ##__VA_ARGS__)
+#define dev_notice_ratelimited(dev, fmt, ...)				\
+	dev_level_ratelimited(dev_notice, dev, fmt, ##__VA_ARGS__)
+#define dev_info_ratelimited(dev, fmt, ...)				\
+	dev_level_ratelimited(dev_info, dev, fmt, ##__VA_ARGS__)
+#if defined(CONFIG_DYNAMIC_DEBUG)
+/* descriptor check is first to prevent flooding with "callbacks suppressed" */
+#define dev_dbg_ratelimited(dev, fmt, ...)				\
+do {									\
+	static DEFINE_RATELIMIT_STATE(_rs,				\
+				      DEFAULT_RATELIMIT_INTERVAL,	\
+				      DEFAULT_RATELIMIT_BURST);		\
+	DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt);			\
+	if (DYNAMIC_DEBUG_BRANCH(descriptor) &&				\
+	    __ratelimit(&_rs))						\
+		__dynamic_dev_dbg(&descriptor, dev, dev_fmt(fmt),	\
+				  ##__VA_ARGS__);			\
+} while (0)
+#elif defined(DEBUG)
+#define dev_dbg_ratelimited(dev, fmt, ...)				\
+do {									\
+	static DEFINE_RATELIMIT_STATE(_rs,				\
+				      DEFAULT_RATELIMIT_INTERVAL,	\
+				      DEFAULT_RATELIMIT_BURST);		\
+	if (__ratelimit(&_rs))						\
+		dev_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__); \
+} while (0)
+#else
+#define dev_dbg_ratelimited(dev, fmt, ...)				\
+do {									\
+	if (0)								\
+		dev_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__); \
+} while (0)
+#endif
+
+#ifdef VERBOSE_DEBUG
+#define dev_vdbg	dev_dbg
+#else
+#define dev_vdbg(dev, fmt, ...)						\
+({									\
+	if (0)								\
+		dev_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__); \
+})
+#endif
+
+/*
+ * dev_WARN*() acts like dev_printk(), but with the key difference of
+ * using WARN/WARN_ONCE to include file/line information and a backtrace.
+ */
+#define dev_WARN(dev, format, arg...) \
+	WARN(1, "%s %s: " format, dev_driver_string(dev), dev_name(dev), ## arg);
+
+#define dev_WARN_ONCE(dev, condition, format, arg...) \
+	WARN_ONCE(condition, "%s %s: " format, \
+			dev_driver_string(dev), dev_name(dev), ## arg)
+
+#endif /* _DEVICE_PRINTK_H_ */
include/linux/device.h +1 -216

235 lines not on this page · raw message

Signature · 1 line
2.24.0
author maintainer
#4 lore raw

PATCH 4/6 device.h: move 'struct bus' stuff out to device/bus.h

In reply to Greg Kroah-Hartman

device.h has everything and the kitchen sink when it comes to struct device things, so split out the struct bus things things to a separate .h file to make things easier to maintain and manage over time.

Cc "Rafael J. Wysocki" <[email protected]>
Cc Suzuki K Poulose <[email protected]>
Cc Saravana Kannan <[email protected]>
Cc Heikki Krogerus <[email protected]>
---
 drivers/base/bus.c         |   1 +
 include/linux/device.h     | 265 +---------------------------------
 include/linux/device/bus.h | 288 +++++++++++++++++++++++++++++++++++++
 3 files changed, 290 insertions(+), 264 deletions(-)
 create mode 100644 include/linux/device/bus.h
drivers/base/bus.c +1 -0
index a1d1e8256324..886e9054999a 100644
@@ -9,6 +9,7 @@
  */
 
 #include <linux/async.h>
+#include <linux/device/bus.h>
 #include <linux/device.h>
 #include <linux/module.h>
 #include <linux/errno.h>
include/linux/device.h +1 -264

283 lines not on this page · raw message

include/linux/device/bus.h new file +288 -0

288 lines not on this page · raw message

Signature · 1 line
2.24.0
author maintainer
#5 lore raw

PATCH 5/6 device.h: move 'struct class' stuff out to device/class.h

In reply to Greg Kroah-Hartman

device.h has everything and the kitchen sink when it comes to struct device things, so split out the struct class things things to a separate .h file to make things easier to maintain and manage over time.

Cc "Rafael J. Wysocki" <[email protected]>
Cc Suzuki K Poulose <[email protected]>
Cc Saravana Kannan <[email protected]>
Cc Heikki Krogerus <[email protected]>
---
 drivers/base/class.c         |   1 +
 include/linux/device.h       | 241 +------------------------------
 include/linux/device/class.h | 266 +++++++++++++++++++++++++++++++++++
 3 files changed, 268 insertions(+), 240 deletions(-)
 create mode 100644 include/linux/device/class.h
drivers/base/class.c +1 -0
index d8a6a5864c2e..bcd410e6d70a 100644
@@ -8,6 +8,7 @@
  * Copyright (c) 2003-2004 IBM Corp.
  */
 
+#include <linux/device/class.h>
 #include <linux/device.h>
 #include <linux/module.h>
 #include <linux/init.h>
include/linux/device.h +1 -240

253 lines not on this page · raw message

include/linux/device/class.h new file +266 -0

266 lines not on this page · raw message

Signature · 1 line
2.24.0
author maintainer
#6 lore raw

PATCH 6/6 device.h: move 'struct driver' stuff out to device/driver.h

In reply to Greg Kroah-Hartman

device.h has everything and the kitchen sink when it comes to struct device things, so split out the struct driver things things to a separate .h file to make things easier to maintain and manage over time.

Cc "Rafael J. Wysocki" <[email protected]>
Cc Suzuki K Poulose <[email protected]>
Cc Saravana Kannan <[email protected]>
Cc Heikki Krogerus <[email protected]>
---
 drivers/base/driver.c         |   1 +
 include/linux/device.h        | 272 +------------------------------
 include/linux/device/driver.h | 292 ++++++++++++++++++++++++++++++++++
 init/main.c                   |   2 +-
 4 files changed, 295 insertions(+), 272 deletions(-)
 create mode 100644 include/linux/device/driver.h
drivers/base/driver.c +1 -0
index 4e5ca632f35e..57c68769e157 100644
@@ -8,6 +8,7 @@
  * Copyright (c) 2007 Novell Inc.
  */
 
+#include <linux/device/driver.h>
 #include <linux/device.h>
 #include <linux/module.h>
 #include <linux/errno.h>
include/linux/device.h +1 -271

294 lines not on this page · raw message

include/linux/device/driver.h new file +292 -0

292 lines not on this page · raw message

init/main.c +1 -1
index 91f6ebb30ef0..dc50a803ea8f 100644
@@ -63,7 +63,7 @@
 #include <linux/lockdep.h>
 #include <linux/kmemleak.h>
 #include <linux/pid_namespace.h>
-#include <linux/device.h>
+#include <linux/device/driver.h>
 #include <linux/kthread.h>
 #include <linux/sched.h>
 #include <linux/sched/init.h>
Signature · 1 line
2.24.0
#7 lore raw
In reply to Greg Kroah-Hartman
Quoted 8 lines · Greg Kroah-Hartman

During the 5.4-rc merge Linus complained about the size of device.h and how it can be a pain to merge things into at times. It's also become kind of a "kitchen sink" for anything related to drivers / devices / busses / classes and is the 10th largest include/linux/*.h file by size.

So let's split it up into smaller pieces, moving things out by logical parts where it can be.

Yes please! Took a cursory look at the series (except 1/6) and it looks okay to me. However, didn't check for copy-pastas or anything that was left in device.h that could have been moved out. I'll try to do the latter, later.

-Saravana

Quoted 27 lines

Greg Kroah-Hartman (6):
drivers/base: base.h: add proper copyright and header info device.h: move devtmpfs prototypes out of the file device.h: move dev_printk()-like functions to dev_printk.h device.h: move 'struct bus' stuff out to device/bus.h device.h: move 'struct class' stuff out to device/class.h device.h: move 'struct driver' stuff out to device/driver.h

 drivers/base/base.h           |  19 +
 drivers/base/bus.c            |   1 +
 drivers/base/class.c          |   1 +
 drivers/base/driver.c         |   1 +
 include/linux/dev_printk.h    | 235 ++++++++
 include/linux/device.h        | 999 +---------------------------------
 include/linux/device/bus.h    | 288 ++++++++++
 include/linux/device/class.h  | 266 +++++++++
 include/linux/device/driver.h | 292 ++++++++++
 init/main.c                   |   2 +-
 10 files changed, 1108 insertions(+), 996 deletions(-)
 create mode 100644 include/linux/dev_printk.h
 create mode 100644 include/linux/device/bus.h
 create mode 100644 include/linux/device/class.h
 create mode 100644 include/linux/device/driver.h

--
2.24.0