aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--scripts/kconfig/expr.c10
-rw-r--r--scripts/kconfig/lkc.h2
-rw-r--r--scripts/kconfig/menu.c4
-rw-r--r--scripts/kconfig/symbol.c12
-rw-r--r--scripts/kconfig/util.c23
-rw-r--r--scripts/kconfig/zconf.l8
6 files changed, 40 insertions, 19 deletions
diff --git a/scripts/kconfig/expr.c b/scripts/kconfig/expr.c
index 290ce41f8ba4..d6626521f9b9 100644
--- a/scripts/kconfig/expr.c
+++ b/scripts/kconfig/expr.c
@@ -13,7 +13,7 @@
13 13
14struct expr *expr_alloc_symbol(struct symbol *sym) 14struct expr *expr_alloc_symbol(struct symbol *sym)
15{ 15{
16 struct expr *e = calloc(1, sizeof(*e)); 16 struct expr *e = xcalloc(1, sizeof(*e));
17 e->type = E_SYMBOL; 17 e->type = E_SYMBOL;
18 e->left.sym = sym; 18 e->left.sym = sym;
19 return e; 19 return e;
@@ -21,7 +21,7 @@ struct expr *expr_alloc_symbol(struct symbol *sym)
21 21
22struct expr *expr_alloc_one(enum expr_type type, struct expr *ce) 22struct expr *expr_alloc_one(enum expr_type type, struct expr *ce)
23{ 23{
24 struct expr *e = calloc(1, sizeof(*e)); 24 struct expr *e = xcalloc(1, sizeof(*e));
25 e->type = type; 25 e->type = type;
26 e->left.expr = ce; 26 e->left.expr = ce;
27 return e; 27 return e;
@@ -29,7 +29,7 @@ struct expr *expr_alloc_one(enum expr_type type, struct expr *ce)
29 29
30struct expr *expr_alloc_two(enum expr_type type, struct expr *e1, struct expr *e2) 30struct expr *expr_alloc_two(enum expr_type type, struct expr *e1, struct expr *e2)
31{ 31{
32 struct expr *e = calloc(1, sizeof(*e)); 32 struct expr *e = xcalloc(1, sizeof(*e));
33 e->type = type; 33 e->type = type;
34 e->left.expr = e1; 34 e->left.expr = e1;
35 e->right.expr = e2; 35 e->right.expr = e2;
@@ -38,7 +38,7 @@ struct expr *expr_alloc_two(enum expr_type type, struct expr *e1, struct expr *e
38 38
39struct expr *expr_alloc_comp(enum expr_type type, struct symbol *s1, struct symbol *s2) 39struct expr *expr_alloc_comp(enum expr_type type, struct symbol *s1, struct symbol *s2)
40{ 40{
41 struct expr *e = calloc(1, sizeof(*e)); 41 struct expr *e = xcalloc(1, sizeof(*e));
42 e->type = type; 42 e->type = type;
43 e->left.sym = s1; 43 e->left.sym = s1;
44 e->right.sym = s2; 44 e->right.sym = s2;
@@ -66,7 +66,7 @@ struct expr *expr_copy(const struct expr *org)
66 if (!org) 66 if (!org)
67 return NULL; 67 return NULL;
68 68
69 e = malloc(sizeof(*org)); 69 e = xmalloc(sizeof(*org));
70 memcpy(e, org, sizeof(*org)); 70 memcpy(e, org, sizeof(*org));
71 switch (org->type) { 71 switch (org->type) {
72 case E_SYMBOL: 72 case E_SYMBOL:
diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h
index 7577a7fbb405..f8aee5fc6d5e 100644
--- a/scripts/kconfig/lkc.h
+++ b/scripts/kconfig/lkc.h
@@ -122,6 +122,8 @@ void menu_set_type(int type);
122/* util.c */ 122/* util.c */
123struct file *file_lookup(const char *name); 123struct file *file_lookup(const char *name);
124int file_write_dep(const char *name); 124int file_write_dep(const char *name);
125void *xmalloc(size_t size);
126void *xcalloc(size_t nmemb, size_t size);
125 127
126struct gstr { 128struct gstr {
127 size_t len; 129 size_t len;
diff --git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c
index a3cade659f89..84a2ba2077aa 100644
--- a/scripts/kconfig/menu.c
+++ b/scripts/kconfig/menu.c
@@ -48,7 +48,7 @@ void menu_add_entry(struct symbol *sym)
48{ 48{
49 struct menu *menu; 49 struct menu *menu;
50 50
51 menu = malloc(sizeof(*menu)); 51 menu = xmalloc(sizeof(*menu));
52 memset(menu, 0, sizeof(*menu)); 52 memset(menu, 0, sizeof(*menu));
53 menu->sym = sym; 53 menu->sym = sym;
54 menu->parent = current_menu; 54 menu->parent = current_menu;
@@ -531,7 +531,7 @@ static void get_prompt_str(struct gstr *r, struct property *prop,
531 location = menu; 531 location = menu;
532 } 532 }
533 if (head && location) { 533 if (head && location) {
534 jump = malloc(sizeof(struct jump_key)); 534 jump = xmalloc(sizeof(struct jump_key));
535 535
536 if (menu_is_visible(prop->menu)) { 536 if (menu_is_visible(prop->menu)) {
537 /* 537 /*
diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index 22a3c400fc41..ecc5aa5f865d 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -656,11 +656,11 @@ bool sym_set_string_value(struct symbol *sym, const char *newval)
656 size = strlen(newval) + 1; 656 size = strlen(newval) + 1;
657 if (sym->type == S_HEX && (newval[0] != '0' || (newval[1] != 'x' && newval[1] != 'X'))) { 657 if (sym->type == S_HEX && (newval[0] != '0' || (newval[1] != 'x' && newval[1] != 'X'))) {
658 size += 2; 658 size += 2;
659 sym->def[S_DEF_USER].val = val = malloc(size); 659 sym->def[S_DEF_USER].val = val = xmalloc(size);
660 *val++ = '0'; 660 *val++ = '0';
661 *val++ = 'x'; 661 *val++ = 'x';
662 } else if (!oldval || strcmp(oldval, newval)) 662 } else if (!oldval || strcmp(oldval, newval))
663 sym->def[S_DEF_USER].val = val = malloc(size); 663 sym->def[S_DEF_USER].val = val = xmalloc(size);
664 else 664 else
665 return true; 665 return true;
666 666
@@ -812,7 +812,7 @@ struct symbol *sym_lookup(const char *name, int flags)
812 hash = 0; 812 hash = 0;
813 } 813 }
814 814
815 symbol = malloc(sizeof(*symbol)); 815 symbol = xmalloc(sizeof(*symbol));
816 memset(symbol, 0, sizeof(*symbol)); 816 memset(symbol, 0, sizeof(*symbol));
817 symbol->name = new_name; 817 symbol->name = new_name;
818 symbol->type = S_UNKNOWN; 818 symbol->type = S_UNKNOWN;
@@ -863,7 +863,7 @@ const char *sym_expand_string_value(const char *in)
863 size_t reslen; 863 size_t reslen;
864 864
865 reslen = strlen(in) + 1; 865 reslen = strlen(in) + 1;
866 res = malloc(reslen); 866 res = xmalloc(reslen);
867 res[0] = '\0'; 867 res[0] = '\0';
868 868
869 while ((src = strchr(in, '$'))) { 869 while ((src = strchr(in, '$'))) {
@@ -921,7 +921,7 @@ const char *sym_escape_string_value(const char *in)
921 p++; 921 p++;
922 } 922 }
923 923
924 res = malloc(reslen); 924 res = xmalloc(reslen);
925 res[0] = '\0'; 925 res[0] = '\0';
926 926
927 strcat(res, "\""); 927 strcat(res, "\"");
@@ -1228,7 +1228,7 @@ struct property *prop_alloc(enum prop_type type, struct symbol *sym)
1228 struct property *prop; 1228 struct property *prop;
1229 struct property **propp; 1229 struct property **propp;
1230 1230
1231 prop = malloc(sizeof(*prop)); 1231 prop = xmalloc(sizeof(*prop));
1232 memset(prop, 0, sizeof(*prop)); 1232 memset(prop, 0, sizeof(*prop));
1233 prop->type = type; 1233 prop->type = type;
1234 prop->sym = sym; 1234 prop->sym = sym;
diff --git a/scripts/kconfig/util.c b/scripts/kconfig/util.c
index d0b8b2318e48..6e7fbf196809 100644
--- a/scripts/kconfig/util.c
+++ b/scripts/kconfig/util.c
@@ -23,7 +23,7 @@ struct file *file_lookup(const char *name)
23 } 23 }
24 } 24 }
25 25
26 file = malloc(sizeof(*file)); 26 file = xmalloc(sizeof(*file));
27 memset(file, 0, sizeof(*file)); 27 memset(file, 0, sizeof(*file));
28 file->name = file_name; 28 file->name = file_name;
29 file->next = file_list; 29 file->next = file_list;
@@ -81,7 +81,7 @@ int file_write_dep(const char *name)
81struct gstr str_new(void) 81struct gstr str_new(void)
82{ 82{
83 struct gstr gs; 83 struct gstr gs;
84 gs.s = malloc(sizeof(char) * 64); 84 gs.s = xmalloc(sizeof(char) * 64);
85 gs.len = 64; 85 gs.len = 64;
86 gs.max_width = 0; 86 gs.max_width = 0;
87 strcpy(gs.s, "\0"); 87 strcpy(gs.s, "\0");
@@ -138,3 +138,22 @@ const char *str_get(struct gstr *gs)
138 return gs->s; 138 return gs->s;
139} 139}
140 140
141void *xmalloc(size_t size)
142{
143 void *p = malloc(size);
144 if (p)
145 return p;
146 fprintf(stderr, "Out of memory.\n");
147 exit(1);
148}
149
150void *xcalloc(size_t nmemb, size_t size)
151{
152 void *p = calloc(nmemb, size);
153 if (p)
154 return p;
155 fprintf(stderr, "Out of memory.\n");
156 exit(1);
157}
158
159
diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l
index 00f9d3a9cf8b..6555a475453b 100644
--- a/scripts/kconfig/zconf.l
+++ b/scripts/kconfig/zconf.l
@@ -40,7 +40,7 @@ static void zconf_endfile(void);
40 40
41static void new_string(void) 41static void new_string(void)
42{ 42{
43 text = malloc(START_STRSIZE); 43 text = xmalloc(START_STRSIZE);
44 text_asize = START_STRSIZE; 44 text_asize = START_STRSIZE;
45 text_size = 0; 45 text_size = 0;
46 *text = 0; 46 *text = 0;
@@ -62,7 +62,7 @@ static void append_string(const char *str, int size)
62 62
63static void alloc_string(const char *str, int size) 63static void alloc_string(const char *str, int size)
64{ 64{
65 text = malloc(size + 1); 65 text = xmalloc(size + 1);
66 memcpy(text, str, size); 66 memcpy(text, str, size);
67 text[size] = 0; 67 text[size] = 0;
68} 68}
@@ -288,7 +288,7 @@ void zconf_initscan(const char *name)
288 exit(1); 288 exit(1);
289 } 289 }
290 290
291 current_buf = malloc(sizeof(*current_buf)); 291 current_buf = xmalloc(sizeof(*current_buf));
292 memset(current_buf, 0, sizeof(*current_buf)); 292 memset(current_buf, 0, sizeof(*current_buf));
293 293
294 current_file = file_lookup(name); 294 current_file = file_lookup(name);
@@ -299,7 +299,7 @@ void zconf_nextfile(const char *name)
299{ 299{
300 struct file *iter; 300 struct file *iter;
301 struct file *file = file_lookup(name); 301 struct file *file = file_lookup(name);
302 struct buffer *buf = malloc(sizeof(*buf)); 302 struct buffer *buf = xmalloc(sizeof(*buf));
303 memset(buf, 0, sizeof(*buf)); 303 memset(buf, 0, sizeof(*buf));
304 304
305 current_buf->state = YY_CURRENT_BUFFER; 305 current_buf->state = YY_CURRENT_BUFFER;