From patchwork Mon Apr 10 11:21:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sricharan Ramabadhran X-Patchwork-Id: 9672417 X-Patchwork-Delegate: bhelgaas@google.com 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 44EFA600CB for ; Mon, 10 Apr 2017 11:25:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3AEA028111 for ; Mon, 10 Apr 2017 11:25:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2F8DD283E2; Mon, 10 Apr 2017 11:25:24 +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=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AFB3D282E8 for ; Mon, 10 Apr 2017 11:25:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753452AbdDJLW2 (ORCPT ); Mon, 10 Apr 2017 07:22:28 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:56030 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753372AbdDJLWX (ORCPT ); Mon, 10 Apr 2017 07:22:23 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id DE8D560B7D; Mon, 10 Apr 2017 11:22:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1491823337; bh=BjBYoLXlDXL7kOIIXo+glre3/G/4aJ+lp7uUBs4K6kY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W27QWnYsWZNRAdHmkspvFl50PllvnsiwrMHq9ncMvayYCv2fFjHvdswFGqF3ddcMF /gXAYW8Ey9VB2kbRGJeib6F29alw5uWH8w+ppiQr1opb+VSaVLOCISYMDYn2yFl+BJ PENydw766sTs98PaCUD/ivaMi2eBz2DCO4m8jwVo= 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 2AF4760CDE; Mon, 10 Apr 2017 11:22:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1491823336; bh=BjBYoLXlDXL7kOIIXo+glre3/G/4aJ+lp7uUBs4K6kY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OfE4yf0xkWWbqSJEmeo8ds+Q0tq6nu5UlXSpX9LfTSaQNuAy8niqbjEkbJ3PTV4+q kD+HcIIAURu9C5lG250ykbPp2nCcZxpKB76KuBFTyfpsqFFWtFpNWTdq4cUFOtjPrp luGTmcdvPrIADB8czmWRVq4z4J0SnLwST3/Y3V+c= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 2AF4760CDE 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 Cc: sricharan@codeaurora.org Subject: [PATCH V11 05/11] of: device: Fix overflow of coherent_dma_mask Date: Mon, 10 Apr 2017 16:51:00 +0530 Message-Id: <1491823266-1209-6-git-send-email-sricharan@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1491823266-1209-1-git-send-email-sricharan@codeaurora.org> References: <1491823266-1209-1-git-send-email-sricharan@codeaurora.org> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.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. Reviewed-by: Robin Murphy Acked-by: Rob Herring Signed-off-by: Sricharan R --- 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 0d378c0..e1ae9e7 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);