extract and use FILE_LINE macro
authorAlexey Dobriyan <adobriyan@gmail.com>
Sat, 16 Sep 2023 18:21:31 +0000 (21:21 +0300)
committerAndrew Morton <akpm@linux-foundation.org>
Wed, 18 Oct 2023 21:43:21 +0000 (14:43 -0700)
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 <adobriyan@gmail.com>
Cc: Kees Cook <keescook@chromium.org>
Cc: Takashi Iwai <tiwai@suse.de>
Cc: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/fortify-string.h
include/linux/stringify.h
include/linux/timer.h
sound/pci/asihpi/hpidebug.h

index da51a83b28293c4229a4585c7abd5e0cf0f8ba51..442ee9170259f2a4da0876d9c416e70f2b4593c7 100644 (file)
@@ -643,7 +643,7 @@ __FORTIFY_INLINE bool fortify_memcpy_chk(__kernel_size_t size,
                                     __q_size_field, #op),              \
                  #op ": detected field-spanning write (size %zu) of single %s (size %zu)\n", \
                  __fortify_size,                                       \
-                 "field \"" #p "\" at " __FILE__ ":" __stringify(__LINE__), \
+                 "field \"" #p "\" at " FILE_LINE,                     \
                  __p_size_field);                                      \
        __underlying_##op(p, q, __fortify_size);                        \
 })
index 841cec8ed525e38eea1fea8c3246fa9e4bbde818..0e84cbe652709d7053f5755401dc7dbed8f71584 100644 (file)
@@ -9,4 +9,6 @@
 #define __stringify_1(x...)    #x
 #define __stringify(x...)      __stringify_1(x)
 
+#define FILE_LINE      __FILE__ ":" __stringify(__LINE__)
+
 #endif /* !__LINUX_STRINGIFY_H */
index 9162f275819a780def8efeb98cc4b553e1c44d28..26a545bb0153c031e2253efd7d88177f6fb883f4 100644 (file)
@@ -77,8 +77,7 @@ struct timer_list {
                .entry = { .next = TIMER_ENTRY_STATIC },        \
                .function = (_function),                        \
                .flags = (_flags),                              \
-               __TIMER_LOCKDEP_MAP_INITIALIZER(                \
-                       __FILE__ ":" __stringify(__LINE__))     \
+               __TIMER_LOCKDEP_MAP_INITIALIZER(FILE_LINE)      \
        }
 
 #define DEFINE_TIMER(_name, _function)                         \
index c24ed69eb74314406274a5f52f1d12712a0d83e2..c6dfc229213d50ae92efe58578a7dd07ce404c9b 100644 (file)
@@ -29,16 +29,15 @@ enum { HPI_DEBUG_LEVEL_ERROR = 0,   /* always log errors */
    the start of each message, eg see linux kernel hpios.h */
 
 #ifdef SOURCEFILE_NAME
+#undef FILE_LINE
 #define FILE_LINE  SOURCEFILE_NAME ":" __stringify(__LINE__) " "
-#else
-#define FILE_LINE  __FILE__ ":" __stringify(__LINE__) " "
 #endif
 
 #define HPI_DEBUG_ASSERT(expression) \
        do { \
                if (!(expression)) { \
                        printk(KERN_ERR  FILE_LINE \
-                               "ASSERT " __stringify(expression)); \
+                               " ASSERT " __stringify(expression)); \
                } \
        } while (0)
 
@@ -46,7 +45,7 @@ enum { HPI_DEBUG_LEVEL_ERROR = 0,     /* always log errors */
        do { \
                if (hpi_debug_level >= HPI_DEBUG_LEVEL_##level) { \
                        printk(HPI_DEBUG_FLAG_##level \
-                       FILE_LINE  __VA_ARGS__); \
+                       FILE_LINE " " __VA_ARGS__); \
                } \
        } while (0)
 
@@ -70,7 +69,7 @@ void hpi_debug_data(u16 *pdata, u32 len);
        do { \
                if (hpi_debug_level >= HPI_DEBUG_LEVEL_##level) { \
                        hpi_debug_message(phm, HPI_DEBUG_FLAG_##level \
-                               FILE_LINE __stringify(level)); \
+                               FILE_LINE " " __stringify(level)); \
                } \
        } while (0)