diff options
Diffstat (limited to 'scripts/kconfig/symbol.c')
-rw-r--r-- | scripts/kconfig/symbol.c | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index 6c8fbbb66ebc..9ee3923117ee 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c | |||
@@ -651,12 +651,20 @@ bool sym_is_changable(struct symbol *sym) | |||
651 | return sym->visible > sym->rev_dep.tri; | 651 | return sym->visible > sym->rev_dep.tri; |
652 | } | 652 | } |
653 | 653 | ||
654 | static unsigned strhash(const char *s) | ||
655 | { | ||
656 | /* fnv32 hash */ | ||
657 | unsigned hash = 2166136261U; | ||
658 | for (; *s; s++) | ||
659 | hash = (hash ^ *s) * 0x01000193; | ||
660 | return hash; | ||
661 | } | ||
662 | |||
654 | struct symbol *sym_lookup(const char *name, int flags) | 663 | struct symbol *sym_lookup(const char *name, int flags) |
655 | { | 664 | { |
656 | struct symbol *symbol; | 665 | struct symbol *symbol; |
657 | const char *ptr; | ||
658 | char *new_name; | 666 | char *new_name; |
659 | int hash = 0; | 667 | int hash; |
660 | 668 | ||
661 | if (name) { | 669 | if (name) { |
662 | if (name[0] && !name[1]) { | 670 | if (name[0] && !name[1]) { |
@@ -666,12 +674,11 @@ struct symbol *sym_lookup(const char *name, int flags) | |||
666 | case 'n': return &symbol_no; | 674 | case 'n': return &symbol_no; |
667 | } | 675 | } |
668 | } | 676 | } |
669 | for (ptr = name; *ptr; ptr++) | 677 | hash = strhash(name) % SYMBOL_HASHSIZE; |
670 | hash += *ptr; | ||
671 | hash &= 0xff; | ||
672 | 678 | ||
673 | for (symbol = symbol_hash[hash]; symbol; symbol = symbol->next) { | 679 | for (symbol = symbol_hash[hash]; symbol; symbol = symbol->next) { |
674 | if (!strcmp(symbol->name, name) && | 680 | if (symbol->name && |
681 | !strcmp(symbol->name, name) && | ||
675 | (flags ? symbol->flags & flags | 682 | (flags ? symbol->flags & flags |
676 | : !(symbol->flags & (SYMBOL_CONST|SYMBOL_CHOICE)))) | 683 | : !(symbol->flags & (SYMBOL_CONST|SYMBOL_CHOICE)))) |
677 | return symbol; | 684 | return symbol; |
@@ -679,7 +686,7 @@ struct symbol *sym_lookup(const char *name, int flags) | |||
679 | new_name = strdup(name); | 686 | new_name = strdup(name); |
680 | } else { | 687 | } else { |
681 | new_name = NULL; | 688 | new_name = NULL; |
682 | hash = 256; | 689 | hash = 0; |
683 | } | 690 | } |
684 | 691 | ||
685 | symbol = malloc(sizeof(*symbol)); | 692 | symbol = malloc(sizeof(*symbol)); |
@@ -697,7 +704,6 @@ struct symbol *sym_lookup(const char *name, int flags) | |||
697 | struct symbol *sym_find(const char *name) | 704 | struct symbol *sym_find(const char *name) |
698 | { | 705 | { |
699 | struct symbol *symbol = NULL; | 706 | struct symbol *symbol = NULL; |
700 | const char *ptr; | ||
701 | int hash = 0; | 707 | int hash = 0; |
702 | 708 | ||
703 | if (!name) | 709 | if (!name) |
@@ -710,12 +716,11 @@ struct symbol *sym_find(const char *name) | |||
710 | case 'n': return &symbol_no; | 716 | case 'n': return &symbol_no; |
711 | } | 717 | } |
712 | } | 718 | } |
713 | for (ptr = name; *ptr; ptr++) | 719 | hash = strhash(name) % SYMBOL_HASHSIZE; |
714 | hash += *ptr; | ||
715 | hash &= 0xff; | ||
716 | 720 | ||
717 | for (symbol = symbol_hash[hash]; symbol; symbol = symbol->next) { | 721 | for (symbol = symbol_hash[hash]; symbol; symbol = symbol->next) { |
718 | if (!strcmp(symbol->name, name) && | 722 | if (symbol->name && |
723 | !strcmp(symbol->name, name) && | ||
719 | !(symbol->flags & SYMBOL_CONST)) | 724 | !(symbol->flags & SYMBOL_CONST)) |
720 | break; | 725 | break; |
721 | } | 726 | } |