device.h: split up into smaller pieces
Greg Kroah-Hartman
maintainercover 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
Greg Kroah-Hartman
maintainerPATCH 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.
--- drivers/base/base.h | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/base/base.h +11 -0
@@ -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
Greg Kroah-Hartman
maintainerPATCH 2/6 device.h: move devtmpfs prototypes out of the file
In reply to Greg Kroah-HartmanThe 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.
--- drivers/base/base.h | 8 ++++++++ include/linux/device.h | 4 ---- 2 files changed, 8 insertions(+), 4 deletions(-)
drivers/base/base.h +8 -0
@@ -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
@@ -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
Greg Kroah-Hartman
maintainerPATCH 3/6 device.h: move dev_printk()-like functions to dev_printk.h
In reply to Greg Kroah-Hartmandevice.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.
--- 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
@@ -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
Greg Kroah-Hartman
maintainerPATCH 4/6 device.h: move 'struct bus' stuff out to device/bus.h
In reply to Greg Kroah-Hartmandevice.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.
--- 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
@@ -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
Greg Kroah-Hartman
maintainerPATCH 5/6 device.h: move 'struct class' stuff out to device/class.h
In reply to Greg Kroah-Hartmandevice.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.
--- 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
@@ -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
Greg Kroah-Hartman
maintainerPATCH 6/6 device.h: move 'struct driver' stuff out to device/driver.h
In reply to Greg Kroah-Hartmandevice.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.
--- 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
@@ -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
@@ -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
Quoted 8 lines · Greg Kroah-Hartman
During the 5.4-rc merge Linus complained about the size of
device.hand 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 largestinclude/linux/*.hfile 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 infodevice.h: move devtmpfs prototypes out of the filedevice.h: move dev_printk()-like functions todev_printk.hdevice.h: move 'struct bus' stuff out todevice/bus.hdevice.h: move 'struct class' stuff out todevice/class.hdevice.h: move 'struct driver' stuff out todevice/driver.hdrivers/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