From patchwork Wed May 11 17:36:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rhyland Klein X-Patchwork-Id: 621219 X-Patchwork-Delegate: jonathanh@nvidia.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3r4jwy68Y5z9t0t for ; Thu, 12 May 2016 03:37:06 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752012AbcEKRhF (ORCPT ); Wed, 11 May 2016 13:37:05 -0400 Received: from hqemgate14.nvidia.com ([216.228.121.143]:4808 "EHLO hqemgate14.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752007AbcEKRhD (ORCPT ); Wed, 11 May 2016 13:37:03 -0400 Received: from hqnvupgp07.nvidia.com (Not Verified[216.228.121.13]) by hqemgate14.nvidia.com id ; Wed, 11 May 2016 10:37:03 -0700 Received: from HQHUB102.nvidia.com ([172.20.187.25]) by hqnvupgp07.nvidia.com (PGP Universal service); Wed, 11 May 2016 10:35:24 -0700 X-PGP-Universal: processed; by hqnvupgp07.nvidia.com on Wed, 11 May 2016 10:35:24 -0700 Received: from HQMAIL102.nvidia.com (172.18.146.10) by HQHUB102.nvidia.com (172.20.187.25) with Microsoft SMTP Server (TLS) id 8.3.406.0; Wed, 11 May 2016 10:37:02 -0700 Received: from HQMAIL107.nvidia.com (172.20.187.13) by HQMAIL102.nvidia.com (172.18.146.10) with Microsoft SMTP Server (TLS) id 15.0.1130.7; Wed, 11 May 2016 17:37:02 +0000 Received: from hqnvemgw01.nvidia.com (172.20.150.20) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server id 15.0.1130.7 via Frontend Transport; Wed, 11 May 2016 17:37:02 +0000 Received: from rklein-work.nvidia.com (Not Verified[10.2.71.84]) by hqnvemgw01.nvidia.com with Trustwave SEG (v7,5,5,8150) id ; Wed, 11 May 2016 10:37:02 -0700 From: Rhyland Klein To: Gavin Shan CC: Rob Herring , Jon Hunter , , , Rhyland Klein , Subject: [PATCH] drivers/of: Fix depth when unflattening devicetree Date: Wed, 11 May 2016 13:36:57 -0400 Message-ID: <1462988217-29314-1-git-send-email-rklein@nvidia.com> X-Mailer: git-send-email 1.9.1 X-NVConfidentiality: public MIME-Version: 1.0 Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org When the implementation for unflatten_dt_node() changed from being recursive to being non-recursive, it had a side effect of increasing the depth passed to fdt_next_node() by 1. This is fine most of the time, but it seems that when the end of the dtb is being parsed, it will cause the FDT_END condition in fdt_next_node() to return a different value (returning nextoffset instead of -FDT_ERR_NOTFOUND). This ends up passing an FDT_ERR_TRUNCATED error back to the unflatten_dt_node() which then sees that and complains "Error -8 processing FDT" causing boot to fail. This patch simply avoids incrementing depth and uses modified accesses for local array indices so that the depth is the same as it was before the change as far as fdt_next_node() is concerned. This problem was discovered trying to boot Tegra210-Smaug platforms. Cc: stable@vger.kernel.org Fixes: 9ffa9eb41763 ("drivers/of: Avoid recursively calling unflatten_dt_node()") Signed-off-by: Rhyland Klein --- drivers/of/fdt.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index df9f4e8dfa00..becb025702d7 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -407,24 +407,24 @@ static int unflatten_dt_nodes(const void *blob, root = dad; fpsizes[depth] = dad ? strlen(of_node_full_name(dad)) : 0; - nps[depth++] = dad; + nps[depth+1] = dad; for (offset = 0; offset >= 0; offset = fdt_next_node(blob, offset, &depth)) { if (WARN_ON_ONCE(depth >= FDT_MAX_DEPTH)) continue; - fpsizes[depth] = populate_node(blob, offset, &mem, - nps[depth - 1], - fpsizes[depth - 1], - &nps[depth], dryrun); - if (!fpsizes[depth]) + fpsizes[depth+1] = populate_node(blob, offset, &mem, + nps[depth], + fpsizes[depth], + &nps[depth+1], dryrun); + if (!fpsizes[depth+1]) return mem - base; if (!dryrun && nodepp && !*nodepp) - *nodepp = nps[depth]; + *nodepp = nps[depth+1]; if (!dryrun && !root) - root = nps[depth]; + root = nps[depth+1]; } if (offset < 0 && offset != -FDT_ERR_NOTFOUND) {