Skip to content

Commit fb13cb8

Browse files
committed
printk: Introduce kmsg_dump_reason_str()
The pstore subsystem already had a private version of this function. With the coming addition of the pstore/zone driver, this needs to be shared. As it really should live with printk, move it there instead. Link: https://lore.kernel.org/lkml/[email protected]/ Acked-by: Petr Mladek <[email protected]> Acked-by: Sergey Senozhatsky <[email protected]> Reviewed-by: Pavel Tatashin <[email protected]> Signed-off-by: Kees Cook <[email protected]>
1 parent b1f6f16 commit fb13cb8

File tree

3 files changed

+25
-17
lines changed

3 files changed

+25
-17
lines changed

fs/pstore/platform.c

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -135,22 +135,6 @@ enum pstore_type_id pstore_name_to_type(const char *name)
135135
}
136136
EXPORT_SYMBOL_GPL(pstore_name_to_type);
137137

138-
static const char *get_reason_str(enum kmsg_dump_reason reason)
139-
{
140-
switch (reason) {
141-
case KMSG_DUMP_PANIC:
142-
return "Panic";
143-
case KMSG_DUMP_OOPS:
144-
return "Oops";
145-
case KMSG_DUMP_EMERG:
146-
return "Emergency";
147-
case KMSG_DUMP_SHUTDOWN:
148-
return "Shutdown";
149-
default:
150-
return "Unknown";
151-
}
152-
}
153-
154138
static void pstore_timer_kick(void)
155139
{
156140
if (pstore_update_ms < 0)
@@ -403,7 +387,7 @@ static void pstore_dump(struct kmsg_dumper *dumper,
403387
unsigned int part = 1;
404388
int ret;
405389

406-
why = get_reason_str(reason);
390+
why = kmsg_dump_reason_str(reason);
407391

408392
if (down_trylock(&psinfo->buf_lock)) {
409393
/* Failed to acquire lock: give up if we cannot wait. */

include/linux/kmsg_dump.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ void kmsg_dump_rewind(struct kmsg_dumper *dumper);
7070
int kmsg_dump_register(struct kmsg_dumper *dumper);
7171

7272
int kmsg_dump_unregister(struct kmsg_dumper *dumper);
73+
74+
const char *kmsg_dump_reason_str(enum kmsg_dump_reason reason);
7375
#else
7476
static inline void kmsg_dump(enum kmsg_dump_reason reason)
7577
{
@@ -111,6 +113,11 @@ static inline int kmsg_dump_unregister(struct kmsg_dumper *dumper)
111113
{
112114
return -EINVAL;
113115
}
116+
117+
static inline const char *kmsg_dump_reason_str(enum kmsg_dump_reason reason)
118+
{
119+
return "Disabled";
120+
}
114121
#endif
115122

116123
#endif /* _LINUX_KMSG_DUMP_H */

kernel/printk/printk.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3144,6 +3144,23 @@ EXPORT_SYMBOL_GPL(kmsg_dump_unregister);
31443144
static bool always_kmsg_dump;
31453145
module_param_named(always_kmsg_dump, always_kmsg_dump, bool, S_IRUGO | S_IWUSR);
31463146

3147+
const char *kmsg_dump_reason_str(enum kmsg_dump_reason reason)
3148+
{
3149+
switch (reason) {
3150+
case KMSG_DUMP_PANIC:
3151+
return "Panic";
3152+
case KMSG_DUMP_OOPS:
3153+
return "Oops";
3154+
case KMSG_DUMP_EMERG:
3155+
return "Emergency";
3156+
case KMSG_DUMP_SHUTDOWN:
3157+
return "Shutdown";
3158+
default:
3159+
return "Unknown";
3160+
}
3161+
}
3162+
EXPORT_SYMBOL_GPL(kmsg_dump_reason_str);
3163+
31473164
/**
31483165
* kmsg_dump - dump kernel log to kernel message dumpers.
31493166
* @reason: the reason (oops, panic etc) for dumping

0 commit comments

Comments
 (0)