From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C75B1C25B08 for ; Sat, 6 Aug 2022 02:29:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241658AbiHFC3M (ORCPT ); Fri, 5 Aug 2022 22:29:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237982AbiHFC3J (ORCPT ); Fri, 5 Aug 2022 22:29:09 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7EA02286F9 for ; Fri, 5 Aug 2022 19:29:07 -0700 (PDT) Received: from dggpemm500024.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4M05vX5qM9zmVJS; Sat, 6 Aug 2022 10:27:04 +0800 (CST) Received: from dggpemm500001.china.huawei.com (7.185.36.107) by dggpemm500024.china.huawei.com (7.185.36.203) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sat, 6 Aug 2022 10:29:04 +0800 Received: from [10.174.177.243] (10.174.177.243) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Sat, 6 Aug 2022 10:29:04 +0800 Message-ID: <832b38ca-064e-0ab8-cd62-337d0d83d471@huawei.com> Date: Sat, 6 Aug 2022 10:29:03 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: [PATCH 01/11] mm/ioremap: change the return value of io[re|un]map_allowed Content-Language: en-US To: Alexander Gordeev , Baoquan He CC: , , , , References: <20220801144029.57829-1-bhe@redhat.com> <20220801144029.57829-2-bhe@redhat.com> From: Kefeng Wang In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.177.243] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2022/8/4 23:42, Alexander Gordeev wrote: > On Mon, Aug 01, 2022 at 10:40:19PM +0800, Baoquan He wrote: > > Hi Baoquan, > >> --- a/arch/arm64/mm/ioremap.c >> +++ b/arch/arm64/mm/ioremap.c >> @@ -3,19 +3,20 @@ >> #include >> #include >> >> -bool ioremap_allowed(phys_addr_t phys_addr, size_t size, unsigned long prot) >> +void __iomem *ioremap_allowed(phys_addr_t phys_addr, size_t size, unsigned long prot) >> { >> unsigned long last_addr = phys_addr + size - 1; >> + int ret = -EINVAL; > If ret variable is really needed? > >> diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h >> index 72974cb81343..d72eb310fb3c 100644 >> --- a/include/asm-generic/io.h >> +++ b/include/asm-generic/io.h >> @@ -967,26 +967,27 @@ static inline void iounmap(volatile void __iomem *addr) >> /* >> * Arch code can implement the following two hooks when using GENERIC_IOREMAP >> * ioremap_allowed() return a bool, >> - * - true means continue to remap >> - * - false means skip remap and return directly >> + * - IS_ERR means return an error >> + * - NULL means continue to remap >> + * - a non-NULL, non-IS_ERR pointer is returned directly > If ioremap_allowed() returns a valid pointer, then the function name > is not as precise anymore. Maybe use arch_ioremap/unmap as before, or some better name. > >> @@ -28,8 +29,11 @@ void __iomem *ioremap_prot(phys_addr_t phys_addr, size_t size, >> phys_addr -= offset; >> size = PAGE_ALIGN(size + offset); >> >> - if (!ioremap_allowed(phys_addr, size, prot)) >> + base = ioremap_allowed(phys_addr, size, prot); >> + if (IS_ERR(base)) >> return NULL; >> + else if (base) >> + return base; > It is probably just me, but the base name bit misleading here. We could reuse vaddr, not add new base. > >> @@ -50,9 +54,9 @@ EXPORT_SYMBOL(ioremap_prot); >> >> void iounmap(volatile void __iomem *addr) >> { >> - void *vaddr = (void *)((unsigned long)addr & PAGE_MASK); >> + void __iomem *vaddr = (void __iomem *)((unsigned long)addr & PAGE_MASK); >> >> - if (!iounmap_allowed(vaddr)) >> + if (iounmap_allowed(vaddr)) > I guess, iounmap_allowed() should accept void __iomem *, not void *. > Then addr needs to be passed to iounmap_allowed() not vaddr. The following is_vmalloc_addr()  and vunmap() in iounmap() use void *, so we could simply use void* for iounmap_allowed(). > >> return; > .