Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp5657251imm; Mon, 27 Aug 2018 01:44:47 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZfNk9uOISpHJQcw0wcDE3+TMbPifuA3x0EMUfyB5vUPBc9NHfSIUooDpopaZlDyqj0CuWO X-Received: by 2002:a17:902:28c7:: with SMTP id f65-v6mr12105296plb.240.1535359487293; Mon, 27 Aug 2018 01:44:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535359487; cv=none; d=google.com; s=arc-20160816; b=zXGarJ0gfxk4tv/oj2AI27USL0EuHwMgJ/JS8Z0ToIf2VIMeRgDI0vC2uenkYcCvPc IZ1nweNJbHgECcUZwnTD8odSuVwp0WUZ/uoMhFODe5Pvx3Uj8nBlorZpomzPO6eTkbic kM0z+bSR4AfiLXPYON0TJIhhXk2cLvQdyr8iFyQgTYTEZZ73/lBtA62/v8kTOIvFlsXy EQhHCd9PIa6wUWD11udhUlQYMJL4THhs16fY3VfgmvTRYQtjoK73pPI5EM5c9K6WiU3x SNrEz79eQXKmsYgclV1+awvsnACy9YpKkraYBQzLr0wj2sVT/1iwmpT35dJ6vVVg/44v BEVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:date:cc:to:from:subject:message-id :arc-authentication-results; bh=yDD85Gtc2a3ZfFidM62vfU9O17jIYQxw/BjSlIgVAZE=; b=ypiXZkAoPzNITMy8jorMxo7idRVzkFjc6s1mN9m41UlLGjSybXVZOCwJgzDbmR0vrP eqOHouFoD+PhkkTBR4QJzL0QGoCzysyMKP72MyPJh06+/RttZ5Mx1FWtuRNj/WaksQrr 9rUxkb25kCxAZaI8jQFxHMk8++VNF8opnyhncaNZeBuJVfFyujnQ+ng06Quvb7qIJyHs nN7pLdqmX/w5nhKJ4USMHDZxXgB4sCr29+f9yNZ/0F6m8t/nF++E9SUuls7d8R1dH/qp 6ET2v8h5on5pPkc+GsW/E6AbOy1py8FMguLEx2X/P0nPnZttRdixUD+iXsqBu/dB14ok ntjw== ARC-Authentication-Results: i=1; mx.google.com; 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 l185-v6si14898652pfl.134.2018.08.27.01.44.32; Mon, 27 Aug 2018 01:44:47 -0700 (PDT) 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; 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 S1726977AbeH0M2d (ORCPT + 99 others); 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-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::::::::::::::::::::::::::::::::,RULES_HIT:41:355:379:541:599:966:973:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1534:1541:1593:1594:1711:1730:1747:1777:1792:2196:2199:2393:2559:2562:2693:2828:3138:3139:3140:3141:3142:3353:3622:3865:3866:3867:3868:3870:3871:3872:3873:3874:4250:4321:4385:5007:6119:6737:7875:7903:8660:10004:10400:10848:11026:11232:11658:11914:12043:12048:12114:12296:12740:12760:12895:13069:13148:13161:13229:13230:13311:13357:13439:14096:14097:14659:14721:21080:21433:21451:21627:21809:30054:30079:30091,0,RBL:47.151.153.53:@perches.com:.lbl8.mailshell.net-62.8.0.100 64.201.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:29,LUA_SUMMARY:none 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?