From: David Laight <david.laight.linux@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>,
Petr Mladek <pmladek@suse.com>, Kees Cook <kees@kernel.org>,
David Laight <david.laight.linux@gmail.com>,
linux-kernel@vger.kernel.org, linux-kbuild@vger.kernel.org,
bpf@vger.kernel.org, Jim Cromie <jim.cromie@gmail.com>,
Lorenzo Stoakes <ljs@kernel.org>
Cc: Luis Chamberlain <mcgrof@kernel.org>,
Andrey Grodzovsky <andrey.grodzovsky@crowdstrike.com>,
Steven Rostedt <rostedt@goodmis.org>
Subject: [PATCH v2 next 04/15] kallsyms: scripts/kallsyms: Check for output file write errors
Date: Sun, 18 Oct 2026 16:51:55 +0100 [thread overview]
Message-ID: <20261018155206.132411-5-david.laight.linux@gmail.com> (raw)
In-Reply-To: <20261018155206.132411-1-david.laight.linux@gmail.com>
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 <david.laight.linux@gmail.com>
---
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 <err.h>
#include <errno.h>
#include <getopt.h>
#include <stdbool.h>
@@ -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
next prev parent reply other threads:[~2026-10-18 15:53 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-18 15:51 [PATCH v2 next 00/15] kallsyms: optimise symbol search by name David Laight
2026-10-18 15:51 ` [PATCH v2 next 01/15] kallsyms: scripts/kallsyms.c: Avoid overrunning on-stack buffer David Laight
2026-10-18 15:51 ` [PATCH v2 next 02/15] kallsyms: Fix selftest startup delay David Laight
2026-10-18 15:51 ` [PATCH v2 next 03/15] kallsyms: Improve selftest test_perf_kallsyms_lookup_name() output David Laight
2026-10-18 16:03 ` sashiko-bot
2026-10-19 16:07 ` kernel test robot
2026-10-19 17:08 ` David Laight
2026-10-19 20:57 ` kernel test robot
2026-10-19 21:25 ` David Laight
2026-10-18 15:51 ` David Laight [this message]
2026-10-18 15:51 ` [PATCH v2 next 05/15] kallsyms: Match compressed tokens on the fly during binary search David Laight
2026-10-18 15:51 ` [PATCH v2 next 06/15] kallsyms: Optimise symbol name search David Laight
2026-10-18 16:15 ` sashiko-bot
2026-10-18 17:04 ` David Laight
2026-10-18 15:51 ` [PATCH v2 next 07/15] kallsyms: Optimise detection of duplicate symbol names David Laight
2026-10-18 15:51 ` [PATCH v2 next 08/15] kallsyms: Support changing the density of the kallsyms_markers[] array David Laight
2026-10-18 15:52 ` [PATCH v2 next 09/15] kallsyms: Add a kernel parameter for the marker shift David Laight
2026-10-18 15:52 ` [PATCH v2 next 10/15] kallsyms: scripts/kallsyms: Rename some variables for clarity David Laight
2026-10-18 15:52 ` [PATCH v2 next 11/15] kallsyms: scripts/kallsyms: Keep full expansion of tokens David Laight
2026-10-18 16:00 ` sashiko-bot
2026-10-18 16:37 ` David Laight
2026-10-18 15:52 ` [PATCH v2 next 12/15] kallsyms: scripts/kallsyms: Optimise compress_symbols() David Laight
2026-10-18 15:52 ` [PATCH v2 next 13/15] kallsyms: scripts/kallsyms: Reuse tokens that have no references David Laight
2026-10-18 15:52 ` [PATCH 14/15] kallsyms: scripts/kallsyms: Reduce the output file size David Laight
2026-10-18 16:05 ` sashiko-bot
2026-10-18 16:47 ` David Laight
2026-10-19 19:50 ` kernel test robot
2026-10-19 21:23 ` David Laight
2026-10-18 15:52 ` [PATCH 15/15] kallsyms: scripts/kallsyms: Improve compression by about 2% David Laight
2026-10-18 16:05 ` sashiko-bot
2026-10-18 17:28 ` David Laight
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261018155206.132411-5-david.laight.linux@gmail.com \
--to=david.laight.linux@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=andrey.grodzovsky@crowdstrike.com \
--cc=bpf@vger.kernel.org \
--cc=jim.cromie@gmail.com \
--cc=kees@kernel.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ljs@kernel.org \
--cc=mcgrof@kernel.org \
--cc=pmladek@suse.com \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox