From nobody Fri Feb 13 01:40:23 2026 Received: from mail.nfschina.com (unknown [42.101.60.195]) by smtp.subspace.kernel.org (Postfix) with SMTP id EED611420DA for ; Tue, 4 Jun 2024 08:42:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=42.101.60.195 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717490534; cv=none; b=n4+OYhScvnBV72anYCanY4ik5JYD8J2S4CLDQPL1U6yFeLu8dAvy3XSSsa3wi3teRpfWJQ6GZHA5kVIEJiKk9SG39jKfibMk+xGN8vR3ly1rOBpQ+//JYNNsLWSsbCWDdOfi1bIYeHFrGz885oxNqaiut64KUYjwI6YW/2vMEds= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717490534; c=relaxed/simple; bh=IhCW5tPZwTtj5+YMsXpg5bHM6SkJlvgCSjrTIAYjZ5E=; h=From:To:Cc:Subject:Date:Message-Id; b=OVQF7pehrpbrV9rGH182l0LNta0d+UrykViC61JVy9+C2evM3EtYhmrnZppFjA8OUvyd6gKCDHUWegD25u4OTde6Yxlbht63PiWFNL2Xs40OQX1XwXgQ1ykMBHpD4Kd+9H9Tb6qi8KEYsxJMG7w4nIzCd1fDx9EGZZlbxITUrdo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nfschina.com; spf=pass smtp.mailfrom=nfschina.com; arc=none smtp.client-ip=42.101.60.195 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=nfschina.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nfschina.com Received: from localhost.localdomain (unknown [219.141.250.2]) by mail.nfschina.com (Maildata Gateway V2.8.8) with ESMTPA id 757C86048992C; Tue, 4 Jun 2024 16:41:54 +0800 (CST) X-MD-Sfrom: kunyu@nfschina.com X-MD-SrcIP: 219.141.250.2 From: kunyu To: hch@lst.de, m.szyprowski@samsung.com, robin.murphy@arm.com Cc: iommu@lists.linux.dev, linux-kernel@vger.kernel.org, kunyu Subject: [PATCH] dma: direct: Optimize the code for the dma_direct_free function Date: Tue, 4 Jun 2024 16:41:00 +0800 Message-Id: <20240604084100.51464-1-kunyu@nfschina.com> X-Mailer: git-send-email 2.18.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" The 'is_swiotlb-for-alloc' and 'dev_isdma_coherent' judgment functions need to be called multiple times, so they are adjusted to variable judgment, which can improve code conciseness. Signed-off-by: kunyu --- kernel/dma/direct.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/kernel/dma/direct.c b/kernel/dma/direct.c index 4d543b1e9d57..041e316ad4c0 100644 --- a/kernel/dma/direct.c +++ b/kernel/dma/direct.c @@ -315,23 +315,24 @@ void dma_direct_free(struct device *dev, size_t size, void *cpu_addr, dma_addr_t dma_addr, unsigned long attrs) { unsigned int page_order =3D get_order(size); + bool swiotlb_for_alloc =3D is_swiotlb_for_alloc(dev); + bool is_dma_coherent =3D dev_is_dma_coherent(dev); =20 if ((attrs & DMA_ATTR_NO_KERNEL_MAPPING) && - !force_dma_unencrypted(dev) && !is_swiotlb_for_alloc(dev)) { + !force_dma_unencrypted(dev) && !swiotlb_for_alloc) { /* cpu_addr is a struct page cookie, not a kernel address */ dma_free_contiguous(dev, cpu_addr, size); return; } =20 if (IS_ENABLED(CONFIG_ARCH_HAS_DMA_ALLOC) && - !dev_is_dma_coherent(dev) && - !is_swiotlb_for_alloc(dev)) { + !is_dma_coherent && !swiotlb_for_alloc) { arch_dma_free(dev, size, cpu_addr, dma_addr, attrs); return; } =20 if (IS_ENABLED(CONFIG_DMA_GLOBAL_POOL) && - !dev_is_dma_coherent(dev)) { + !is_dma_coherent) { if (!dma_release_from_global_coherent(page_order, cpu_addr)) WARN_ON_ONCE(1); return; --=20 2.18.2