Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2386682imm; Mon, 24 Sep 2018 03:34:18 -0700 (PDT) X-Google-Smtp-Source: ACcGV6354L+ppT1k/Rfbt7V8rqVMQfjP+AXHfTa31veQtdP1tbUcrdFUEWAcBvHqq5OSolRNREpa X-Received: by 2002:a63:1921:: with SMTP id z33-v6mr9123243pgl.302.1537785258468; Mon, 24 Sep 2018 03:34:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537785258; cv=none; d=google.com; s=arc-20160816; b=luVmCXCUMZfI720hrj+IfwMFJcuNMD7Hn83Tt9ZLEoRYIF4PCyx/ydZMV76tI4eUkg oVSwHw8Oa/fFVazNdXilbgprIzV8V0jTNYFWk0643KIRq0AqT2+q9GaCB2hUWNkp5tAm VGsKOpzCJH9bSVp3v/DveoI3wRn6z2mH4DqQ44ke6tRxJWkL1tsW/r/blty96mxVZvw6 8l/y8ZJDGoAaQh2YIBsdL49Svm/17pBo8ge2Fx9qpJcPJuFwP8oVFYwZ0mhn0eXPaNzf qWd7jmDqNDfIiyz8dZ0JKzibZQWUqgQsJtTR7miZkZPEchFRY0b4sgdWxT4HQLlEq0vh E5bg== 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; bh=Pm6tcjAI/qXZ+UD/BKyesbK6vzrl3ry0jS/848aA69o=; b=vAFQOLX54bYdv9xRlfxTIFF7U0m9s9OidCraoySZQhKaxBFhYR6ouMbysREYwXze2X bhIcADWrCIaEcdbh1JXwtkOPnHjWuorDskZseZ35s0X20z8nPOvhMxko/ft1yGg1azmq +Gt0l2ZBJb0JSmBOO5ISQ6xB3J3zfOkMEHD0FBNdiFZPK/9Pr5k1hjqObqKgSNyw7gFb yJe8NHxRgy9BwTlF1CScTe9ItJUuGT4VNTQ9dDqs6eO+IS1Jw2FKnPRTUi6b/kFV3j5W RQAv9LDbMQRPK5SYGNo6j1WqNs+DxGuNhhfxmJM3RsxkR4D16lskYJtlChfrsxYS2HRR 5j1Q== 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 c4-v6si35724456pfa.285.2018.09.24.03.34.02; Mon, 24 Sep 2018 03:34: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; 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 S1728562AbeIXQdq (ORCPT + 99 others); Mon, 24 Sep 2018 12:33:46 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:33576 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727771AbeIXQdq (ORCPT ); Mon, 24 Sep 2018 12:33:46 -0400 Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w8OATmkX000950 for ; Mon, 24 Sep 2018 06:32:21 -0400 Received: from e06smtp05.uk.ibm.com (e06smtp05.uk.ibm.com [195.75.94.101]) by mx0a-001b2d01.pphosted.com with ESMTP id 2mpuywe0cd-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Mon, 24 Sep 2018 06:32:21 -0400 Received: from localhost by e06smtp05.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 24 Sep 2018 11:32:18 +0100 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp05.uk.ibm.com (192.168.101.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Mon, 24 Sep 2018 11:32:12 +0100 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w8OAWBDr52101212 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Mon, 24 Sep 2018 10:32:11 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7781DAE053; Mon, 24 Sep 2018 13:31:13 +0100 (BST) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 317F9AE045; Mon, 24 Sep 2018 13:31:09 +0100 (BST) Received: from rapoport-lnx (unknown [9.148.206.170]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Mon, 24 Sep 2018 13:31:09 +0100 (BST) Date: Mon, 24 Sep 2018 13:32:05 +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 , Arnd Bergmann , Andy Shevchenko , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH v3 3/4] devres: provide devm_kstrdup_const() References: <20180924101150.23349-1-brgl@bgdev.pl> <20180924101150.23349-4-brgl@bgdev.pl> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180924101150.23349-4-brgl@bgdev.pl> User-Agent: Mutt/1.5.24 (2015-08-30) X-TM-AS-GCONF: 00 x-cbid: 18092410-0020-0000-0000-000002CAC99E X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18092410-0021-0000-0000-00002118DD36 Message-Id: <20180924103204.GC6264@rapoport-lnx> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2018-09-24_06:,, 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-1809240110 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 24, 2018 at 12:11:49PM +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 and returns the string as is otherwise. > > Also provide a corresponding version of devm_kfree(). > > Signed-off-by: Bartosz Golaszewski > Reviewed-by: Bjorn Andersson Acked-by: Mike Rapoport > --- > drivers/base/devres.c | 38 ++++++++++++++++++++++++++++++++++++++ > include/linux/device.h | 3 +++ > 2 files changed, 41 insertions(+) > > diff --git a/drivers/base/devres.c b/drivers/base/devres.c > index 438c91a43508..48185d57bc5b 100644 > --- a/drivers/base/devres.c > +++ b/drivers/base/devres.c > @@ -11,6 +11,8 @@ > #include > #include > > +#include > + > #include "base.h" > > struct devres_node { > @@ -822,6 +824,28 @@ char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp) > } > EXPORT_SYMBOL_GPL(devm_kstrdup); > > +/** > + * 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 > + * > + * Strings allocated by devm_kstrdup_const will be automatically freed when > + * the associated device is detached. > + * > + * RETURNS: > + * Source string if it is in .rodata section otherwise it falls back to > + * devm_kstrdup. > + */ > +const 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); > + > /** > * devm_kvasprintf - Allocate resource managed space and format a string > * into that. > @@ -895,6 +919,20 @@ void devm_kfree(struct device *dev, const void *p) > } > EXPORT_SYMBOL_GPL(devm_kfree); > > +/** > + * devm_kfree_const - Resource managed conditional kfree > + * @dev: device this memory belongs to > + * @p: memory to free > + * > + * Function calls devm_kfree only if @p is not in .rodata section. > + */ > +void devm_kfree_const(struct device *dev, const void *p) > +{ > + if (!is_kernel_rodata((unsigned long)p)) > + devm_kfree(dev, p); > +} > +EXPORT_SYMBOL(devm_kfree_const); > + > /** > * devm_kmemdup - Resource-managed kmemdup > * @dev: Device this memory belongs to > diff --git a/include/linux/device.h b/include/linux/device.h > index 33f7cb271fbb..79ccc6eb0975 100644 > --- a/include/linux/device.h > +++ b/include/linux/device.h > @@ -693,7 +693,10 @@ static inline void *devm_kcalloc(struct device *dev, > return devm_kmalloc_array(dev, n, size, flags | __GFP_ZERO); > } > extern void devm_kfree(struct device *dev, const void *p); > +extern void devm_kfree_const(struct device *dev, const void *p); > extern char *devm_kstrdup(struct device *dev, const char *s, gfp_t gfp) __malloc; > +extern const char *devm_kstrdup_const(struct device *dev, > + const char *s, gfp_t gfp); > extern void *devm_kmemdup(struct device *dev, const void *src, size_t len, > gfp_t gfp); > > -- > 2.18.0 > -- Sincerely yours, Mike.