Skip to content

Commit 663336e

Browse files
JoePerchesgregkh
authored andcommitted
device: Add #define dev_fmt similar to #define pr_fmt
Add a prefixing macro to dev_<level> uses similar to the pr_fmt prefixing macro used in pr_<level> calls. This can help avoid some string duplication in dev_<level> uses. The default, like pr_fmt, is an empty #define dev_fmt(fmt) fmt Rename the existing dev_<level> functions to _dev_<level> and introduce #define dev_<level> _dev_<level> macros that use the new #define dev_fmt Miscellanea: o Consistently use #defines with fmt, ... and ##__VA_ARGS__ o Remove unnecessary externs Signed-off-by: Joe Perches <joe@perches.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 0a50f61 commit 663336e

File tree

2 files changed

+64
-51
lines changed

2 files changed

+64
-51
lines changed

drivers/base/core.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3002,12 +3002,12 @@ void func(const struct device *dev, const char *fmt, ...) \
30023002
} \
30033003
EXPORT_SYMBOL(func);
30043004

3005-
define_dev_printk_level(dev_emerg, KERN_EMERG);
3006-
define_dev_printk_level(dev_alert, KERN_ALERT);
3007-
define_dev_printk_level(dev_crit, KERN_CRIT);
3008-
define_dev_printk_level(dev_err, KERN_ERR);
3009-
define_dev_printk_level(dev_warn, KERN_WARNING);
3010-
define_dev_printk_level(dev_notice, KERN_NOTICE);
3005+
define_dev_printk_level(_dev_emerg, KERN_EMERG);
3006+
define_dev_printk_level(_dev_alert, KERN_ALERT);
3007+
define_dev_printk_level(_dev_crit, KERN_CRIT);
3008+
define_dev_printk_level(_dev_err, KERN_ERR);
3009+
define_dev_printk_level(_dev_warn, KERN_WARNING);
3010+
define_dev_printk_level(_dev_notice, KERN_NOTICE);
30113011
define_dev_printk_level(_dev_info, KERN_INFO);
30123012

30133013
#endif

include/linux/device.h

Lines changed: 58 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,30 +1317,34 @@ struct device_link *device_link_add(struct device *consumer,
13171317
struct device *supplier, u32 flags);
13181318
void device_link_del(struct device_link *link);
13191319

1320+
#ifndef dev_fmt
1321+
#define dev_fmt(fmt) fmt
1322+
#endif
1323+
13201324
#ifdef CONFIG_PRINTK
13211325

1322-
extern __printf(3, 0)
1326+
__printf(3, 0)
13231327
int dev_vprintk_emit(int level, const struct device *dev,
13241328
const char *fmt, va_list args);
1325-
extern __printf(3, 4)
1329+
__printf(3, 4)
13261330
int dev_printk_emit(int level, const struct device *dev, const char *fmt, ...);
13271331

1328-
extern __printf(3, 4)
1332+
__printf(3, 4)
13291333
void dev_printk(const char *level, const struct device *dev,
13301334
const char *fmt, ...);
1331-
extern __printf(2, 3)
1332-
void dev_emerg(const struct device *dev, const char *fmt, ...);
1333-
extern __printf(2, 3)
1334-
void dev_alert(const struct device *dev, const char *fmt, ...);
1335-
extern __printf(2, 3)
1336-
void dev_crit(const struct device *dev, const char *fmt, ...);
1337-
extern __printf(2, 3)
1338-
void dev_err(const struct device *dev, const char *fmt, ...);
1339-
extern __printf(2, 3)
1340-
void dev_warn(const struct device *dev, const char *fmt, ...);
1341-
extern __printf(2, 3)
1342-
void dev_notice(const struct device *dev, const char *fmt, ...);
1343-
extern __printf(2, 3)
1335+
__printf(2, 3)
1336+
void _dev_emerg(const struct device *dev, const char *fmt, ...);
1337+
__printf(2, 3)
1338+
void _dev_alert(const struct device *dev, const char *fmt, ...);
1339+
__printf(2, 3)
1340+
void _dev_crit(const struct device *dev, const char *fmt, ...);
1341+
__printf(2, 3)
1342+
void _dev_err(const struct device *dev, const char *fmt, ...);
1343+
__printf(2, 3)
1344+
void _dev_warn(const struct device *dev, const char *fmt, ...);
1345+
__printf(2, 3)
1346+
void _dev_notice(const struct device *dev, const char *fmt, ...);
1347+
__printf(2, 3)
13441348
void _dev_info(const struct device *dev, const char *fmt, ...);
13451349

13461350
#else
@@ -1358,26 +1362,26 @@ static inline void __dev_printk(const char *level, const struct device *dev,
13581362
{}
13591363
static inline __printf(3, 4)
13601364
void dev_printk(const char *level, const struct device *dev,
1361-
const char *fmt, ...)
1365+
const char *fmt, ...)
13621366
{}
13631367

13641368
static inline __printf(2, 3)
1365-
void dev_emerg(const struct device *dev, const char *fmt, ...)
1369+
void _dev_emerg(const struct device *dev, const char *fmt, ...)
13661370
{}
13671371
static inline __printf(2, 3)
1368-
void dev_crit(const struct device *dev, const char *fmt, ...)
1372+
void _dev_crit(const struct device *dev, const char *fmt, ...)
13691373
{}
13701374
static inline __printf(2, 3)
1371-
void dev_alert(const struct device *dev, const char *fmt, ...)
1375+
void _dev_alert(const struct device *dev, const char *fmt, ...)
13721376
{}
13731377
static inline __printf(2, 3)
1374-
void dev_err(const struct device *dev, const char *fmt, ...)
1378+
void _dev_err(const struct device *dev, const char *fmt, ...)
13751379
{}
13761380
static inline __printf(2, 3)
1377-
void dev_warn(const struct device *dev, const char *fmt, ...)
1381+
void _dev_warn(const struct device *dev, const char *fmt, ...)
13781382
{}
13791383
static inline __printf(2, 3)
1380-
void dev_notice(const struct device *dev, const char *fmt, ...)
1384+
void _dev_notice(const struct device *dev, const char *fmt, ...)
13811385
{}
13821386
static inline __printf(2, 3)
13831387
void _dev_info(const struct device *dev, const char *fmt, ...)
@@ -1386,27 +1390,36 @@ void _dev_info(const struct device *dev, const char *fmt, ...)
13861390
#endif
13871391

13881392
/*
1389-
* Stupid hackaround for existing uses of non-printk uses dev_info
1390-
*
1391-
* Note that the definition of dev_info below is actually _dev_info
1392-
* and a macro is used to avoid redefining dev_info
1393+
* #defines for all the dev_<level> macros to prefix with whatever
1394+
* possible use of #define dev_fmt(fmt) ...
13931395
*/
13941396

1395-
#define dev_info(dev, fmt, arg...) _dev_info(dev, fmt, ##arg)
1397+
#define dev_emerg(dev, fmt, ...) \
1398+
_dev_emerg(dev, dev_fmt(fmt), ##__VA_ARGS__)
1399+
#define dev_crit(dev, fmt, ...) \
1400+
_dev_crit(dev, dev_fmt(fmt), ##__VA_ARGS__)
1401+
#define dev_alert(dev, fmt, ...) \
1402+
_dev_alert(dev, dev_fmt(fmt), ##__VA_ARGS__)
1403+
#define dev_err(dev, fmt, ...) \
1404+
_dev_err(dev, dev_fmt(fmt), ##__VA_ARGS__)
1405+
#define dev_warn(dev, fmt, ...) \
1406+
_dev_warn(dev, dev_fmt(fmt), ##__VA_ARGS__)
1407+
#define dev_notice(dev, fmt, ...) \
1408+
_dev_notice(dev, dev_fmt(fmt), ##__VA_ARGS__)
1409+
#define dev_info(dev, fmt, ...) \
1410+
_dev_info(dev, dev_fmt(fmt), ##__VA_ARGS__)
13961411

13971412
#if defined(CONFIG_DYNAMIC_DEBUG)
1398-
#define dev_dbg(dev, format, ...) \
1399-
do { \
1400-
dynamic_dev_dbg(dev, format, ##__VA_ARGS__); \
1401-
} while (0)
1413+
#define dev_dbg(dev, fmt, ...) \
1414+
dynamic_dev_dbg(dev, dev_fmt(fmt), ##__VA_ARGS__)
14021415
#elif defined(DEBUG)
1403-
#define dev_dbg(dev, format, arg...) \
1404-
dev_printk(KERN_DEBUG, dev, format, ##arg)
1416+
#define dev_dbg(dev, fmt, ...) \
1417+
dev_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__)
14051418
#else
1406-
#define dev_dbg(dev, format, arg...) \
1407-
({ \
1408-
if (0) \
1409-
dev_printk(KERN_DEBUG, dev, format, ##arg); \
1419+
#define dev_dbg(dev, fmt, ...) \
1420+
({ \
1421+
if (0) \
1422+
dev_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__); \
14101423
})
14111424
#endif
14121425

@@ -1478,7 +1491,7 @@ do { \
14781491
DEFINE_DYNAMIC_DEBUG_METADATA(descriptor, fmt); \
14791492
if (unlikely(descriptor.flags & _DPRINTK_FLAGS_PRINT) && \
14801493
__ratelimit(&_rs)) \
1481-
__dynamic_dev_dbg(&descriptor, dev, fmt, \
1494+
__dynamic_dev_dbg(&descriptor, dev, dev_fmt(fmt), \
14821495
##__VA_ARGS__); \
14831496
} while (0)
14841497
#elif defined(DEBUG)
@@ -1488,23 +1501,23 @@ do { \
14881501
DEFAULT_RATELIMIT_INTERVAL, \
14891502
DEFAULT_RATELIMIT_BURST); \
14901503
if (__ratelimit(&_rs)) \
1491-
dev_printk(KERN_DEBUG, dev, fmt, ##__VA_ARGS__); \
1504+
dev_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__); \
14921505
} while (0)
14931506
#else
14941507
#define dev_dbg_ratelimited(dev, fmt, ...) \
14951508
do { \
14961509
if (0) \
1497-
dev_printk(KERN_DEBUG, dev, fmt, ##__VA_ARGS__); \
1510+
dev_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__); \
14981511
} while (0)
14991512
#endif
15001513

15011514
#ifdef VERBOSE_DEBUG
15021515
#define dev_vdbg dev_dbg
15031516
#else
1504-
#define dev_vdbg(dev, format, arg...) \
1505-
({ \
1506-
if (0) \
1507-
dev_printk(KERN_DEBUG, dev, format, ##arg); \
1517+
#define dev_vdbg(dev, fmt, ...) \
1518+
({ \
1519+
if (0) \
1520+
dev_printk(KERN_DEBUG, dev, dev_fmt(fmt), ##__VA_ARGS__); \
15081521
})
15091522
#endif
15101523

0 commit comments

Comments
 (0)