Skip to content

Commit 39ced19

Browse files
andy-shevakpm00
authored andcommitted
lib/vsprintf: split out sprintf() and friends
Patch series "lib/vsprintf: Rework header inclusions", v3. Some patches that reduce the mess with the header inclusions related to vsprintf.c module. Each patch has its own description, and has no dependencies to each other, except the collisions over modifications of the same places. Hence the series. This patch (of 2): kernel.h is being used as a dump for all kinds of stuff for a long time. sprintf() and friends are used in many drivers without need of the full kernel.h dependency train with it. Here is the attempt on cleaning it up by splitting out sprintf() and friends. Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Andy Shevchenko <[email protected]> Reviewed-by: Petr Mladek <[email protected]> Cc: Alexander Potapenko <[email protected]> Cc: Dmitry Vyukov <[email protected]> Cc: Marco Elver <[email protected]> Cc: Rasmus Villemoes <[email protected]> Cc: Sergey Senozhatsky <[email protected]> Cc: Steven Rostedt (Google) <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent a7031f1 commit 39ced19

File tree

4 files changed

+28
-29
lines changed

4 files changed

+28
-29
lines changed

include/linux/kernel.h

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <linux/panic.h>
3030
#include <linux/printk.h>
3131
#include <linux/build_bug.h>
32+
#include <linux/sprintf.h>
3233
#include <linux/static_call_types.h>
3334
#include <linux/instruction_pointer.h>
3435
#include <asm/byteorder.h>
@@ -203,35 +204,6 @@ static inline void might_fault(void) { }
203204

204205
void do_exit(long error_code) __noreturn;
205206

206-
extern int num_to_str(char *buf, int size,
207-
unsigned long long num, unsigned int width);
208-
209-
/* lib/printf utilities */
210-
211-
extern __printf(2, 3) int sprintf(char *buf, const char * fmt, ...);
212-
extern __printf(2, 0) int vsprintf(char *buf, const char *, va_list);
213-
extern __printf(3, 4)
214-
int snprintf(char *buf, size_t size, const char *fmt, ...);
215-
extern __printf(3, 0)
216-
int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
217-
extern __printf(3, 4)
218-
int scnprintf(char *buf, size_t size, const char *fmt, ...);
219-
extern __printf(3, 0)
220-
int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
221-
extern __printf(2, 3) __malloc
222-
char *kasprintf(gfp_t gfp, const char *fmt, ...);
223-
extern __printf(2, 0) __malloc
224-
char *kvasprintf(gfp_t gfp, const char *fmt, va_list args);
225-
extern __printf(2, 0)
226-
const char *kvasprintf_const(gfp_t gfp, const char *fmt, va_list args);
227-
228-
extern __scanf(2, 3)
229-
int sscanf(const char *, const char *, ...);
230-
extern __scanf(2, 0)
231-
int vsscanf(const char *, const char *, va_list);
232-
233-
extern int no_hash_pointers_enable(char *str);
234-
235207
extern int get_option(char **str, int *pint);
236208
extern char *get_options(const char *str, int nints, int *ints);
237209
extern unsigned long long memparse(const char *ptr, char **retptr);

include/linux/sprintf.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
#ifndef _LINUX_KERNEL_SPRINTF_H_
3+
#define _LINUX_KERNEL_SPRINTF_H_
4+
5+
#include <linux/compiler_attributes.h>
6+
#include <linux/types.h>
7+
8+
int num_to_str(char *buf, int size, unsigned long long num, unsigned int width);
9+
10+
__printf(2, 3) int sprintf(char *buf, const char * fmt, ...);
11+
__printf(2, 0) int vsprintf(char *buf, const char *, va_list);
12+
__printf(3, 4) int snprintf(char *buf, size_t size, const char *fmt, ...);
13+
__printf(3, 0) int vsnprintf(char *buf, size_t size, const char *fmt, va_list args);
14+
__printf(3, 4) int scnprintf(char *buf, size_t size, const char *fmt, ...);
15+
__printf(3, 0) int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
16+
__printf(2, 3) __malloc char *kasprintf(gfp_t gfp, const char *fmt, ...);
17+
__printf(2, 0) __malloc char *kvasprintf(gfp_t gfp, const char *fmt, va_list args);
18+
__printf(2, 0) const char *kvasprintf_const(gfp_t gfp, const char *fmt, va_list args);
19+
20+
__scanf(2, 3) int sscanf(const char *, const char *, ...);
21+
__scanf(2, 0) int vsscanf(const char *, const char *, va_list);
22+
23+
int no_hash_pointers_enable(char *str);
24+
25+
#endif /* _LINUX_KERNEL_SPRINTF_H */

lib/test_printf.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/random.h>
1313
#include <linux/rtc.h>
1414
#include <linux/slab.h>
15+
#include <linux/sprintf.h>
1516
#include <linux/string.h>
1617

1718
#include <linux/bitmap.h>

lib/vsprintf.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <linux/dcache.h>
3535
#include <linux/cred.h>
3636
#include <linux/rtc.h>
37+
#include <linux/sprintf.h>
3738
#include <linux/time.h>
3839
#include <linux/uuid.h>
3940
#include <linux/of.h>

0 commit comments

Comments
 (0)