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.

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>

+13 -16
+13 -16
scripts/kconfig/lexer.l
··· 391 391 exit(1); 392 392 } 393 393 394 - current_buf = xmalloc(sizeof(*current_buf)); 395 - memset(current_buf, 0, sizeof(*current_buf)); 396 - 397 394 current_file = file_lookup(name); 398 395 yylineno = 1; 399 396 } ··· 400 403 struct file *iter; 401 404 struct file *file = file_lookup(name); 402 405 struct buffer *buf = xmalloc(sizeof(*buf)); 403 - memset(buf, 0, sizeof(*buf)); 404 406 405 - current_buf->state = YY_CURRENT_BUFFER; 407 + buf->state = YY_CURRENT_BUFFER; 408 + buf->parent = current_buf; 409 + current_buf = buf; 406 410 yyin = zconf_fopen(file->name); 407 411 if (!yyin) { 408 412 fprintf(stderr, "%s:%d: can't open file \"%s\"\n", ··· 411 413 exit(1); 412 414 } 413 415 yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE)); 414 - buf->parent = current_buf; 415 - current_buf = buf; 416 416 417 417 current_file->lineno = yylineno; 418 418 file->parent = current_file; ··· 437 441 438 442 static void zconf_endfile(void) 439 443 { 440 - struct buffer *parent; 444 + struct buffer *tmp; 441 445 442 446 current_file = current_file->parent; 443 447 if (current_file) 444 448 yylineno = current_file->lineno; 445 449 446 - parent = current_buf->parent; 447 - if (parent) { 448 - fclose(yyin); 449 - yy_delete_buffer(YY_CURRENT_BUFFER); 450 - yy_switch_to_buffer(parent->state); 451 - } 452 - free(current_buf); 453 - current_buf = parent; 450 + if (!current_buf) 451 + return; 452 + 453 + fclose(yyin); 454 + yy_delete_buffer(YY_CURRENT_BUFFER); 455 + yy_switch_to_buffer(current_buf->state); 456 + tmp = current_buf; 457 + current_buf = current_buf->parent; 458 + free(tmp); 454 459 } 455 460 456 461 int zconf_lineno(void)