Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp5847094imm; Mon, 27 Aug 2018 05:30:18 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYklQhKwnUQJvhh2A4E1+/dyjYSBCLE4HZH1CwHuAfEWBq9wgKBKNS92gWq4VedccXvONLm X-Received: by 2002:a17:902:9a48:: with SMTP id x8-v6mr13038055plv.72.1535373018609; Mon, 27 Aug 2018 05:30:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535373018; cv=none; d=google.com; s=arc-20160816; b=0jO9MXnvMHPtjzwxgIHXT3t9DWDGKLkQ1wORM7R8bexrmtYw9W3EvqCxEsYHavyw5p bstRQ4WfMcjx/znNW6LOhv+2cUV6p3L8qJ4UYujCJX4/9hzQ318NgWHFnY2lXHv9Rl4Z OWJfBpNbBVCV8PcVSMTVsvLW0X25rJLWyMFXdKZq6sWRG2iG97nkRz7anAp9D/dmqkm6 RsQXO0v5m8W+Bv9qWFc0p7VrLHxZrS3FIYCtvOpNb40FOcswnVwqmT9Te1rbryyioiHB cZEAXZWg+L5k1YiPBiz9mYM7BaNCZdFNwoy2QP9M51TMJOeo+vWcKhR2oGkFZ+NIfxhK N6mA== 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=Jp1RsIGxKGYhbx7WsB6UMwgH0lcSbkdJqIRzAaLejWY=; b=q0MXXrCp9iQlEeUY0lJGTlBXrfyFX88Kdbp2I1Sd+cU/liuzXGoVbge+GJLzw1vr24 6JuvvVwlB0YVf2sLDIXZiWIHxS+NlnpdQoEaOXF2IarsEpA4p2KtUH+S4K8ty6BxXAE8 W8iU4CY8GDPN33JlNboZ3CQb3nAqm2xn6f5KPJax+C8APa5zRhUJgm0zbhA8Wv9kVDFZ Zc2js+MYV73whmrUPTqzT2JsSabwXdELqsNKLs5YXBI+tRN9uN+2bTCgv1Qr6uvEHe6T qLh3Y1aDWlslfN7Qo+LiYIterGVSzlnHSgBaPE1jekOPG/U6rKny52/deoKG5aJ/w3hG INMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=1qAFI17+; 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 i13-v6si12427173pgq.426.2018.08.27.05.30.02; Mon, 27 Aug 2018 05:30:18 -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=1qAFI17+; 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 S1727206AbeH0QPO (ORCPT + 99 others); Mon, 27 Aug 2018 12:15:14 -0400 Received: from mail-it0-f66.google.com ([209.85.214.66]:38254 "EHLO mail-it0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726868AbeH0QPO (ORCPT ); Mon, 27 Aug 2018 12:15:14 -0400 Received: by mail-it0-f66.google.com with SMTP id p129-v6so10191555ite.3 for ; Mon, 27 Aug 2018 05:28:46 -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=Jp1RsIGxKGYhbx7WsB6UMwgH0lcSbkdJqIRzAaLejWY=; b=1qAFI17+4mQuoRJMg3LEPDnpFFiQHvKORJaKf6cTIHBEhSbRv2vrwjGEyWPFKSHivG tU3iTX8FqIqAjShRUcB04EulkEE0RXrOaqRf19ngh9SB9LmCA+s9LmzXeBlUJBoziNZX symL/HBvmA7pBeCtYqs48KK3bYGi7ktnBCz05662oIlx4NoTzAcRykW3rf46tTIh0BcF y7MnQEZm8tNG0SIAmfAigpvYaj97WDV3bq2665GvA1gYV8lqbqkdR76FhKY0YC3lcX9Z dU2Z55WBokxbdpJ9wqp3uk7Tu/UNbghxx1Uhxc13In5enpAXExM24AdB74sullXPcO1u houQ== 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=Jp1RsIGxKGYhbx7WsB6UMwgH0lcSbkdJqIRzAaLejWY=; b=r3Ai1gqm5yfovUUs8Zvo2cyeJ+8G0XSAEvkx3cqeZqpmd67bSxLt5BZ1pSFYgbu63W 5D9vKp8Oa6hEq/qP3jvSfs83TGjJBt9d23G70V/3qfNtcwQ1izD8gwpA9jlM5sF+mwcX 7b8m42HgV3YWzpyGVv1HQxs9YeY06eHfZBXSVVOGCEFJAgKsQYhCYY8uAquZOG583xNy RNWwlBzh3X2+mzVIatZsB2WXAp1JLsXkp+x1WzaHn40e/mJkRQcVXL4Wb2g/vMfg1knV 5qeBLkmTB+ho6xY8YQy3M7caaM9l686UTWq9Wz0DGpm/5fUWZDsXTFxXh8j7KYI/4HCD tkwA== X-Gm-Message-State: APzg51DDp3RdZFJL/WRcUjIOdCy6bncPua5ks+Krc/+ahMykLlJs4BJH BgmvmXG/L5oHyW8B0dMLpNB2G9lAkLLS0V0z+6PZCA== X-Received: by 2002:a24:41cd:: with SMTP id b74-v6mr6517196itd.85.1535372926403; Mon, 27 Aug 2018 05:28:46 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a5e:9402:0:0:0:0:0 with HTTP; Mon, 27 Aug 2018 05:28:45 -0700 (PDT) In-Reply-To: <20180827103915.GC13848@rapoport-lnx> References: <20180827082101.5036-1-brgl@bgdev.pl> <20180827082101.5036-2-brgl@bgdev.pl> <20180827103915.GC13848@rapoport-lnx> From: Bartosz Golaszewski Date: Mon, 27 Aug 2018 14:28:45 +0200 Message-ID: Subject: Re: [PATCH 2/2] clk: pmc-atom: use devm_kstrdup_const() To: Mike Rapoport Cc: Michael Turquette , Stephen Boyd , Greg Kroah-Hartman , "Rafael J . Wysocki" , Arend van Spriel , Ulf Hansson , Bjorn Helgaas , Vivek Gautam , Robin Murphy , Joe Perches , Heikki Krogerus , Andrew Morton , 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 12:39 GMT+02:00 Mike Rapoport : > On Mon, Aug 27, 2018 at 10:21:01AM +0200, Bartosz Golaszewski wrote: >> Use devm_kstrdup_const() in the pmc-atom driver. This mostly serves as >> an example of how to use this new routine to shrink driver code. >> >> While we're at it: replace a call to kcalloc() with devm_kcalloc(). >> >> Signed-off-by: Bartosz Golaszewski >> --- >> drivers/clk/x86/clk-pmc-atom.c | 19 ++++--------------- >> 1 file changed, 4 insertions(+), 15 deletions(-) >> >> diff --git a/drivers/clk/x86/clk-pmc-atom.c b/drivers/clk/x86/clk-pmc-atom.c >> index 08ef69945ffb..daa2192e6568 100644 >> --- a/drivers/clk/x86/clk-pmc-atom.c >> +++ b/drivers/clk/x86/clk-pmc-atom.c >> @@ -253,14 +253,6 @@ static void plt_clk_unregister_fixed_rate_loop(struct clk_plt_data *data, >> plt_clk_unregister_fixed_rate(data->parents[i]); >> } >> >> -static void plt_clk_free_parent_names_loop(const char **parent_names, >> - unsigned int i) >> -{ >> - while (i--) >> - kfree_const(parent_names[i]); >> - kfree(parent_names); >> -} >> - >> static void plt_clk_unregister_loop(struct clk_plt_data *data, >> unsigned int i) >> { >> @@ -286,8 +278,8 @@ static const char **plt_clk_register_parents(struct platform_device *pdev, >> if (!data->parents) >> return ERR_PTR(-ENOMEM); >> >> - parent_names = kcalloc(nparents, sizeof(*parent_names), >> - GFP_KERNEL); >> + parent_names = devm_kcalloc(&pdev->dev, nparents, >> + sizeof(*parent_names), GFP_KERNEL); >> if (!parent_names) >> return ERR_PTR(-ENOMEM); >> >> @@ -300,7 +292,8 @@ static const char **plt_clk_register_parents(struct platform_device *pdev, >> err = PTR_ERR(data->parents[i]); >> goto err_unreg; >> } >> - parent_names[i] = kstrdup_const(clks[i].name, GFP_KERNEL); >> + parent_names[i] = devm_kstrdup_const(&pdev->dev, >> + clks[i].name, GFP_KERNEL); >> } >> >> data->nparents = nparents; >> @@ -308,7 +301,6 @@ static const char **plt_clk_register_parents(struct platform_device *pdev, >> >> err_unreg: >> plt_clk_unregister_fixed_rate_loop(data, i); >> - plt_clk_free_parent_names_loop(parent_names, i); > > What happens if clks[i].name is not a part of RO data? The devm_kstrdup_const > will allocate memory and nothing will ever free it... > I'm looking at it and trying to see if I'm missing something, but AFAIK the whole concept of devm_* is to leave out the resource management part. devm_kstrdup_const() will internally call devm_kstrdup() for strings that are not in .rodata and once the device is detached, the string will be freed (or not if it's in .rodata). BR Bart > And, please don't drop kfree(parent_names) here. > >> return ERR_PTR(err); >> } >> >> @@ -351,15 +343,12 @@ static int plt_clk_probe(struct platform_device *pdev) >> goto err_unreg_clk_plt; >> } >> >> - plt_clk_free_parent_names_loop(parent_names, data->nparents); >> - >> platform_set_drvdata(pdev, data); >> return 0; >> >> err_unreg_clk_plt: >> plt_clk_unregister_loop(data, i); >> plt_clk_unregister_parents(data); >> - plt_clk_free_parent_names_loop(parent_names, data->nparents); > > Ditto. > >> return err; >> } >> >> -- >> 2.18.0 >> > > -- > Sincerely yours, > Mike. >