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 X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 36B57C433F4 for ; Mon, 27 Aug 2018 08:43:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F389A208B2 for ; Mon, 27 Aug 2018 08:43:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F389A208B2 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=perches.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726991AbeH0M2d (ORCPT ); Mon, 27 Aug 2018 08:28:33 -0400 Received: from smtprelay0019.hostedemail.com ([216.40.44.19]:34216 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726931AbeH0M2d (ORCPT ); Mon, 27 Aug 2018 08:28:33 -0400 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay03.hostedemail.com (Postfix) with ESMTP id 14FEA837F24D; Mon, 27 Aug 2018 08:42:51 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-HE-Tag: roll06_35806dfb6350f X-Filterd-Recvd-Size: 2976 Received: from XPS-9350.home (unknown [47.151.153.53]) (Authenticated sender: joe@perches.com) by omf05.hostedemail.com (Postfix) with ESMTPA; Mon, 27 Aug 2018 08:42:47 +0000 (UTC) Message-ID: <4a576f65b8fb3a0e6f0ca662e89070eb982be298.camel@perches.com> Subject: Re: [PATCH 1/2] devres: provide devm_kstrdup_const() From: Joe Perches To: Bartosz Golaszewski , Michael Turquette , Stephen Boyd , Greg Kroah-Hartman , "Rafael J . Wysocki" , Arend van Spriel , Ulf Hansson , Bjorn Helgaas , Vivek Gautam , Robin Murphy , Heikki Krogerus , Andrew Morton , Mike Rapoport , Michal Hocko , Al Viro , Jonathan Corbet , Roman Gushchin , Huang Ying , Kees Cook , Bjorn Andersson Cc: linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Date: Mon, 27 Aug 2018 01:42:46 -0700 In-Reply-To: <20180827082101.5036-1-brgl@bgdev.pl> References: <20180827082101.5036-1-brgl@bgdev.pl> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.28.1-2 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2018-08-27 at 10:21 +0200, Bartosz Golaszewski wrote: > Provide a resource managed version of kstrdup_const(). This variant > internally calls devm_kstrdup() on pointers that are outside of > .rodata section. Also provide a corresponding version of devm_kfree(). [] > diff --git a/mm/util.c b/mm/util.c [] > /** > * kstrdup - allocate space for and copy an existing string > * @s: the string to duplicate > @@ -78,6 +92,27 @@ const char *kstrdup_const(const char *s, gfp_t gfp) > } > EXPORT_SYMBOL(kstrdup_const); > > +/** > + * devm_kstrdup_const - resource managed conditional string duplication > + * @dev: device for which to duplicate the string > + * @s: the string to duplicate > + * @gfp: the GFP mask used in the kmalloc() call when allocating memory > + * > + * Function returns source string if it is in .rodata section otherwise it > + * fallbacks to devm_kstrdup. > + * > + * Strings allocated by devm_kstrdup_const will be automatically freed when > + * the associated device is detached. > + */ > +char *devm_kstrdup_const(struct device *dev, const char *s, gfp_t gfp) > +{ > + if (is_kernel_rodata((unsigned long)s)) > + return s; > + > + return devm_kstrdup(dev, s, gfp); > +} > +EXPORT_SYMBOL(devm_kstrdup_const); Doesn't this lose constness and don't you get a compiler warning here? The kstrdup_const function returns a const char *, why shouldn't this?