Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751388AbdIOPDf (ORCPT ); Fri, 15 Sep 2017 11:03:35 -0400 Received: from mail-io0-f196.google.com ([209.85.223.196]:36177 "EHLO mail-io0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751111AbdIOPDe (ORCPT ); Fri, 15 Sep 2017 11:03:34 -0400 X-Google-Smtp-Source: AOwi7QDrs6KIkBWpW7RdxOY5IqZbN6/FZ3Ol7qTHyUckew0cQIBJQVzGPOLjP0x1lXTfB/mSXUcIN4f7Zq03dy9Uwes= MIME-Version: 1.0 In-Reply-To: References: <20170905081026.1198405-1-arnd@arndb.de> From: Arnd Bergmann Date: Fri, 15 Sep 2017 17:03:33 +0200 X-Google-Sender-Auth: 9II2CXzO12wv_06CiE8-to7yKDY Message-ID: Subject: Re: dma-coherent: fix dma_declare_coherent_memory() logic error To: Roy Pledge Cc: Christoph Hellwig , Marek Szyprowski , Greg Kroah-Hartman , Robin Murphy , Vladimir Murzin , Mark Craske , "George G. Davis" , Bastian Hecht , "iommu@lists.linux-foundation.org" , "linux-kernel@vger.kernel.org" Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2185 Lines: 52 >> @@ -338,14 +346,18 @@ static struct reserved_mem *dma_reserved_default_memory __initdata; >> static int rmem_dma_device_init(struct reserved_mem *rmem, struct device *dev) >> { >> struct dma_coherent_mem *mem = rmem->priv; >> + int ret; >> + >> + if (!mem) >> + return -ENODEV; > > When I picked up this change my use of of_reserved_mem_device_init() > broke. The only place rmem->priv is set is in this function (bottom of > the patch) so the !mem check above will always fail. Am I missing > something? It seems to me the intent here was to only call > dma_init_coherent_memory() once and use rmem->priv as a cache for future > calls but I'm just looking at the implemation of this for the first time. Yes, you are right, I misread that code. I think we need this fixup on top to restore the previous behavior: diff --git a/drivers/base/dma-coherent.c b/drivers/base/dma-coherent.c index a39b2166b145..744f64f43454 100644 --- a/drivers/base/dma-coherent.c +++ b/drivers/base/dma-coherent.c @@ -348,16 +348,15 @@ static int rmem_dma_device_init(struct reserved_mem *rmem, struct device *dev) struct dma_coherent_mem *mem = rmem->priv; int ret; - if (!mem) - return -ENODEV; - - ret = dma_init_coherent_memory(rmem->base, rmem->base, rmem->size, - DMA_MEMORY_EXCLUSIVE, &mem); - - if (ret) { - pr_err("Reserved memory: failed to init DMA memory pool at %pa, size %ld MiB\n", - &rmem->base, (unsigned long)rmem->size / SZ_1M); - return ret; + if (!mem) { + ret = dma_init_coherent_memory(rmem->base, rmem->base, + rmem->size, + DMA_MEMORY_EXCLUSIVE, &mem); + if (ret) { + pr_err("Reserved memory: failed to init DMA memory pool at %pa, size %ld MiB\n", + &rmem->base, (unsigned long)rmem->size / SZ_1M); + return ret; + } } mem->use_dev_dma_pfn_offset = true; rmem->priv = mem;