summaryrefslogtreecommitdiffstats
path: root/scripts/kallsyms.c
diff options
context:
space:
mode:
authorMasahiro Yamada <masahiroy@kernel.org>2024-08-12 14:48:52 +0200
committerMasahiro Yamada <masahiroy@kernel.org>2024-09-01 13:34:48 +0200
commitaeaa4283a309520c22a783071f554645943955d8 (patch)
tree4f61ef553883115c7bd7efd4da8bd124e02a62c9 /scripts/kallsyms.c
parentmodpost: replace the use of NOFAIL() with xmalloc() etc. (diff)
downloadlinux-aeaa4283a309520c22a783071f554645943955d8.tar.xz
linux-aeaa4283a309520c22a783071f554645943955d8.zip
kallsyms: use xmalloc() and xrealloc()
When malloc() or realloc() fails, there is not much userspace programs can do. xmalloc() and xrealloc() are useful to bail out on a memory allocation failure. Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
Diffstat (limited to 'scripts/kallsyms.c')
-rw-r--r--scripts/kallsyms.c23
1 files changed, 5 insertions, 18 deletions
diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
index 123dab0572f8..c70458e68ece 100644
--- a/scripts/kallsyms.c
+++ b/scripts/kallsyms.c
@@ -27,6 +27,8 @@
#include <ctype.h>
#include <limits.h>
+#include <xalloc.h>
+
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0]))
#define KSYM_NAME_LEN 512
@@ -168,12 +170,7 @@ static struct sym_entry *read_symbol(FILE *in, char **buf, size_t *buf_len)
* compressed together */
len++;
- sym = malloc(sizeof(*sym) + len + 1);
- if (!sym) {
- fprintf(stderr, "kallsyms failure: "
- "unable to allocate required amount of memory\n");
- exit(EXIT_FAILURE);
- }
+ sym = xmalloc(sizeof(*sym) + len + 1);
sym->addr = addr;
sym->len = len;
sym->sym[0] = type;
@@ -278,12 +275,7 @@ static void read_map(const char *in)
if (table_cnt >= table_size) {
table_size += 10000;
- table = realloc(table, sizeof(*table) * table_size);
- if (!table) {
- fprintf(stderr, "out of memory\n");
- fclose(fp);
- exit (1);
- }
+ table = xrealloc(table, sizeof(*table) * table_size);
}
table[table_cnt++] = sym;
@@ -391,12 +383,7 @@ static void write_src(void)
/* table of offset markers, that give the offset in the compressed stream
* every 256 symbols */
markers_cnt = (table_cnt + 255) / 256;
- markers = malloc(sizeof(*markers) * markers_cnt);
- if (!markers) {
- fprintf(stderr, "kallsyms failure: "
- "unable to allocate required memory\n");
- exit(EXIT_FAILURE);
- }
+ markers = xmalloc(sizeof(*markers) * markers_cnt);
output_label("kallsyms_names");
off = 0;