Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

printk: Provide helper for message prepending

In order to support prepending different texts to printk
messages, split out the prepending code into a helper
function.

Signed-off-by: John Ogness <john.ogness@linutronix.de>
Reviewed-by: Petr Mladek <pmladek@suse.com>
Link: https://lore.kernel.org/r/20240904120536.115780-11-john.ogness@linutronix.de
Signed-off-by: Petr Mladek <pmladek@suse.com>

authored by

John Ogness and committed by
Petr Mladek
75d43037 13189fa7

+25 -11
+25 -11
kernel/printk/printk.c
··· 2843 2843 #ifdef CONFIG_PRINTK 2844 2844 2845 2845 /* 2846 - * Prepend the message in @pmsg->pbufs->outbuf with a "dropped message". This 2847 - * is achieved by shifting the existing message over and inserting the dropped 2848 - * message. 2846 + * Prepend the message in @pmsg->pbufs->outbuf. This is achieved by shifting 2847 + * the existing message over and inserting the scratchbuf message. 2849 2848 * 2850 - * @pmsg is the printk message to prepend. 2849 + * @pmsg is the original printk message. 2850 + * @fmt is the printf format of the message which will prepend the existing one. 2851 2851 * 2852 - * @dropped is the dropped count to report in the dropped message. 2853 - * 2854 - * If the message text in @pmsg->pbufs->outbuf does not have enough space for 2855 - * the dropped message, the message text will be sufficiently truncated. 2852 + * If there is not enough space in @pmsg->pbufs->outbuf, the existing 2853 + * message text will be sufficiently truncated. 2856 2854 * 2857 2855 * If @pmsg->pbufs->outbuf is modified, @pmsg->outbuf_len is updated. 2858 2856 */ 2859 - void console_prepend_dropped(struct printk_message *pmsg, unsigned long dropped) 2857 + __printf(2, 3) 2858 + static void console_prepend_message(struct printk_message *pmsg, const char *fmt, ...) 2860 2859 { 2861 2860 struct printk_buffers *pbufs = pmsg->pbufs; 2862 2861 const size_t scratchbuf_sz = sizeof(pbufs->scratchbuf); 2863 2862 const size_t outbuf_sz = sizeof(pbufs->outbuf); 2864 2863 char *scratchbuf = &pbufs->scratchbuf[0]; 2865 2864 char *outbuf = &pbufs->outbuf[0]; 2865 + va_list args; 2866 2866 size_t len; 2867 2867 2868 - len = scnprintf(scratchbuf, scratchbuf_sz, 2869 - "** %lu printk messages dropped **\n", dropped); 2868 + va_start(args, fmt); 2869 + len = vscnprintf(scratchbuf, scratchbuf_sz, fmt, args); 2870 + va_end(args); 2870 2871 2871 2872 /* 2872 2873 * Make sure outbuf is sufficiently large before prepending. ··· 2887 2886 memmove(outbuf + len, outbuf, pmsg->outbuf_len + 1); 2888 2887 memcpy(outbuf, scratchbuf, len); 2889 2888 pmsg->outbuf_len += len; 2889 + } 2890 + 2891 + /* 2892 + * Prepend the message in @pmsg->pbufs->outbuf with a "dropped message". 2893 + * @pmsg->outbuf_len is updated appropriately. 2894 + * 2895 + * @pmsg is the printk message to prepend. 2896 + * 2897 + * @dropped is the dropped count to report in the dropped message. 2898 + */ 2899 + void console_prepend_dropped(struct printk_message *pmsg, unsigned long dropped) 2900 + { 2901 + console_prepend_message(pmsg, "** %lu printk messages dropped **\n", dropped); 2890 2902 } 2891 2903 2892 2904 /*