From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932819AbdDFGT3 (ORCPT ); Thu, 6 Apr 2017 02:19:29 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:35337 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755013AbdDFGTV (ORCPT ); Thu, 6 Apr 2017 02:19:21 -0400 From: frowand.list@gmail.com To: Rob Herring Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] of: change fixup of dma-ranges size to error Date: Wed, 5 Apr 2017 23:18:49 -0700 Message-Id: <1491459529-31391-1-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Frank Rowand of_dma_get_range() has workaround code to fixup a device tree that incorrectly specified a mask instead of a size for property dma-ranges. That device tree was fixed a year ago in v4.6, so the workaround is no longer needed. Leave a data validation check in place, but no longer do the fixup. Move the check one level deeper in the call stack so that other possible users of dma-ranges will also be protected. The fix to the device tree was in commit c91cb9123cdd ("dtb: amd: Fix DMA ranges in device tree"). Signed-off-by: Frank Rowand --- drivers/of/address.c | 12 +++++++++++- drivers/of/device.c | 15 --------------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/drivers/of/address.c b/drivers/of/address.c index 02b2903fe9d2..dae98923968f 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -829,6 +829,7 @@ int of_dma_get_range(struct device_node *np, u64 *dma_addr, u64 *paddr, u64 *siz int len, naddr, nsize, pna; int ret = 0; u64 dmaaddr; + u64 tmp_size; if (!node) return -EINVAL; @@ -879,7 +880,16 @@ int of_dma_get_range(struct device_node *np, u64 *dma_addr, u64 *paddr, u64 *siz } *dma_addr = dmaaddr; - *size = of_read_number(ranges + naddr + pna, nsize); + tmp_size = of_read_number(ranges + naddr + pna, nsize); + + /* check if mask specified instead of size */ + if (tmp_size & 1) { + pr_debug("invalid dma-range size in node: %s\n", np->full_name); + ret = -EINVAL; + goto out; + } + + *size = tmp_size; pr_debug("dma_addr(%llx) cpu_addr(%llx) size(%llx)\n", *dma_addr, *paddr, *size); diff --git a/drivers/of/device.c b/drivers/of/device.c index b1e6bebda3f3..09dedd045007 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -110,21 +110,6 @@ void of_dma_configure(struct device *dev, struct device_node *np) 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) { - dev_warn(dev, "Invalid size 0x%llx for dma-range\n", - size); - size = size + 1; - } - - if (!size) { - dev_err(dev, "Adjusted size 0x%llx invalid\n", size); - return; - } dev_dbg(dev, "dma_pfn_offset(%#08lx)\n", offset); } -- Frank Rowand