Exit with an error status if any writes to the output file fail. The file is big and it might the point where 'disk full' is reached. Use errx() for all the error exits to simplify the code and ensure the program name is added. Signed-off-by: David Laight --- scripts/kallsyms.c | 46 +++++++++++++++++++--------------------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c index bda8921c95ef..2e936317fb09 100644 --- a/scripts/kallsyms.c +++ b/scripts/kallsyms.c @@ -18,6 +18,7 @@ * */ +#include #include #include #include @@ -135,18 +136,16 @@ static struct sym_entry *read_symbol(FILE *in, char **buf, size_t *buf_len) addr = strtoull(*buf, &p, 16); - if (*buf == p || *p++ != ' ' || !isascii((type = *p++)) || *p++ != ' ') { - fprintf(stderr, "line format error\n"); - exit(EXIT_FAILURE); - } + if (*buf == p || *p++ != ' ' || !isascii((type = *p++)) || *p++ != ' ') + errx(1, "line format error"); name = p; len = strlen(name); if (len >= KSYM_NAME_LEN) { - fprintf(stderr, "Symbol %s too long for kallsyms (%zu >= %d).\n" - "Please increase KSYM_NAME_LEN both in kernel and kallsyms.c\n", - name, len, KSYM_NAME_LEN); + warnx("Symbol %s too long for kallsyms (%zu >= %d).\n" + "Please increase KSYM_NAME_LEN both in kernel and kallsyms.c", + name, len, KSYM_NAME_LEN); return NULL; } @@ -253,10 +252,8 @@ static void read_map(const char *in) size_t buflen = 0; fp = fopen(in, "r"); - if (!fp) { - perror(in); - exit(1); - } + if (!fp) + err(1, "failed to open %s", in); while (!feof(fp)) { sym = read_symbol(fp, &buf, &buflen); @@ -362,18 +359,12 @@ static void write_src(void) table[i]->seq = i; /* There cannot be any symbol of length zero. */ - if (table[i]->len == 0) { - fprintf(stderr, "kallsyms failure: " - "unexpected zero symbol length\n"); - exit(EXIT_FAILURE); - } + if (table[i]->len == 0) + errx(1, "unexpected zero symbol length"); /* Only lengths that fit in up-to-two-byte ULEB128 are supported. */ - if (table[i]->len > 0x3FFF) { - fprintf(stderr, "kallsyms failure: " - "unexpected huge symbol length\n"); - exit(EXIT_FAILURE); - } + if (table[i]->len > 0x3FFF) + errx(1, "unexpected huge symbol length"); /* Encode length with ULEB128. */ if (table[i]->len <= 0x7F) { @@ -431,12 +422,9 @@ static void write_src(void) if (pc_relative) { long long offset = table[i]->addr - _text; - if (offset < INT_MIN || offset > INT_MAX) { - fprintf(stderr, "kallsyms failure: " - "relative symbol value %#llx out of range\n", - table[i]->addr); - exit(EXIT_FAILURE); - } + if (offset < INT_MIN || offset > INT_MAX) + errx(1, "relative symbol value %#llx out of range", + table[i]->addr); printf("\t.long\t_text - . + (%d)\t/* %s */\n", (int)offset, table[i]->sym); } else { @@ -456,6 +444,10 @@ static void write_src(void) (unsigned char)(table[i]->seq >> 0), table[i]->sym); printf("\n"); + + fflush(stdout); + if (ferror(stdout)) + errx(1, "error writing to output file"); } -- 2.39.5