From patchwork Fri Jan 23 22:32:36 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Murali Karicheri X-Patchwork-Id: 5697891 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D6C789F357 for ; Fri, 23 Jan 2015 22:33:49 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EC5F920340 for ; Fri, 23 Jan 2015 22:33:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7C8E620304 for ; Fri, 23 Jan 2015 22:33:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752469AbbAWWdn (ORCPT ); Fri, 23 Jan 2015 17:33:43 -0500 Received: from comal.ext.ti.com ([198.47.26.152]:48424 "EHLO comal.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751877AbbAWWdm (ORCPT ); Fri, 23 Jan 2015 17:33:42 -0500 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id t0NMWlUS013213; Fri, 23 Jan 2015 16:32:47 -0600 Received: from DLEE71.ent.ti.com (dlee71.ent.ti.com [157.170.170.114]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id t0NMWk5c005023; Fri, 23 Jan 2015 16:32:46 -0600 Received: from dflp32.itg.ti.com (10.64.6.15) by DLEE71.ent.ti.com (157.170.170.114) with Microsoft SMTP Server id 14.3.224.2; Fri, 23 Jan 2015 16:32:46 -0600 Received: from ula0868495.itg.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id t0NMWgX9007161; Fri, 23 Jan 2015 16:32:45 -0600 From: Murali Karicheri To: , , , , CC: Murali Karicheri , Joerg Roedel , Grant Likely , Rob Herring , Bjorn Helgaas , Will Deacon , Russell King , Arnd Bergmann , Suravee Suthikulpanit Subject: [PATCH v4 3/6] of: fix size when dma-range is not used Date: Fri, 23 Jan 2015 17:32:36 -0500 Message-ID: <1422052359-12384-4-git-send-email-m-karicheri2@ti.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1422052359-12384-1-git-send-email-m-karicheri2@ti.com> References: <1422052359-12384-1-git-send-email-m-karicheri2@ti.com> MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Fix the dma-range size when the DT attribute is missing. i.e set size to dev->coherent_dma_mask + 1 instead of dev->coherent_dma_mask. To detect overflow when mask is set to max of u64, add a check, log error and return. Some platform use mask format for size in DTS. So add a work around to catch this and fix. Cc: Joerg Roedel Cc: Grant Likely Cc: Rob Herring Cc: Bjorn Helgaas Cc: Will Deacon Cc: Russell King Cc: Arnd Bergmann Cc: Suravee Suthikulpanit Signed-off-by: Murali Karicheri --- drivers/of/device.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/of/device.c b/drivers/of/device.c index 2de320d..0a5ff54 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -105,12 +105,24 @@ 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; + size = dev->coherent_dma_mask + 1; } else { offset = PFN_DOWN(paddr - dma_addr); + /* + * Add a work around to treat the size as mask + 1 in case + * it is defined in DT as a mask. + */ + if (size & 1) + size = size + 1; dev_dbg(dev, "dma_pfn_offset(%#08lx)\n", offset); } + /* if size is 0, we have an overflow of u64 */ + if (!size) { + dev_err(dev, "invalid size\n"); + return; + } + dev->dma_pfn_offset = offset; coherent = of_dma_is_coherent(np);