Skip to content

Commit 12e3342

Browse files
committed
kconfig: remove unneeded buffer allocation in zconf_initscan()
In Kconfig, there is a stack to save the lexer state for each inclusion level. Currently, it operates as an empty stack, with the 'current_buf' always pointing to an empty buffer. There is no need to preallocate the buffer. Change it to a full stack. Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
1 parent b401b62 commit 12e3342

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

scripts/kconfig/lexer.l

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,6 @@ void zconf_initscan(const char *name)
391391
exit(1);
392392
}
393393

394-
current_buf = xmalloc(sizeof(*current_buf));
395-
memset(current_buf, 0, sizeof(*current_buf));
396-
397394
current_file = file_lookup(name);
398395
yylineno = 1;
399396
}
@@ -403,18 +400,17 @@ void zconf_nextfile(const char *name)
403400
struct file *iter;
404401
struct file *file = file_lookup(name);
405402
struct buffer *buf = xmalloc(sizeof(*buf));
406-
memset(buf, 0, sizeof(*buf));
407403

408-
current_buf->state = YY_CURRENT_BUFFER;
404+
buf->state = YY_CURRENT_BUFFER;
405+
buf->parent = current_buf;
406+
current_buf = buf;
409407
yyin = zconf_fopen(file->name);
410408
if (!yyin) {
411409
fprintf(stderr, "%s:%d: can't open file \"%s\"\n",
412410
zconf_curname(), zconf_lineno(), file->name);
413411
exit(1);
414412
}
415413
yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
416-
buf->parent = current_buf;
417-
current_buf = buf;
418414

419415
current_file->lineno = yylineno;
420416
file->parent = current_file;
@@ -441,20 +437,21 @@ void zconf_nextfile(const char *name)
441437

442438
static void zconf_endfile(void)
443439
{
444-
struct buffer *parent;
440+
struct buffer *tmp;
445441

446442
current_file = current_file->parent;
447443
if (current_file)
448444
yylineno = current_file->lineno;
449445

450-
parent = current_buf->parent;
451-
if (parent) {
452-
fclose(yyin);
453-
yy_delete_buffer(YY_CURRENT_BUFFER);
454-
yy_switch_to_buffer(parent->state);
455-
}
456-
free(current_buf);
457-
current_buf = parent;
446+
if (!current_buf)
447+
return;
448+
449+
fclose(yyin);
450+
yy_delete_buffer(YY_CURRENT_BUFFER);
451+
yy_switch_to_buffer(current_buf->state);
452+
tmp = current_buf;
453+
current_buf = current_buf->parent;
454+
free(tmp);
458455
}
459456

460457
int zconf_lineno(void)

0 commit comments

Comments
 (0)