Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp4865940imm; Tue, 9 Oct 2018 06:29:03 -0700 (PDT) X-Google-Smtp-Source: ACcGV60ovkRetyzHiuIb29SZcgLbDMIt/3kRCElYBNsdOH9q0iPCyQNCa7cGDGOoxImoL3XH4DOj X-Received: by 2002:a62:2542:: with SMTP id l63-v6mr24228465pfl.64.1539091743254; Tue, 09 Oct 2018 06:29:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539091743; cv=none; d=google.com; s=arc-20160816; b=v45PGMPAUQHJbiCBXzlsNXweTIr8bvy47z6oquplHpWtaLhluZ8rj+dLsjb7/3HpQJ Ihec3YSguu7I8Zw4uhkqs8XMWtHuFfVgy4djRp2gLQ+ONbAbFmHMkdWx1DYHQMz7SynE HU5QjlW+zSBe4iH+rjQ0t+uPq+ekaoMmnyI2B3w+H2b6jv+2NoN5hfZglwsDp14jH/dB 9viQHse1CfwN6Dr7Zwngi6bCTwdqxwvMnfjBFLVrXLH3f0UqkEATj7KzXXGqgIdgYdAs QX9s+mPNJEQjAHs1wKjlX3VQ36Mmf2C7I0sFAM38zRja6+/Rjq+1FCqPHd/75u2Nijyi mBJQ== 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:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=VVrA3gX4S4aK9b26/sI5R8iiOEO8w46y03v4nt2GxbY=; b=JrYlhaD3J9aXdLh795mv/KnFMOGKIT7qsN9wcCGkctW5P2hB/Yg1ZQRCP3EJ22qaRq fCNE+yDdBNbZHt/GYHoawxn+Imiz3k/SqcY1L7HUP/LmhvK3aNC/SUeFN9k997Bp7F6c NcRmMGYemfyemD91tLY1ZhhhgQCBnqgvm1EiusedeVPXCrnIJPHiMP1gmcoHddOdimlB cfImMq3NPgmVZlMRQF2nU8Bl4b6IqJKkegnAO+B7lYj/Sojx5lCPZZfNQW1GX8rA6K0a Mhd/9n4J+iXIxkw4zZsmGCSYafFqquqf1KtsLYuU8PXLPTOsuumHBsdA1pjb36GgUT/u DR+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=JvHYW2+N; 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 s6-v6si21079759pgc.133.2018.10.09.06.28.48; Tue, 09 Oct 2018 06:29:03 -0700 (PDT) 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; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=JvHYW2+N; 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 S1727689AbeJIUnT (ORCPT + 99 others); Tue, 9 Oct 2018 16:43:19 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:49942 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727080AbeJIUnS (ORCPT ); Tue, 9 Oct 2018 16:43:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From :Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=VVrA3gX4S4aK9b26/sI5R8iiOEO8w46y03v4nt2GxbY=; b=JvHYW2+NRx9uTFwvGoZUB3K994 Ltj4pFTEi1yyA7kwBwtmRHbedPTrG3gCPqY3wCtb3bZJEHjCU/sqzXnuLSNkRz+Gvu7vpO0Rls4T3 CEuP5xLYrWxsf1knWSzpOzUEjS/OdZMAKeCH2kieVo4v18xgHP53xYO+2HBmp6cuRYbJiS6eSWB9t KdmnUzrgjecB0KlFQoVB+hDIWFA7Gby/cIUFD544mthDIRFUSigTLJw/Hmmc1Z5LdqBHR3DB+daMT GFAtYLTlaT7t9DmlVXFMS50N0RdDWG4thjLXBau8unoiIp7Q7coMJg57S/4wMHn4/1Iu1QPE9dC9G WbMOli/w==; Received: from clnet-p19-102.ikbnet.co.at ([83.175.77.102] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1g9s1T-0001Rf-QG; Tue, 09 Oct 2018 13:26:04 +0000 From: Christoph Hellwig To: Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Cc: linuxppc-dev@lists.ozlabs.org, iommu@lists.linux-foundation.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 24/33] powerpc/dma: fix an off-by-one in dma_capable Date: Tue, 9 Oct 2018 15:24:51 +0200 Message-Id: <20181009132500.17643-25-hch@lst.de> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181009132500.17643-1-hch@lst.de> References: <20181009132500.17643-1-hch@lst.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We need to compare the last byte in the dma range and not the one after it for the bus_dma_mask, just like we do for the regular dma_mask. Fix this cleanly by merging the two comparisms into one. Signed-off-by: Christoph Hellwig --- arch/powerpc/include/asm/dma-direct.h | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/arch/powerpc/include/asm/dma-direct.h b/arch/powerpc/include/asm/dma-direct.h index e00ab5d0612d..92d8aed86422 100644 --- a/arch/powerpc/include/asm/dma-direct.h +++ b/arch/powerpc/include/asm/dma-direct.h @@ -4,15 +4,11 @@ static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size) { -#ifdef CONFIG_SWIOTLB - if (dev->bus_dma_mask && addr + size > dev->bus_dma_mask) - return false; -#endif - if (!dev->dma_mask) return false; - return addr + size - 1 <= *dev->dma_mask; + return addr + size - 1 <= + min_not_zero(*dev->dma_mask, dev->bus_dma_mask); } static inline dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr) -- 2.19.0