Received: by 10.223.185.116 with SMTP id b49csp2032313wrg; Mon, 12 Feb 2018 03:09:45 -0800 (PST) X-Google-Smtp-Source: AH8x227FTlflXFIxEiYxTjahpNDcBiDd29396H7vtR9jMVu4o8mlIrlbGIsz7lVy2g1DGzNuy37v X-Received: by 10.101.86.15 with SMTP id l15mr9283832pgs.340.1518433785452; Mon, 12 Feb 2018 03:09:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518433785; cv=none; d=google.com; s=arc-20160816; b=q1kyp4VzWNGxl/afp4FmxobdAzz/pwwW1ocJqujk3czoZKJhriK/pjQUMjHBtbDOfK byEsu2VQxb+I5y5Es+slrAidhP7BMriS942a1cWciwmyBzkRaO+06CDV5+N+gdhSnTlM Ndj+9RKEOGGctqGcjnAbsaFeCd/OynX7AXzs7SRn8dbez4vDcfcnJkPhrEYQJLqyKjzE puQg1gB9rECM8fdR1JjNadbrzOS54bzY3bJw84jfBrPkONiftCfos6AxjpxNsRuj1Kl3 WndUmhgfCyoErl1f/hKPdGMNfDvWudGP1166BonsuFxpyAVPOitrS85l59S2Q6aA1hOo ahZQ== 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:in-reply-to :mime-version:user-agent:date:message-id:from:cc:references:to :subject:arc-authentication-results; bh=LOHDMFeStRVXidTasnNvqiyRFmNBR2fIJtWQmcqmo68=; b=AxGo6CUI7qwnHCCVFwod1PGvdFv7gAwAbnfIPMEzUC5Jpl3Ts1ng0uZvTVKjVcQh1J SmX8ojz5MLszLz72ptDxa0PHaM/xWlgrP28apMGZF/DDQdGrknbl1So+GG0TlDP4dnUv YVKMKfYfroKN0OdPk0nvcyejtnlZ1J1islI1efwmzULZFX1jZW53xE2PuyJKCP/fIoZw MspOQcul3OE6VrUlwSKe1+FFzW237xtjcey/lEXeuCLIQMVMc0rIqZtT7w1KGY8/p+iP SXS/o+RvPo8X0Oe6i0B0Ud9ik0uWq41k8zUU5RXZAkrVa5LItp0xn3cx6tY7ysmZ2Bde 9+xQ== 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 m8si4981876pgn.343.2018.02.12.03.09.30; Mon, 12 Feb 2018 03:09:45 -0800 (PST) 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 S933987AbeBLLH5 (ORCPT + 99 others); Mon, 12 Feb 2018 06:07:57 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:5205 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933581AbeBLLHz (ORCPT ); Mon, 12 Feb 2018 06:07:55 -0500 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 0E082E8838EDA; Mon, 12 Feb 2018 19:07:43 +0800 (CST) Received: from [127.0.0.1] (10.177.29.40) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.361.1; Mon, 12 Feb 2018 19:07:41 +0800 Subject: Re: [PATCH v6] devres: combine function devm_ioremap* To: References: <1517226496-32324-1-git-send-email-xieyisheng1@huawei.com> CC: , , From: Yisheng Xie Message-ID: Date: Mon, 12 Feb 2018 19:07:34 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.1.0 MIME-Version: 1.0 In-Reply-To: <1517226496-32324-1-git-send-email-xieyisheng1@huawei.com> Content-Type: text/plain; charset="windows-1252" Content-Transfer-Encoding: 7bit X-Originating-IP: [10.177.29.40] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Greg, Christophe, Any comment about this version? And sorry to disturb :) Thanks Yisheng On 2018/1/29 19:48, Yisheng Xie wrote: > When I tried to use devm_ioremap function and review related > code, I found devm_ioremap_* almost have the similar realize > with each other, which can be combined. > > In the former version, I have tried to kill ioremap_cache to > reduce the size of devres, which can not work for ioremap is > not the same as ioremap_nocache in some ARCHs likes ia64. > Therefore, as the suggestion of Christophe, I introduce a help > function __devm_ioremap, let devm_ioremap* inline and call > __devm_ioremap with different devm_ioremap_type. > > After apply the patch, the size of devres.o can be reduce from > 8216 Bytes to 8052 Bytes in my compile environment. > > Suggested-by: Greg KH > Suggested-by: Christophe LEROY > Signed-off-by: Yisheng Xie > --- > v2: > - use MARCO for ioremap > v3: > - kill dev_ioremap_nocache > v4: > - combine function devm_ioremap* - per Christophe > v5: > - fix code style. - per Christophe > v6: > - just put the cleanup in the devres.c - per Greg > > lib/devres.c | 78 +++++++++++++++++++++++++++++------------------------------- > 1 file changed, 38 insertions(+), 40 deletions(-) > > diff --git a/lib/devres.c b/lib/devres.c > index 5f2aedd..5bec112 100644 > --- a/lib/devres.c > +++ b/lib/devres.c > @@ -5,6 +5,12 @@ > #include > #include > > +enum devm_ioremap_type { > + DEVM_IOREMAP = 0, > + DEVM_IOREMAP_NC, > + DEVM_IOREMAP_WC, > +}; > + > void devm_ioremap_release(struct device *dev, void *res) > { > iounmap(*(void __iomem **)res); > @@ -15,24 +21,28 @@ static int devm_ioremap_match(struct device *dev, void *res, void *match_data) > return *(void **)res == match_data; > } > > -/** > - * devm_ioremap - Managed ioremap() > - * @dev: Generic device to remap IO address for > - * @offset: Resource address to map > - * @size: Size of map > - * > - * Managed ioremap(). Map is automatically unmapped on driver detach. > - */ > -void __iomem *devm_ioremap(struct device *dev, resource_size_t offset, > - resource_size_t size) > +static void __iomem *__devm_ioremap(struct device *dev, resource_size_t offset, > + resource_size_t size, > + enum devm_ioremap_type type) > { > - void __iomem **ptr, *addr; > + void __iomem **ptr, *addr = NULL; > > ptr = devres_alloc(devm_ioremap_release, sizeof(*ptr), GFP_KERNEL); > if (!ptr) > return NULL; > > - addr = ioremap(offset, size); > + switch (type) { > + case DEVM_IOREMAP: > + addr = ioremap(offset, size); > + break; > + case DEVM_IOREMAP_NC: > + addr = ioremap_nocache(offset, size); > + break; > + case DEVM_IOREMAP_WC: > + addr = ioremap_wc(offset, size); > + break; > + } > + > if (addr) { > *ptr = addr; > devres_add(dev, ptr); > @@ -41,6 +51,20 @@ void __iomem *devm_ioremap(struct device *dev, resource_size_t offset, > > return addr; > } > + > +/** > + * devm_ioremap - Managed ioremap() > + * @dev: Generic device to remap IO address for > + * @offset: Resource address to map > + * @size: Size of map > + * > + * Managed ioremap(). Map is automatically unmapped on driver detach. > + */ > +void __iomem *devm_ioremap(struct device *dev, resource_size_t offset, > + resource_size_t size) > +{ > + return __devm_ioremap(dev, offset, size, DEVM_IOREMAP); > +} > EXPORT_SYMBOL(devm_ioremap); > > /** > @@ -55,20 +79,7 @@ void __iomem *devm_ioremap(struct device *dev, resource_size_t offset, > void __iomem *devm_ioremap_nocache(struct device *dev, resource_size_t offset, > resource_size_t size) > { > - void __iomem **ptr, *addr; > - > - ptr = devres_alloc(devm_ioremap_release, sizeof(*ptr), GFP_KERNEL); > - if (!ptr) > - return NULL; > - > - addr = ioremap_nocache(offset, size); > - if (addr) { > - *ptr = addr; > - devres_add(dev, ptr); > - } else > - devres_free(ptr); > - > - return addr; > + return __devm_ioremap(dev, offset, size, DEVM_IOREMAP_NC); > } > EXPORT_SYMBOL(devm_ioremap_nocache); > > @@ -83,20 +94,7 @@ void __iomem *devm_ioremap_nocache(struct device *dev, resource_size_t offset, > void __iomem *devm_ioremap_wc(struct device *dev, resource_size_t offset, > resource_size_t size) > { > - void __iomem **ptr, *addr; > - > - ptr = devres_alloc(devm_ioremap_release, sizeof(*ptr), GFP_KERNEL); > - if (!ptr) > - return NULL; > - > - addr = ioremap_wc(offset, size); > - if (addr) { > - *ptr = addr; > - devres_add(dev, ptr); > - } else > - devres_free(ptr); > - > - return addr; > + return __devm_ioremap(dev, offset, size, DEVM_IOREMAP_WC); > } > EXPORT_SYMBOL(devm_ioremap_wc); > >