Received: by 10.223.176.5 with SMTP id f5csp2780010wra; Mon, 29 Jan 2018 03:58:31 -0800 (PST) X-Google-Smtp-Source: AH8x2274zBAc8HcZW2cXliKFEDC+qTOdP3tXSoxzDkoV+sKY/rMkO+vG0qrq8cmPrCTCwwclyFnG X-Received: by 10.98.69.82 with SMTP id s79mr26582006pfa.214.1517227111645; Mon, 29 Jan 2018 03:58:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517227111; cv=none; d=google.com; s=arc-20160816; b=vKn3ixJd23IfVTu61yNnwbbzZ4iEyKHEoc30+tH6xK/1XYCtFB+GgtSn18ctjgUNTz mVuLOgbMsVr2lebh5/dyJrz8z300n/b7GkwDmHxd6HcE1Kd2BLP0GOpYJLV79ZTWHlsm ob/+OWp35mY6ducmpV4dn+v8G6QpkTElAYAIb9q8jl7C3+gUdAoBXLBgWzijycW0bJH9 UKvhYJXZqHzmDJ80m7V2ytHcnWn85PT1EAV/LKkf4wwyWCdKJH2cMozzYy6TRAqhK6jR EZsUmx2j9TzCbkBmY5+5UTV2hIQSyInVMWEtxqpbd5tZJGyFXzz1mWHIsRpil+RvdN+b rIJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from:arc-authentication-results; bh=gsC81ihbVlqgEkGVRkuqXsMAPaUI7nPmSD/0gEEGExA=; b=j+Y3U4F82afU/l6IzTHLtYJqSR6yEeGRYJ9McJkNoSbBEGJ97yo61xL6mUa6QXrM+E aeSIxVAv0G5fww2UjHnw0kYMeAl3TDEyeAreJPhrlqfSmPEilhLDw0zhYOWLNwB4sbL9 LIuMeDjMlES+mizKOQBLjDwqpzqPYIC+FW23A7GwxQoESTmIQ/3dQ1dRh4ROk4o49XK2 OzJm0HHH4VHh2q3Ow6hoWLqvdGRX5dUTbvK/zaLKHILHDEVPrjbrKqGXA5VBfq+/ifMm WqPvDqoTnW2f/MVR3re61zofdfJzCEic6oi16W2PsvQpY6z04pM5HhkNBFcipqtHZXeG phig== 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 m23si7349286pgc.438.2018.01.29.03.58.16; Mon, 29 Jan 2018 03:58:31 -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 S1751791AbeA2L5R (ORCPT + 99 others); Mon, 29 Jan 2018 06:57:17 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:60442 "EHLO huawei.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751298AbeA2L5Q (ORCPT ); Mon, 29 Jan 2018 06:57:16 -0500 Received: from DGGEMS407-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id C5D9D317A9062; Mon, 29 Jan 2018 19:57:11 +0800 (CST) Received: from linux-ibm.site (10.175.102.37) by DGGEMS407-HUB.china.huawei.com (10.3.19.207) with Microsoft SMTP Server id 14.3.361.1; Mon, 29 Jan 2018 19:57:06 +0800 From: Yisheng Xie To: CC: , , , Subject: [PATCH v6] devres: combine function devm_ioremap* Date: Mon, 29 Jan 2018 19:48:16 +0800 Message-ID: <1517226496-32324-1-git-send-email-xieyisheng1@huawei.com> X-Mailer: git-send-email 1.7.12.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.102.37] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); -- 1.8.3.1