Received: by 10.223.185.116 with SMTP id b49csp1055765wrg; Fri, 16 Feb 2018 11:36:09 -0800 (PST) X-Google-Smtp-Source: AH8x224lmbTnu9Yd1PRcXu9kcuggj28QTQ5ukL+DWgpbuvmvYBumdiEq9c85z5zTbkOZkQYLiUSi X-Received: by 10.98.69.146 with SMTP id n18mr7093955pfi.29.1518809769351; Fri, 16 Feb 2018 11:36:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518809769; cv=none; d=google.com; s=arc-20160816; b=LYCnbWySMtxU1/3hIFGtrKXmJIRFgVPOr8nXFU4XUgVtdYBYahwoBCtaq884xWdHbc RuLOFTq6XYEtAE3W2bQX/f2UBr7tvchXPq/3IaxL/QzWbjzZzPsZ7+BgP/NyFbxFlubF fEGoyKq+SSnLWkdJMMjp+sNHsWeYHtEjXpwRUdjjiRIGZ6X0/CTL3jvKdYZfe4wwuVe9 k2whPbgxv4kN/vNWPfeQ7UpnRg59tYTSLNb5fYY13Qy08JsyuCpOJLjjvFkrChEIjcan 4Jcs0VuqjlOhubaTxJYsI+1LbX6vqr0CREJ3wzy6OGYxl+QxNf1R1jcn6A/S/cH5ADsU gw+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter :arc-authentication-results; bh=x37G/JrybxXhVfsvSRijeqSjd9Vmal2cBfU3vCqzxWI=; b=n5Ldv5D5fRcZN9zJolofLjw9hOBEEEmllHk1HJj/n01Pr3DnkDksFWAo5AJTIbzV3b 1l//YztSBZuW+l0mtT2KeY/Q+DH8yThWMPwuLQZR5wqZUElXXfEWaWpIEl85LnUP3HyI N9queCSL0McVPHJc/maPymoSmBiARfJOfpF+6s/txxp8+1JVHXGCuzW9yLn0y2jN/XlY kCUPt7N21LbTTwrqQTvuCvEKycQ4hCs0fpaWpBiH+uh2Qes56wZGaHC6vnygekfCQ73h V+HAFq7xRm/0umFj/Eqsf5Tf+WE7a+SQwN0YnUsz5adpa8Q38Jh1Cb7z6yel6YUuqlWy 1t/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=ZAEzv6Vt; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o14-v6si550570pli.183.2018.02.16.11.35.54; Fri, 16 Feb 2018 11:36:09 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@nifty.com header.s=dec2015msa header.b=ZAEzv6Vt; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752878AbeBPSlY (ORCPT + 99 others); Fri, 16 Feb 2018 13:41:24 -0500 Received: from conuserg-07.nifty.com ([210.131.2.74]:57763 "EHLO conuserg-07.nifty.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752622AbeBPSlS (ORCPT ); Fri, 16 Feb 2018 13:41:18 -0500 Received: from grover.sesame (FL1-125-199-20-195.osk.mesh.ad.jp [125.199.20.195]) (authenticated) by conuserg-07.nifty.com with ESMTP id w1GIdBT6013418; Sat, 17 Feb 2018 03:39:15 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-07.nifty.com w1GIdBT6013418 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1518806355; bh=x37G/JrybxXhVfsvSRijeqSjd9Vmal2cBfU3vCqzxWI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZAEzv6VtrCoKX3v0tpsSlIRB45IBre4UrlcyyD2uVh7B6vmW7YNoxxNpD18eGwYL0 JVsIO+2t6EDzuDbfaQ3ui86L56yNCFwtl1XE8m9eKdJ/NeeoLKPIeeRxCPDTY6KzEn LWCrbuyp3xshYynZG7Fp4gZuCK8DRFKU2T9ZW4k2KxK0Muba+JbzMNcUZ0GU5MHpU2 50f2pAkUwmLlplME0IdUXmu3BV9rd7It9crE0ZAyaj598xn32iMQegLncnmSQpYtWn WT+0cF4DwrzYewfn2x4hSe+Mdnv1jP63T27wLpYtQa+g10IkgGZsmKIBt0/VUULbyC RBDS0SE2yJxcg== X-Nifty-SrcIP: [125.199.20.195] From: Masahiro Yamada To: linux-kbuild@vger.kernel.org, Linus Torvalds Cc: Greg Kroah-Hartman , Arnd Bergmann , Kees Cook , Randy Dunlap , Ulf Magnusson , Sam Ravnborg , Michal Marek , Masahiro Yamada , linux-kernel@vger.kernel.org Subject: [PATCH 03/23] kconfig: add xstrdup() helper Date: Sat, 17 Feb 2018 03:38:31 +0900 Message-Id: <1518806331-7101-4-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1518806331-7101-1-git-send-email-yamada.masahiro@socionext.com> References: <1518806331-7101-1-git-send-email-yamada.masahiro@socionext.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We already have xmalloc(), xcalloc(), and xrealloc((). Add xstrdup() as well to save tedious error handling. Signed-off-by: Masahiro Yamada --- scripts/kconfig/confdata.c | 2 +- scripts/kconfig/kxgettext.c | 2 +- scripts/kconfig/lkc.h | 1 + scripts/kconfig/symbol.c | 4 ++-- scripts/kconfig/util.c | 11 +++++++++++ scripts/kconfig/zconf.y | 2 +- 6 files changed, 17 insertions(+), 5 deletions(-) diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c index 5c12dc9..df26c7b 100644 --- a/scripts/kconfig/confdata.c +++ b/scripts/kconfig/confdata.c @@ -178,7 +178,7 @@ static int conf_set_sym_val(struct symbol *sym, int def, int def_flags, char *p) case S_HEX: done: if (sym_string_valid(sym, p)) { - sym->def[def].val = strdup(p); + sym->def[def].val = xstrdup(p); sym->flags |= def_flags; } else { if (def != S_DEF_AUTO) diff --git a/scripts/kconfig/kxgettext.c b/scripts/kconfig/kxgettext.c index 2858738..240880a 100644 --- a/scripts/kconfig/kxgettext.c +++ b/scripts/kconfig/kxgettext.c @@ -101,7 +101,7 @@ static struct message *message__new(const char *msg, char *option, if (self->files == NULL) goto out_fail; - self->msg = strdup(msg); + self->msg = xstrdup(msg); if (self->msg == NULL) goto out_fail_msg; diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h index 4e23feb..2d5ec2d 100644 --- a/scripts/kconfig/lkc.h +++ b/scripts/kconfig/lkc.h @@ -115,6 +115,7 @@ 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); +char *xstrdup(const char *s); struct gstr { size_t len; diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c index cca9663..2220bc4 100644 --- a/scripts/kconfig/symbol.c +++ b/scripts/kconfig/symbol.c @@ -183,7 +183,7 @@ static void sym_validate_range(struct symbol *sym) sprintf(str, "%lld", val2); else sprintf(str, "0x%llx", val2); - sym->curr.val = strdup(str); + sym->curr.val = xstrdup(str); } static void sym_set_changed(struct symbol *sym) @@ -849,7 +849,7 @@ struct symbol *sym_lookup(const char *name, int flags) : !(symbol->flags & (SYMBOL_CONST|SYMBOL_CHOICE)))) return symbol; } - new_name = strdup(name); + new_name = xstrdup(name); } else { new_name = NULL; hash = 0; diff --git a/scripts/kconfig/util.c b/scripts/kconfig/util.c index b98a79e..c6f6e21 100644 --- a/scripts/kconfig/util.c +++ b/scripts/kconfig/util.c @@ -154,3 +154,14 @@ void *xrealloc(void *p, size_t size) fprintf(stderr, "Out of memory.\n"); exit(1); } + +char *xstrdup(const char *s) +{ + char *p; + + p = strdup(s); + if (p) + return p; + fprintf(stderr, "Out of memory.\n"); + exit(1); +} diff --git a/scripts/kconfig/zconf.y b/scripts/kconfig/zconf.y index 4893676..ad6305b 100644 --- a/scripts/kconfig/zconf.y +++ b/scripts/kconfig/zconf.y @@ -127,7 +127,7 @@ no_mainmenu_stmt: /* empty */ * later regardless of whether it comes from the 'prompt' in * mainmenu_stmt or here */ - menu_add_prompt(P_MENU, strdup("Linux Kernel Configuration"), NULL); + menu_add_prompt(P_MENU, xstrdup("Linux Kernel Configuration"), NULL); }; -- 2.7.4