Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp5671147imm; Mon, 27 Aug 2018 02:03:29 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZLSXNyyLNYkwoUCeVpcg38yzuWP5HwvSuhweQFPePLhMWueKTyVbjwgfytfCB/Ywk/0xJ6 X-Received: by 2002:a63:1125:: with SMTP id g37-v6mr3795380pgl.187.1535360609562; Mon, 27 Aug 2018 02:03:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535360609; cv=none; d=google.com; s=arc-20160816; b=PHL/Eix2xqJ3NZsE+zOdZXbimuVayp5TyhAVzQHBUCPR2YJ0zI6c3oNsAcMxCHdw91 3UeL1IsE3L9DvwrEAwFEf3SaFA7+eGmpi1hV09wjdm0ZYPLfBYgs0LP4VaTfloHNP4x7 r1XRAo8BnSkzG06ECwcwzIvcRKd2s4POE6JDXQDmEzNHcsD8r55FEqDeKNKWgU4Ai4Hf KCB5cigTnu9vt93lHDDCUc/oq6qJVQp5auOD129Twf45lAgwKo8VOZ6PpE4XMn2qFX8r iVnj9dvh6weBTlSmCNRGzn/fGNuau2/tv3h4014Rvy/xpz1vlAussaLByypaM0ZLsF9i WMhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=X/uABiPZ9yR2rK0DeZRSLuxLdEpUuLHriCvZnCoanUQ=; b=rBWMAxXUkn2IqTDsVSs6VklNfPgnFBiSENfM7quVJ+qr/IyDVgYApSX0MHU2QIv5tH oNcr7c+y0qud2+27tFnVn0Xz4cm9ErsI6vzWxdgNIH0I1PQzvSsBWYAX4HE94yuuxuAx pSs1Ps5Tw9c8uMPtlDp/Wk3ve+B4Pa7WQIr8RGDLxOjqrUHCJyUsDdUESc9WagE5N/o/ CY+23/QXgvfb2LgAfDgQBaP6HNI50bUsfiH16sSCRcn5L9yYukP9wUB6+PJqMnte1eiP kZxUb1w0fbUi5ur1ddD0LWvHmN6zY4o5x4c4ClveJ3CtuSZH5hSC/tIE5sIoOnv2lUih CqNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=H9D18Di4; 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 67-v6si15291786pfc.21.2018.08.27.02.03.13; Mon, 27 Aug 2018 02:03:29 -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; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=H9D18Di4; 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 S1726939AbeH0Mro (ORCPT + 99 others); Mon, 27 Aug 2018 08:47:44 -0400 Received: from mail-io0-f196.google.com ([209.85.223.196]:37878 "EHLO mail-io0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726802AbeH0Mro (ORCPT ); Mon, 27 Aug 2018 08:47:44 -0400 Received: by mail-io0-f196.google.com with SMTP id v14-v6so12219220iob.4 for ; Mon, 27 Aug 2018 02:01:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=X/uABiPZ9yR2rK0DeZRSLuxLdEpUuLHriCvZnCoanUQ=; b=H9D18Di49M7tlhlYLSxjZ/m5C5URgBQfJnWoCM5hjJlQeIdodOE+8WLzd3yn+960LN Yh4GIVdL5OX5QQuVXbWn9rZTKkkYabBiYeXNsN8llr0zApneh2IOp0s+hOcl026dTLRd E+HL8f7hFlhab2kfsvpO8tVudKU+hCmmdv3AIqQfRuKVbh2wl41r8ifiscRok91aBvQJ vOF/za2oh/mEyh99w64zH/+QNVCROOgcPQ8pGhVpZQShX7Y+Ll+cbl0uSxHWEGfA9IcH GH+GNXDCsTx3g7AzxG4H1+NywsnzHTwPixd9t6qVe2A/mCzUdHL4/ht/QxhZbxRZbTeu BtGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=X/uABiPZ9yR2rK0DeZRSLuxLdEpUuLHriCvZnCoanUQ=; b=D95c3uGArNMWzQZp5bnDDrxExw3CpdV6yK5lIxqAdP7BjV4TIvJgTWTisFltzCMDhH s56LmCF3oCrcoSJnJIfZVCL7j/uu12wwoV3s2gAQApDco/lblLquT5740IKQ7Rj8r83X CBawGpnr0rUuziiYWMI4QFkqvjFA605Ku4u9L7mVpCx4zQAkevsd1uEca6TyQFZjVVoQ 6xjV7H4TMujT9Bs5mv90e5o24GjkfKfOz5jx0OAsdO2i5ydMHSjyVVKnOceaCg4bNKuX 4aq0Iv9FyZAPydnDTpp3ckHrnQXcpSEyAp1GEHkOAq/8S+DD9HrwUcVrC7tNKwhqAMSg Xtrg== X-Gm-Message-State: APzg51BO2IVBSSK9ci57UmhKz1dCy2TIzSujXpL7+/S8DC9GX17VYxHp 1kYwXUvz4lhrfMztfMv8X0HLQNQnyPB74jldVbCHVA== X-Received: by 2002:a5e:8d07:: with SMTP id m7-v6mr9221166ioj.258.1535360517629; Mon, 27 Aug 2018 02:01:57 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a5e:9402:0:0:0:0:0 with HTTP; Mon, 27 Aug 2018 02:01:57 -0700 (PDT) In-Reply-To: <4a576f65b8fb3a0e6f0ca662e89070eb982be298.camel@perches.com> References: <20180827082101.5036-1-brgl@bgdev.pl> <4a576f65b8fb3a0e6f0ca662e89070eb982be298.camel@perches.com> From: Bartosz Golaszewski Date: Mon, 27 Aug 2018 11:01:57 +0200 Message-ID: Subject: Re: [PATCH 1/2] devres: provide devm_kstrdup_const() To: Joe Perches Cc: 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 , linux-clk , Linux Kernel Mailing List , linux-mm@kvack.org Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 2018-08-27 10:42 GMT+02:00 Joe Perches : > 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? > Yes it does but for some reason gcc 6.3 didn't complain... > The kstrdup_const function returns a const char *, > why shouldn't this? > It probably should, I'll fix it for v2. Bart