Skip to content

Commit 49aab5e

Browse files
committed
kallsyms: provide a bigger buffer to report the real length
With a buffer size close to `KSYM_NAME_LEN`, the "symbol too big" report in `read_symbol` does not really provide information to the user. Therefore, use a bigger buffer. Furthermore, add a static assert to keep things matched. This will be rebased/reorganized in `rust-next` as a new set of kallsyms patches that makes more sense (instead of putting Boqun's patch last of the three, it will go first in the series as an improvement to the mainline kernel). This commit synchronizes with those changes. Fixes: d895436 ("script: kallsyms: Use the correct buffer size for symbols") Signed-off-by: Miguel Ojeda <[email protected]>
1 parent 426f7e4 commit 49aab5e

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

scripts/kallsyms.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,13 @@
3232

3333
#define KSYM_NAME_LEN 512
3434

35+
/* A substantially bigger size than the current maximum. */
36+
#define KSYM_NAME_LEN_BUFFER 2048
37+
_Static_assert(
38+
KSYM_NAME_LEN_BUFFER == KSYM_NAME_LEN * 4,
39+
"Please keep KSYM_NAME_LEN_BUFFER in sync with KSYM_NAME_LEN"
40+
);
41+
3542
struct sym_entry {
3643
unsigned long long addr;
3744
unsigned int len;
@@ -200,15 +207,15 @@ static void check_symbol_range(const char *sym, unsigned long long addr,
200207

201208
static struct sym_entry *read_symbol(FILE *in)
202209
{
203-
char name[KSYM_NAME_LEN+1], type;
210+
char name[KSYM_NAME_LEN_BUFFER+1], type;
204211
unsigned long long addr;
205212
unsigned int len;
206213
struct sym_entry *sym;
207214
int rc;
208215

209-
rc = fscanf(in, "%llx %c %" _stringify(KSYM_NAME_LEN) "s\n", &addr, &type, name);
216+
rc = fscanf(in, "%llx %c %" _stringify(KSYM_NAME_LEN_BUFFER) "s\n", &addr, &type, name);
210217
if (rc != 3) {
211-
if (rc != EOF && fgets(name, KSYM_NAME_LEN + 1, in) == NULL)
218+
if (rc != EOF && fgets(name, KSYM_NAME_LEN_BUFFER + 1, in) == NULL)
212219
fprintf(stderr, "Read error or end of file.\n");
213220
return NULL;
214221
}

0 commit comments

Comments
 (0)