From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35A0DC433EF for ; Tue, 28 Sep 2021 10:04:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 05BE860E09 for ; Tue, 28 Sep 2021 10:04:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240127AbhI1KFv (ORCPT ); Tue, 28 Sep 2021 06:05:51 -0400 Received: from mail.avm.de ([212.42.244.94]:33264 "EHLO mail.avm.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240075AbhI1KFu (ORCPT ); Tue, 28 Sep 2021 06:05:50 -0400 Received: from mail-auth.avm.de (dovecot-mx-01.avm.de [212.42.244.71]) by mail.avm.de (Postfix) with ESMTPS; Tue, 28 Sep 2021 12:04:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=avm.de; s=mail; t=1632823448; bh=xwk5aKeuA2SmiAZZesWO8p3LrHak6bCLbAoWOMLvJes=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=OM9CneT5RaWM+p+70FjKkzYucbSl512yBMIB0BLlIJX9AJo2YE+iudAzE7zROvaCu JXO1IZAGAXmToYa4l7jIFKBoKMOoUyE8Bvq5E2Jjc8FhFeJ+bSFDipCfmWeMvrBnmi HlQrPw0rK+8ddzvChivdRl1HNBdVi4xH9TsqKG/8= Received: from deb-nschier.ads.avm.de (unknown [172.17.24.144]) by mail-auth.avm.de (Postfix) with ESMTPSA id 80539804BC; Tue, 28 Sep 2021 12:04:08 +0200 (CEST) Date: Tue, 28 Sep 2021 12:04:07 +0200 From: Nicolas Schier To: Masahiro Yamada Cc: linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] kconfig: remove 'const' from the return type of sym_escape_string() Message-ID: References: <20210927125944.819010-1-masahiroy@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20210927125944.819010-1-masahiroy@kernel.org> X-purgate-ID: 149429::1632823448-000004DC-7AF8A00D/0/0 X-purgate-type: clean X-purgate-size: 3640 X-purgate-Ad: Categorized by eleven eXpurgate (R) http://www.eleven.de X-purgate: This mail is considered clean (visit http://www.eleven.de for further information) X-purgate: clean Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 27, 2021 at 09:59:44PM +0900, Masahiro Yamada wrote: > sym_escape_string() returns a malloc'ed memory, so it must be freed > when it is done. > > Currently, sym_escape_string() returns the malloc'ed memory as > (const char *), then it is casted to (void *) when it is passed to > free(). This is odd. > > The return type of sym_escape_string() should be (char *). > > Signed-off-by: Masahiro Yamada Reviewed-by: Nicolas Schier > --- > > scripts/kconfig/conf.c | 10 +++++----- > scripts/kconfig/confdata.c | 8 ++++---- > scripts/kconfig/lkc_proto.h | 2 +- > scripts/kconfig/symbol.c | 3 ++- > 4 files changed, 12 insertions(+), 11 deletions(-) > > diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c > index a6dad4a2e7a2..d8e1994bfed0 100644 > --- a/scripts/kconfig/conf.c > +++ b/scripts/kconfig/conf.c > @@ -647,15 +647,15 @@ static void check_conf(struct menu *menu) > switch (input_mode) { > case listnewconfig: > if (sym->name) { > - const char *str; > - > if (sym->type == S_STRING) { > + char *str; > + > str = sym_escape_string(sym); > printf("%s%s=%s\n", CONFIG_, sym->name, str); > - free((void *)str); > + free(str); > } else { > - str = sym_get_string_value(sym); > - printf("%s%s=%s\n", CONFIG_, sym->name, str); > + printf("%s%s=%s\n", CONFIG_, sym->name, > + sym_get_string_value(sym)); > } > } > break; > diff --git a/scripts/kconfig/confdata.c b/scripts/kconfig/confdata.c > index 4e053f2477f9..f7eac4beb128 100644 > --- a/scripts/kconfig/confdata.c > +++ b/scripts/kconfig/confdata.c > @@ -728,7 +728,7 @@ static struct conf_printer header_printer_cb = > static void conf_write_symbol(FILE *fp, struct symbol *sym, > struct conf_printer *printer, void *printer_arg) > { > - const char *str; > + char *str; > > switch (sym->type) { > case S_UNKNOWN: > @@ -736,11 +736,11 @@ static void conf_write_symbol(FILE *fp, struct symbol *sym, > case S_STRING: > str = sym_escape_string(sym); > printer->print_symbol(fp, sym, str, printer_arg); > - free((void *)str); > + free(str); > break; > default: > - str = sym_get_string_value(sym); > - printer->print_symbol(fp, sym, str, printer_arg); > + printer->print_symbol(fp, sym, sym_get_string_value(sym), > + printer_arg); > } > } > > diff --git a/scripts/kconfig/lkc_proto.h b/scripts/kconfig/lkc_proto.h > index 035cc522808b..7ce4b666bba8 100644 > --- a/scripts/kconfig/lkc_proto.h > +++ b/scripts/kconfig/lkc_proto.h > @@ -18,7 +18,7 @@ extern struct symbol * symbol_hash[SYMBOL_HASHSIZE]; > > struct symbol * sym_lookup(const char *name, int flags); > struct symbol * sym_find(const char *name); > -const char * sym_escape_string(struct symbol *sym); > +char *sym_escape_string(struct symbol *sym); > struct symbol ** sym_re_search(const char *pattern); > const char * sym_type_name(enum symbol_type type); > void sym_calc_value(struct symbol *sym); > diff --git a/scripts/kconfig/symbol.c b/scripts/kconfig/symbol.c > index 4a31bb943f79..57189a1ad797 100644 > --- a/scripts/kconfig/symbol.c > +++ b/scripts/kconfig/symbol.c > @@ -871,7 +871,8 @@ struct symbol *sym_find(const char *name) > return symbol; > } > > -const char *sym_escape_string(struct symbol *sym) > +/* the returned pointer must be freed on the caller side */ > +char *sym_escape_string(struct symbol *sym) > { > const char *in, *p; > size_t reslen; > -- > 2.30.2 >