Skip to content

Commit 5097a69

Browse files
Alexey Dobriyanakpm00
authored andcommitted
extract and use FILE_LINE macro
Extract nifty FILE_LINE useful for printk style debugging: printk("%s\n", FILE_LINE); It should not be used en mass probably because __FILE__ string literals can be merged while FILE_LINE's won't. But for debugging it is what the doctor ordered. Don't add leading and trailing underscores, they're painful to type. Trust me, I've tried both versions. Link: https://lkml.kernel.org/r/ebf12ac4-5a61-4b12-b8b0-1253eb371332@p183 Signed-off-by: Alexey Dobriyan <[email protected]> Cc: Kees Cook <[email protected]> Cc: Takashi Iwai <[email protected]> Cc: Thomas Gleixner <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent c37e56c commit 5097a69

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

include/linux/fortify-string.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ __FORTIFY_INLINE bool fortify_memcpy_chk(__kernel_size_t size,
643643
__q_size_field, #op), \
644644
#op ": detected field-spanning write (size %zu) of single %s (size %zu)\n", \
645645
__fortify_size, \
646-
"field \"" #p "\" at " __FILE__ ":" __stringify(__LINE__), \
646+
"field \"" #p "\" at " FILE_LINE, \
647647
__p_size_field); \
648648
__underlying_##op(p, q, __fortify_size); \
649649
})

include/linux/stringify.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@
99
#define __stringify_1(x...) #x
1010
#define __stringify(x...) __stringify_1(x)
1111

12+
#define FILE_LINE __FILE__ ":" __stringify(__LINE__)
13+
1214
#endif /* !__LINUX_STRINGIFY_H */

include/linux/timer.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ struct timer_list {
7777
.entry = { .next = TIMER_ENTRY_STATIC }, \
7878
.function = (_function), \
7979
.flags = (_flags), \
80-
__TIMER_LOCKDEP_MAP_INITIALIZER( \
81-
__FILE__ ":" __stringify(__LINE__)) \
80+
__TIMER_LOCKDEP_MAP_INITIALIZER(FILE_LINE) \
8281
}
8382

8483
#define DEFINE_TIMER(_name, _function) \

sound/pci/asihpi/hpidebug.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,23 @@ enum { HPI_DEBUG_LEVEL_ERROR = 0, /* always log errors */
2929
the start of each message, eg see linux kernel hpios.h */
3030

3131
#ifdef SOURCEFILE_NAME
32+
#undef FILE_LINE
3233
#define FILE_LINE SOURCEFILE_NAME ":" __stringify(__LINE__) " "
33-
#else
34-
#define FILE_LINE __FILE__ ":" __stringify(__LINE__) " "
3534
#endif
3635

3736
#define HPI_DEBUG_ASSERT(expression) \
3837
do { \
3938
if (!(expression)) { \
4039
printk(KERN_ERR FILE_LINE \
41-
"ASSERT " __stringify(expression)); \
40+
" ASSERT " __stringify(expression)); \
4241
} \
4342
} while (0)
4443

4544
#define HPI_DEBUG_LOG(level, ...) \
4645
do { \
4746
if (hpi_debug_level >= HPI_DEBUG_LEVEL_##level) { \
4847
printk(HPI_DEBUG_FLAG_##level \
49-
FILE_LINE __VA_ARGS__); \
48+
FILE_LINE " " __VA_ARGS__); \
5049
} \
5150
} while (0)
5251

@@ -70,7 +69,7 @@ void hpi_debug_data(u16 *pdata, u32 len);
7069
do { \
7170
if (hpi_debug_level >= HPI_DEBUG_LEVEL_##level) { \
7271
hpi_debug_message(phm, HPI_DEBUG_FLAG_##level \
73-
FILE_LINE __stringify(level)); \
72+
FILE_LINE " " __stringify(level)); \
7473
} \
7574
} while (0)
7675

0 commit comments

Comments
 (0)