All of lore.kernel.org
 help / color / mirror / Atom feed
From: Masahiro Yamada <yamada.masahiro@socionext.com>
To: linux-kbuild@vger.kernel.org,
	Linus Torvalds <torvalds@linux-foundation.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Kees Cook <keescook@chromium.org>,
	Nicolas Pitre <nicolas.pitre@linaro.org>,
	"Luis R . Rodriguez" <mcgrof@suse.com>,
	Randy Dunlap <rdunlap@infradead.org>,
	Ulf Magnusson <ulfalizer@gmail.com>,
	Sam Ravnborg <sam@ravnborg.org>,
	Michal Marek <michal.lkml@markovi.net>,
	Martin Schwidefsky <schwidefsky@de.ibm.com>,
	Pavel Machek <pavel@ucw.cz>,
	linux-s390@vger.kernel.org, Jiri Kosina <jkosina@suse.cz>,
	Masahiro Yamada <yamada.masahiro@socionext.com>,
	linux-kernel@vger.kernel.org
Subject: [RFC PATCH 2/7] kconfig: add xrealloc() helper
Date: Fri,  9 Feb 2018 01:19:07 +0900	[thread overview]
Message-ID: <1518106752-29228-3-git-send-email-yamada.masahiro@socionext.com> (raw)
In-Reply-To: <1518106752-29228-1-git-send-email-yamada.masahiro@socionext.com>

We have xmalloc(), xcalloc() already.  Add xrealloc() as well to save
tedious error handling.

Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---

 scripts/kconfig/confdata.c  |  2 +-
 scripts/kconfig/lkc.h       |  1 +
 scripts/kconfig/nconf.gui.c |  2 +-
 scripts/kconfig/symbol.c    |  2 +-
 scripts/kconfig/util.c      | 11 ++++++++++-
 scripts/kconfig/zconf.l     |  2 +-
 6 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c
index f792739..5c12dc9 100644
--- a/scripts/kconfig/confdata.c
+++ b/scripts/kconfig/confdata.c
@@ -201,7 +201,7 @@ static int add_byte(int c, char **lineptr, size_t slen, size_t *n)
 	if (new_size > *n) {
 		new_size += LINE_GROWTH - 1;
 		new_size *= 2;
-		nline = realloc(*lineptr, new_size);
+		nline = xrealloc(*lineptr, new_size);
 		if (!nline)
 			return -1;
 
diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h
index 16cb62b..4e23feb 100644
--- a/scripts/kconfig/lkc.h
+++ b/scripts/kconfig/lkc.h
@@ -114,6 +114,7 @@ struct file *file_lookup(const char *name);
 int file_write_dep(const char *name);
 void *xmalloc(size_t size);
 void *xcalloc(size_t nmemb, size_t size);
+void *xrealloc(void *p, size_t size);
 
 struct gstr {
 	size_t len;
diff --git a/scripts/kconfig/nconf.gui.c b/scripts/kconfig/nconf.gui.c
index a64b1c3..93e3d0c 100644
--- a/scripts/kconfig/nconf.gui.c
+++ b/scripts/kconfig/nconf.gui.c
@@ -374,7 +374,7 @@ int dialog_inputbox(WINDOW *main_window,
 
 	if (strlen(init)+1 > *result_len) {
 		*result_len = strlen(init)+1;
-		*resultp = result = realloc(result, *result_len);
+		*resultp = result = xrealloc(result, *result_len);
 	}
 
 	/* find the widest line of msg: */
diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c
index c9123ed..bc3ec6a 100644
--- a/scripts/kconfig/symbol.c
+++ b/scripts/kconfig/symbol.c
@@ -938,7 +938,7 @@ const char *sym_expand_string_value(const char *in)
 		newlen = strlen(res) + strlen(symval) + strlen(src) + 1;
 		if (newlen > reslen) {
 			reslen = newlen;
-			res = realloc(res, reslen);
+			res = xrealloc(res, reslen);
 		}
 
 		strcat(res, symval);
diff --git a/scripts/kconfig/util.c b/scripts/kconfig/util.c
index 0e76042..01ead28 100644
--- a/scripts/kconfig/util.c
+++ b/scripts/kconfig/util.c
@@ -104,7 +104,7 @@ void str_append(struct gstr *gs, const char *s)
 	if (s) {
 		l = strlen(gs->s) + strlen(s) + 1;
 		if (l > gs->len) {
-			gs->s   = realloc(gs->s, l);
+			gs->s   = xrealloc(gs->s, l);
 			gs->len = l;
 		}
 		strcat(gs->s, s);
@@ -145,3 +145,12 @@ void *xcalloc(size_t nmemb, size_t size)
 	fprintf(stderr, "Out of memory.\n");
 	exit(1);
 }
+
+void *xrealloc(void *p, size_t size)
+{
+	p = realloc(p, size);
+	if (p)
+		return p;
+	fprintf(stderr, "Out of memory.\n");
+	exit(1);
+}
diff --git a/scripts/kconfig/zconf.l b/scripts/kconfig/zconf.l
index 07e074d..0bc43db 100644
--- a/scripts/kconfig/zconf.l
+++ b/scripts/kconfig/zconf.l
@@ -52,7 +52,7 @@ static void append_string(const char *str, int size)
 	if (new_size > text_asize) {
 		new_size += START_STRSIZE - 1;
 		new_size &= -START_STRSIZE;
-		text = realloc(text, new_size);
+		text = xrealloc(text, new_size);
 		text_asize = new_size;
 	}
 	memcpy(text + text_size, str, size);
-- 
2.7.4

  parent reply	other threads:[~2018-02-08 16:19 UTC|newest]

Thread overview: 89+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-08 16:19 [RFC PATCH 0/7] Kconfig: add new special property shell= to test compiler options in Kconfig Masahiro Yamada
2018-02-08 16:19 ` [RFC PATCH 1/7] kbuild: remove kbuild cache Masahiro Yamada
2018-02-08 16:19 ` Masahiro Yamada [this message]
2018-02-08 16:19 ` [RFC PATCH 3/7] kconfig: remove const qualifier from sym_expand_string_value() Masahiro Yamada
2018-02-08 16:19 ` [RFC PATCH 4/7] kconfig: support new special property shell= Masahiro Yamada
2018-02-09  5:30   ` Ulf Magnusson
2018-02-09  9:19     ` Masahiro Yamada
2018-02-09 12:46       ` Ulf Magnusson
2018-02-09 20:46         ` Kees Cook
2018-02-10  5:48           ` Ulf Magnusson
2018-02-10  7:12             ` Masahiro Yamada
2018-02-10  7:49               ` Ulf Magnusson
2018-02-10  8:05                 ` Ulf Magnusson
2018-02-10  8:55                   ` Ulf Magnusson
2018-02-10  9:21                     ` Ulf Magnusson
2018-02-10 18:05                     ` Randy Dunlap
2018-02-11  2:00                       ` Kevin Easton
2018-02-10 19:23                     ` Kees Cook
2018-02-10 20:08                       ` Linus Torvalds
2018-02-11  4:13                         ` Kees Cook
2018-02-11  4:46                           ` Linus Torvalds
2018-02-11  7:28                             ` Linus Torvalds
2018-02-11 10:34                               ` Ulf Magnusson
2018-02-11 17:56                                 ` Kees Cook
2018-02-11 18:13                                   ` Linus Torvalds
2018-02-11 19:39                                     ` Kees Cook
2018-02-11 19:53                                       ` Linus Torvalds
2018-02-11 20:06                                         ` Linus Torvalds
2018-02-11 21:10                                           ` Arnd Bergmann
2018-02-11 21:19                                             ` Kees Cook
2018-02-11 21:50                                               ` Linus Torvalds
2018-02-12 10:44                                                 ` Arnd Bergmann
2018-02-12 10:44                                                   ` Arnd Bergmann
2018-02-11 22:29                                             ` Geert Uytterhoeven
2018-02-15 23:38                                           ` [RFC PATCH 4/7] kconfig: support new special property shell Palmer Dabbelt
2018-02-11 21:11                                         ` [RFC PATCH 4/7] kconfig: support new special property shell= Kees Cook
2018-02-11 19:42                                     ` Linus Torvalds
2018-02-12  8:26                                     ` Peter Zijlstra
2018-02-12 10:27                                       ` Thomas Gleixner
2018-02-12 11:52                                         ` Peter Zijlstra
2018-02-12 16:19                                       ` David Woodhouse
2018-02-12 16:19                                         ` David Woodhouse
2018-02-12 16:56                                         ` Kees Cook
2018-02-12 17:05                                           ` Peter Zijlstra
2018-02-12 17:33                                             ` Kees Cook
2018-02-12 17:36                                               ` David Woodhouse
2018-02-12 17:36                                                 ` David Woodhouse
2018-02-12 17:37                                                 ` Kees Cook
2018-02-12 17:00                                         ` Peter Zijlstra
2018-02-11 18:34                                   ` Ulf Magnusson
2018-02-11 21:05                                     ` Kees Cook
2018-02-11 21:35                                       ` Ulf Magnusson
2018-02-11 20:29                                   ` Ulf Magnusson
2018-02-11 20:42                                     ` Ulf Magnusson
2018-02-12 12:54                                       ` Ulf Magnusson
2018-02-12 14:21                                         ` Masahiro Yamada
2018-02-12 14:23                                           ` Masahiro Yamada
2018-02-12 14:32                                             ` Ulf Magnusson
2018-02-12 14:29                                           ` Ulf Magnusson
2018-02-12 14:53                                           ` Ulf Magnusson
2018-02-12 15:22                                             ` Masahiro Yamada
2018-02-12 15:35                                               ` Ulf Magnusson
2018-02-11 21:22                                   ` Ulf Magnusson
2018-02-12 14:39                                   ` Masahiro Yamada
2018-02-12 15:24                                     ` Kees Cook
2018-02-12 23:48                                       ` Randy Dunlap
2018-02-13  1:41                                         ` Masahiro Yamada
2018-02-13  1:53                                           ` Randy Dunlap
2018-02-13  8:35                                             ` Arnd Bergmann
2018-02-13  8:59                                               ` Masahiro Yamada
2018-02-12 10:44                                 ` Masahiro Yamada
2018-02-12 11:44                                   ` Ulf Magnusson
2018-02-12 11:49                                     ` Ulf Magnusson
2018-02-12 13:53                                     ` Masahiro Yamada
2018-02-12 14:13                                       ` Ulf Magnusson
2018-02-12 15:46                                   ` Kees Cook
2018-02-12 16:10                                     ` Masahiro Yamada
2018-02-13  8:55                                       ` Ulf Magnusson
2018-02-11 16:54                               ` Kees Cook
2018-02-08 16:19 ` [RFC PATCH 5/7] kconfig: invoke silentoldconfig when compiler is updated Masahiro Yamada
2018-02-08 17:19   ` Masahiro Yamada
2018-02-08 17:45     ` Linus Torvalds
2018-02-08 16:19 ` [RFC PATCH 6/7] kconfig: add basic environments to evaluate C flags in Kconfig Masahiro Yamada
2018-02-08 16:19 ` [RFC PATCH 7/7] Test stackprotector options in Kconfig to kill CC_STACKPROTECTOR_AUTO Masahiro Yamada
2018-02-08 18:30   ` Kees Cook
2018-02-09  4:13     ` Masahiro Yamada
2018-02-08 16:43 ` [RFC PATCH 0/7] Kconfig: add new special property shell= to test compiler options in Kconfig Greg Kroah-Hartman
2018-02-08 17:19 ` Linus Torvalds
2018-02-08 17:39   ` Masahiro Yamada

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=1518106752-29228-3-git-send-email-yamada.masahiro@socionext.com \
    --to=yamada.masahiro@socionext.com \
    --cc=akpm@linux-foundation.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jkosina@suse.cz \
    --cc=keescook@chromium.org \
    --cc=linux-kbuild@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=mcgrof@suse.com \
    --cc=michal.lkml@markovi.net \
    --cc=nicolas.pitre@linaro.org \
    --cc=pavel@ucw.cz \
    --cc=rdunlap@infradead.org \
    --cc=sam@ravnborg.org \
    --cc=schwidefsky@de.ibm.com \
    --cc=torvalds@linux-foundation.org \
    --cc=ulfalizer@gmail.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.