Skip to content

Commit 4b183dd

Browse files
committed
mm, slab: cleanup slab_bug() parameters
slab_err() has variadic printf arguments but instead of passing them to slab_bug() it does vsnprintf() to a buffer and passes %s, buf. To allow passing them directly, turn slab_bug() to __slab_bug() with a va_list parameter, and slab_bug() a wrapper with fmt, ... parameters. Then slab_err() can call __slab_bug() without the intermediate buffer. Also constify fmt everywhere, which also simplifies object_err()'s call to slab_bug(). Signed-off-by: Vlastimil Babka <[email protected]> Reviewed-by: Harry Yoo <[email protected]>
1 parent 3f6f32b commit 4b183dd

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

mm/slub.c

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,12 +1017,12 @@ void skip_orig_size_check(struct kmem_cache *s, const void *object)
10171017
set_orig_size(s, (void *)object, s->object_size);
10181018
}
10191019

1020-
static void slab_bug(struct kmem_cache *s, char *fmt, ...)
1020+
static void __slab_bug(struct kmem_cache *s, const char *fmt, va_list argsp)
10211021
{
10221022
struct va_format vaf;
10231023
va_list args;
10241024

1025-
va_start(args, fmt);
1025+
va_copy(args, argsp);
10261026
vaf.fmt = fmt;
10271027
vaf.va = &args;
10281028
pr_err("=============================================================================\n");
@@ -1031,8 +1031,17 @@ static void slab_bug(struct kmem_cache *s, char *fmt, ...)
10311031
va_end(args);
10321032
}
10331033

1034+
static void slab_bug(struct kmem_cache *s, const char *fmt, ...)
1035+
{
1036+
va_list args;
1037+
1038+
va_start(args, fmt);
1039+
__slab_bug(s, fmt, args);
1040+
va_end(args);
1041+
}
1042+
10341043
__printf(2, 3)
1035-
static void slab_fix(struct kmem_cache *s, char *fmt, ...)
1044+
static void slab_fix(struct kmem_cache *s, const char *fmt, ...)
10361045
{
10371046
struct va_format vaf;
10381047
va_list args;
@@ -1088,12 +1097,12 @@ static void print_trailer(struct kmem_cache *s, struct slab *slab, u8 *p)
10881097
}
10891098

10901099
static void object_err(struct kmem_cache *s, struct slab *slab,
1091-
u8 *object, char *reason)
1100+
u8 *object, const char *reason)
10921101
{
10931102
if (slab_add_kunit_errors())
10941103
return;
10951104

1096-
slab_bug(s, "%s", reason);
1105+
slab_bug(s, reason);
10971106
print_trailer(s, slab, object);
10981107
add_taint(TAINT_BAD_PAGE, LOCKDEP_NOW_UNRELIABLE);
10991108

@@ -1129,15 +1138,14 @@ static __printf(3, 4) void slab_err(struct kmem_cache *s, struct slab *slab,
11291138
const char *fmt, ...)
11301139
{
11311140
va_list args;
1132-
char buf[100];
11331141

11341142
if (slab_add_kunit_errors())
11351143
return;
11361144

11371145
va_start(args, fmt);
1138-
vsnprintf(buf, sizeof(buf), fmt, args);
1146+
__slab_bug(s, fmt, args);
11391147
va_end(args);
1140-
slab_bug(s, "%s", buf);
1148+
11411149
__slab_err(slab);
11421150
}
11431151

@@ -1175,7 +1183,7 @@ static void init_object(struct kmem_cache *s, void *object, u8 val)
11751183
s->inuse - poison_size);
11761184
}
11771185

1178-
static void restore_bytes(struct kmem_cache *s, char *message, u8 data,
1186+
static void restore_bytes(struct kmem_cache *s, const char *message, u8 data,
11791187
void *from, void *to)
11801188
{
11811189
slab_fix(s, "Restoring %s 0x%p-0x%p=0x%x", message, from, to - 1, data);
@@ -1190,7 +1198,7 @@ static void restore_bytes(struct kmem_cache *s, char *message, u8 data,
11901198

11911199
static pad_check_attributes int
11921200
check_bytes_and_report(struct kmem_cache *s, struct slab *slab,
1193-
u8 *object, char *what, u8 *start, unsigned int value,
1201+
u8 *object, const char *what, u8 *start, unsigned int value,
11941202
unsigned int bytes, bool slab_obj_print)
11951203
{
11961204
u8 *fault;

0 commit comments

Comments
 (0)