Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp5882938imm; Mon, 27 Aug 2018 06:06:44 -0700 (PDT) X-Google-Smtp-Source: ANB0VdanahJgM7AdBEVf215W9o7rXgLfJ6ruX8fwyi3hYdxYtZtRxlA+V2hJMHQTY2990FVfLSJB X-Received: by 2002:a63:c245:: with SMTP id l5-v6mr12219612pgg.255.1535375204428; Mon, 27 Aug 2018 06:06:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535375204; cv=none; d=google.com; s=arc-20160816; b=omFLz3qi5B4/RGqLoL3ejjwW7oPREuMwsSh9r7sZ8Hp/m3i3vRMtsHwBiyO+S+Rbkk CBCQYh1av3hQB64lUYCXS4l+ARUjYyGRFHFPWUz358a0YqT5tntLexaPuj6ID+yycKFN hvp6dBSBd9EFIDPsHTXqUIpuORVm09aw3ZesHMF9Nt0NWuNWSwjJSJaEbDdwpI1ip0Bk yL8cMYq4pMiLQPqVgP3q6xgxBaOAzqbJpkuUpVFw1O9lGcI5UDvVDD464V26ZtKagvyi nUWyJDsTJGT2eMyK4mSpEF9vSVxjDHiKTYJPMWVFC30ohEy0RlvEfryd5RW/0m02yj8r STbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:user-agent:in-reply-to :content-disposition:mime-version:references:subject:cc:to:from:date :arc-authentication-results; bh=HRBZJh0H+yuefTovaw4nacntAB+ynW3FVurMBmOeIEQ=; b=Dgb1K056U82KwpQDAsCK//YWCiLcCJQGwyDLqMKt9JFAsEbzaNJX8lIdcnU0+Dtf/P Zq2g3TrQ1RLW4D6bL3JZfMQhBl4NKKdGM5TnAPx2R7bN6PvjU9Cpicn8gee0Ssaea0mb O8Xs1vXXZyLZrOL7fbOTe7yL/6A6s0DSnIpzYz0/wnUHcDXkuo8L2jQZi0uCSZDZfV+D lDCHEvfQZkY3sAeAkxBIM7a4jjiMAxms//sEp9GnhrOOAxsi+nVboxaQ1WixBoUGvrld QW6NS8kgj7Dh9p4tqAW2h6PvbnQ2dVUHGbuBRK9YWm6SKR6oVtoNiXCxYJdbpYdOvEQQ XDLA== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z21-v6si12314723pgu.163.2018.08.27.06.06.28; Mon, 27 Aug 2018 06:06:44 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727101AbeH0Qvg (ORCPT + 99 others); Mon, 27 Aug 2018 12:51:36 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:36744 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726883AbeH0Qvg (ORCPT ); Mon, 27 Aug 2018 12:51:36 -0400 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w7RD4uvu116613 for ; Mon, 27 Aug 2018 09:05:01 -0400 Received: from e06smtp07.uk.ibm.com (e06smtp07.uk.ibm.com [195.75.94.103]) by mx0a-001b2d01.pphosted.com with ESMTP id 2m4gj4ues2-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 27 Aug 2018 09:05:00 -0400 Received: from localhost by e06smtp07.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 27 Aug 2018 14:04:57 +0100 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp07.uk.ibm.com (192.168.101.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Mon, 27 Aug 2018 14:04:50 +0100 Received: from d06av21.portsmouth.uk.ibm.com (d06av21.portsmouth.uk.ibm.com [9.149.105.232]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w7RD4nNW41353312 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 27 Aug 2018 13:04:49 GMT Received: from d06av21.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 27F6C5204F; Mon, 27 Aug 2018 16:04:47 +0100 (BST) Received: from rapoport-lnx (unknown [9.148.8.97]) by d06av21.portsmouth.uk.ibm.com (Postfix) with ESMTPS id 97E6A52078; Mon, 27 Aug 2018 16:04:45 +0100 (BST) Date: Mon, 27 Aug 2018 16:04:46 +0300 From: Mike Rapoport To: Bartosz Golaszewski 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 Subject: Re: [PATCH 2/2] clk: pmc-atom: use devm_kstrdup_const() References: <20180827082101.5036-1-brgl@bgdev.pl> <20180827082101.5036-2-brgl@bgdev.pl> <20180827103915.GC13848@rapoport-lnx> <20180827125226.GD13848@rapoport-lnx> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) X-TM-AS-GCONF: 00 x-cbid: 18082713-0028-0000-0000-000002F0482A X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18082713-0029-0000-0000-000023A99BA3 Message-Id: <20180827130446.GE13848@rapoport-lnx> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-08-27_05:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=2 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1807170000 definitions=main-1808270140 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Aug 27, 2018 at 02:58:46PM +0200, Bartosz Golaszewski wrote: > 2018-08-27 14:52 GMT+02:00 Mike Rapoport : > > On Mon, Aug 27, 2018 at 02:28:45PM +0200, Bartosz Golaszewski wrote: > >> 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). > > > > And when it's going to be freed, how the resource management will know > > whether it's .rodata or not? > > > > If the string to be duplicated is in .rodata, it's returned as is from > devm_kstrdup_const(). Never gets added to the devres list, never get's > freed. When the string to be duplicated is not in .rodata, > devm_kstrdup() is called from devm_kstrdup_const(). Now the string is > in the devres list of this device and it will get freed on driver > detach. I really don't see what else could be a problem here. Thanks for the clarification. I think that it's worth adding a similar explanation to the changelog of the first patch. > BR > Bart > > >> 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. > >> > > >> > > > > -- > > Sincerely yours, > > Mike. > > > -- Sincerely yours, Mike.