From patchwork Tue Apr 4 10:18:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sricharan Ramabadhran X-Patchwork-Id: 9661329 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6655860352 for ; Tue, 4 Apr 2017 10:53:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5904A27CF3 for ; Tue, 4 Apr 2017 10:53:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4D98327C0B; Tue, 4 Apr 2017 10:53:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D502127C0B for ; Tue, 4 Apr 2017 10:53:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=tacazBc/VLOyMiEMHIBeg62pv9cejlzOGf2eIy2L6K0=; b=qQt8HaMwsnYWMakC9ZZJL4MQcV r0Ic3sP0E+04k5umJ5e40TpubahYCryI1oU5gFbnx6tN0Jf7KA/vH8xqFLxXBcDmZeF6x3zh+0cNM eGTLPEcXXVuf59WyJpkkhHtpP6re+3AeAFcNlBnazXyH4L0E7+Ss/ngCsupEBPowXtOh14jFTXrKx RJ6VClTy/055M71uxrZpsiO2jeP84Ej8GkdfjpZB4COhXO/UyIn4eUDyVgSGbyZM+OLefeyywtGPo Pg3KX7U7cF9KPNScP8qNrgzIwTnMK+ocInVkho+TnsSGim/QJ+PgO7zeJADaJavxYA9q20NuOzJvH 3rHs2bqw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cvM5a-0001IY-UE; Tue, 04 Apr 2017 10:53:30 +0000 Received: from casper.infradead.org ([2001:770:15f::2]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cvM51-0008Tu-FX for linux-arm-kernel@bombadil.infradead.org; Tue, 04 Apr 2017 10:52:55 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding: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=ANwUxoBe/zumUH9VZ2Vc8FwWpOxE1YYyrEwE5ySawBk=; b=fj0mzpp3N0ptc1EQgwNSPavU/ UWo8hGzNTx7PrmDh6b3/wDqRRA8AJBNc+C+azseE5iRjtRczN8nZDqW7IJuQCklBZl+HHzt1VjiVz XHz9IPP6RBtyOUm4vtnk3rcuZRC1w8qDnFtkoD9zs/maWJpbJYdFMpXpjIRVwUwpprv1VFDAafN08 8zIvctE/4RkyUgV+esl/pyHAWQ1OCav8hPvlHq7B0wls3St/5jQ3qDmPQzy9WBk6Y1XJifwlSWeoZ i3H6B+knjldpOZUYlaO5HhIX3OkE/nIlQISYXZgVJD9OVZE/9qZm8LlL+qLXANPbiI/M0PQIyESdM 8+CRvjMQA==; Received: from smtp.codeaurora.org ([198.145.29.96]) by casper.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cvLZD-0005pB-Nu for linux-arm-kernel@lists.infradead.org; Tue, 04 Apr 2017 10:20:06 +0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 7716460F93; Tue, 4 Apr 2017 10:19:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1491301182; bh=EChKcurmEZsWxbaza5TxOvAKg8y2ujaNW/FLyz13jWk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=V2Dq4GQJFra5TqQYwEpfOz2iY1n1MLF5qRNsMQeLYGbzBvQzf3c6TQQd9clS4vZUL NO5GszdKWZyWK3S1T6JVH70cDsDXzEjoc25fzDQiWLj6wrBK6y0kr2GvKBRRvS4l/F LY3BZZKpfa1vZyMrA3xou0FB8aUrvGocc0H30FZs= Received: from srichara-linux.qualcomm.com (unknown [202.46.23.62]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: sricharan@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 4B79460F65; Tue, 4 Apr 2017 10:19:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1491301181; bh=EChKcurmEZsWxbaza5TxOvAKg8y2ujaNW/FLyz13jWk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LBS5TmRzSJ1kcaDsqbUS+UWLoI0qvIZ9xK44nOnW+vXF7dA3PiZgo6/EIRK3K4cjD Ur+VdIKwJJEvu+j+kL45fTDoMwI6LqP3i6sTphrbqUghE4+ZPkB1AqM1adiO7IRxso m0ix89Rw3OpzguTqvkQFZusPqFVArFfpGSOzN0HA= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 4B79460F65 Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=sricharan@codeaurora.org From: Sricharan R To: robin.murphy@arm.com, will.deacon@arm.com, joro@8bytes.org, lorenzo.pieralisi@arm.com, iommu@lists.linux-foundation.org, linux-arm-kernel@lists.infradead.org, linux-arm-msm@vger.kernel.org, m.szyprowski@samsung.com, bhelgaas@google.com, linux-pci@vger.kernel.org, linux-acpi@vger.kernel.org, tn@semihalf.com, hanjun.guo@linaro.org, okaya@codeaurora.org, robh+dt@kernel.org, frowand.list@gmail.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, sudeep.holla@arm.com, rjw@rjwysocki.net, lenb@kernel.org, catalin.marinas@arm.com, arnd@arndb.de, linux-arch@vger.kernel.org, gregkh@linuxfoundation.org Subject: [PATCH V10 06/12] of: device: Fix overflow of coherent_dma_mask Date: Tue, 4 Apr 2017 15:48:19 +0530 Message-Id: <1491301105-5274-7-git-send-email-sricharan@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1491301105-5274-1-git-send-email-sricharan@codeaurora.org> References: <1489086061-9356-1-git-send-email-sricharan@codeaurora.org> <1491301105-5274-1-git-send-email-sricharan@codeaurora.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170404_112004_082498_4FE6E306 X-CRM114-Status: GOOD ( 17.96 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: sricharan@codeaurora.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Size of the dma-range is calculated as coherent_dma_mask + 1 and passed to arch_setup_dma_ops further. It overflows when the coherent_dma_mask is set for full 64 bits 0xFFFFFFFFFFFFFFFF, resulting in size getting passed as 0 wrongly. Fix this by passsing in max(mask, mask + 1). Note that in this case when the mask is set to full 64bits, we will be passing the mask itself to arch_setup_dma_ops instead of the size. The real fix for this should be to make arch_setup_dma_ops receive the mask and handle it, to be done in the future. Signed-off-by: Sricharan R Reviewed-by: Robin Murphy --- drivers/of/device.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/of/device.c b/drivers/of/device.c index c17c19d..c2ae6bb 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -107,7 +107,7 @@ void of_dma_configure(struct device *dev, struct device_node *np) ret = of_dma_get_range(np, &dma_addr, &paddr, &size); if (ret < 0) { dma_addr = offset = 0; - size = dev->coherent_dma_mask + 1; + size = max(dev->coherent_dma_mask, dev->coherent_dma_mask + 1); } else { offset = PFN_DOWN(paddr - dma_addr); dev_dbg(dev, "dma_pfn_offset(%#08lx)\n", offset);