From patchwork Mon Aug 21 15:16:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 110554 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp1429444qge; Mon, 21 Aug 2017 08:17:17 -0700 (PDT) X-Received: by 10.98.201.145 with SMTP id l17mr17249208pfk.145.1503328637008; Mon, 21 Aug 2017 08:17:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1503328637; cv=none; d=google.com; s=arc-20160816; b=IDTmx6k7GWnkBO3DDOPJyzptIswCufu4oCFxeXdsP0O8osiVcdzze9ymBa1PsF2PC8 ghAnR7cD96od4rDlre/tyYb68tOZbn+xdCluP8o5pwBsq7mo/LdeIFlqm53Iy1nPRbkQ tWTBjEuzcbbenoaeXZXvXBdMmURAKIwTqULigSzLp9Cj4rR7Q1aM6j0lNBxdhHBWj38Z vyEr+g3o9RoF1qN8C5OChMQzQGX0PBm0MxrUpgC30A49M957nDeLw7Kg6W5FDnKw6c45 xHtTtMPXdftNMsBIabdvifJKlpoBbj5qYv3nlXEFD78+xdWpE/x7R7T1c9pgAbQr3CLy 1mJQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=LqWbf4Zw3UfGEWWPjjp4XqNHB2vMwziobnBRjChc59A=; b=xjrQJzuv5emu2CwKfUj08CkFZtL2sqz4eA+AiWfsxiji2FUcCwazZ/xZU9YwANHdWw 0WS1b4jLcZQa2kHya7Mzrn8DVA7m+9Av2W9WqZ4QsuHvrbwYKef1/0JQW92kMsdHmY5h rnuh0dL5uIG0WTQbKrZ7tgpzc4Ua3y8PEVMawxd3VlfmUugWIFN6Asrv1EXXkdUs01hV qlqZL6Gnx33rPTEdtr1hTK7qJWTvZXH2RWpkeGpA1XMBeleNaLzakdIR6bxklyW1cXUx qpkEtHJWCPEocaUhUxb2r/KvGi6/Vy9EADBo2qzAgvxCCgmRDzHATDMPB7Oor+oaPGsH AhGg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 31si8210822pli.109.2017.08.21.08.17.16; Mon, 21 Aug 2017 08:17:16 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753988AbdHUPRJ (ORCPT + 26 others); Mon, 21 Aug 2017 11:17:09 -0400 Received: from mail-oi0-f65.google.com ([209.85.218.65]:34694 "EHLO mail-oi0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753926AbdHUPRD (ORCPT ); Mon, 21 Aug 2017 11:17:03 -0400 Received: by mail-oi0-f65.google.com with SMTP id v11so16099228oif.1; Mon, 21 Aug 2017 08:17:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=LqWbf4Zw3UfGEWWPjjp4XqNHB2vMwziobnBRjChc59A=; b=IH/CG4e8wJcPtUhaBWOSdLYxZoxDXbHhLaFwK2im3gG8bhloZohDM5k2xNv8Dst5iH bevc+t8nj8nz3dwM3kZxuZojUPeqsZ1skvlDVWpPmcdy+FWTKE1wVIrzG0jSbJmnWImp ZzWhRE6ZmTQcdFYE9998qKTLVtA2Z39jtpUk4+QzO6OhzdNGAiff4gCN8G1QQVOR5lTN widhaIGetlBsKfIGE6vL249Pw6fRDy44xCQRxY7wyLgT1gejJj+fKcxOqiMv4s+EoK25 88+K36zkgpoJDnX5pq3A3398vuAAu6ZCeT5A50aPZhcuqerBhl83q9a45V/ZNGcsoLlW u5Bg== X-Gm-Message-State: AHYfb5jA+WUaLa6CnCnASwqPALn+xTda7T0w6/rKBtpzO8GEWbGLE6Mo FVAGMNpctKWxcmE7duU= X-Received: by 10.202.166.72 with SMTP id p69mr19904639oie.258.1503328621941; Mon, 21 Aug 2017 08:17:01 -0700 (PDT) Received: from localhost.localdomain (216-188-254-6.dyn.grandenetworks.net. [216.188.254.6]) by smtp.googlemail.com with ESMTPSA id q134sm4505638oic.51.2017.08.21.08.17.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 21 Aug 2017 08:17:01 -0700 (PDT) From: Rob Herring To: devicetree@vger.kernel.org, Michael Ellerman , linuxppc-dev@lists.ozlabs.org Cc: linux-kernel@vger.kernel.org, Frank Rowand , Benjamin Herrenschmidt , Paul Mackerras , David Laight Subject: [PATCH v2 5/5] of/fdt: only store the device node basename in full_name Date: Mon, 21 Aug 2017 10:16:51 -0500 Message-Id: <20170821151651.25096-6-robh@kernel.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170821151651.25096-1-robh@kernel.org> References: <20170821151651.25096-1-robh@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org With dependencies on a statically allocated full path name converted to use %pOF format specifier, we can store just the basename of node, and the unflattening of the FDT can be simplified. This commit will affect the remaining users of full_name. After analyzing these users, the remaining cases should only change some print messages. The main users of full_name are providing a name for struct resource. The resource names shouldn't be important other than providing /proc/iomem names. We no longer distinguish between pre and post 0x10 dtb formats as either a full path or basename will work. However, less than 0x10 formats have been broken since the conversion to use libfdt (and no one has cared). The conversion of the unflattening code to be non-recursive also broke pre 0x10 formats as the populate_node function would return 0 in that case. Signed-off-by: Rob Herring --- v2: - rebase to linux-next drivers/of/fdt.c | 69 +++++++++----------------------------------------------- 1 file changed, 11 insertions(+), 58 deletions(-) -- 2.11.0 diff --git a/drivers/of/fdt.c b/drivers/of/fdt.c index ce30c9a588a4..27c535af0be8 100644 --- a/drivers/of/fdt.c +++ b/drivers/of/fdt.c @@ -266,74 +266,32 @@ static void populate_properties(const void *blob, *pprev = NULL; } -static unsigned int populate_node(const void *blob, - int offset, - void **mem, - struct device_node *dad, - unsigned int fpsize, - struct device_node **pnp, - bool dryrun) +static bool populate_node(const void *blob, + int offset, + void **mem, + struct device_node *dad, + struct device_node **pnp, + bool dryrun) { struct device_node *np; const char *pathp; unsigned int l, allocl; - int new_format = 0; pathp = fdt_get_name(blob, offset, &l); if (!pathp) { *pnp = NULL; - return 0; + return false; } allocl = ++l; - /* version 0x10 has a more compact unit name here instead of the full - * path. we accumulate the full path size using "fpsize", we'll rebuild - * it later. We detect this because the first character of the name is - * not '/'. - */ - if ((*pathp) != '/') { - new_format = 1; - if (fpsize == 0) { - /* root node: special case. fpsize accounts for path - * plus terminating zero. root node only has '/', so - * fpsize should be 2, but we want to avoid the first - * level nodes to have two '/' so we use fpsize 1 here - */ - fpsize = 1; - allocl = 2; - l = 1; - pathp = ""; - } else { - /* account for '/' and path size minus terminal 0 - * already in 'l' - */ - fpsize += l; - allocl = fpsize; - } - } - np = unflatten_dt_alloc(mem, sizeof(struct device_node) + allocl, __alignof__(struct device_node)); if (!dryrun) { char *fn; of_node_init(np); np->full_name = fn = ((char *)np) + sizeof(*np); - if (new_format) { - /* rebuild full path for new format */ - if (dad && dad->parent) { - strcpy(fn, dad->full_name); -#ifdef DEBUG - if ((strlen(fn) + l + 1) != allocl) { - pr_debug("%s: p: %d, l: %d, a: %d\n", - pathp, (int)strlen(fn), - l, allocl); - } -#endif - fn += strlen(fn); - } - *(fn++) = '/'; - } + memcpy(fn, pathp, l); if (dad != NULL) { @@ -355,7 +313,7 @@ static unsigned int populate_node(const void *blob, } *pnp = np; - return fpsize; + return true; } static void reverse_nodes(struct device_node *parent) @@ -399,7 +357,6 @@ static int unflatten_dt_nodes(const void *blob, struct device_node *root; int offset = 0, depth = 0, initial_depth = 0; #define FDT_MAX_DEPTH 64 - unsigned int fpsizes[FDT_MAX_DEPTH]; struct device_node *nps[FDT_MAX_DEPTH]; void *base = mem; bool dryrun = !base; @@ -418,7 +375,6 @@ static int unflatten_dt_nodes(const void *blob, depth = initial_depth = 1; root = dad; - fpsizes[depth] = dad ? strlen(of_node_full_name(dad)) : 0; nps[depth] = dad; for (offset = 0; @@ -427,11 +383,8 @@ static int unflatten_dt_nodes(const void *blob, if (WARN_ON_ONCE(depth >= FDT_MAX_DEPTH)) continue; - fpsizes[depth+1] = populate_node(blob, offset, &mem, - nps[depth], - fpsizes[depth], - &nps[depth+1], dryrun); - if (!fpsizes[depth+1]) + if (!populate_node(blob, offset, &mem, nps[depth], + &nps[depth+1], dryrun)) return mem - base; if (!dryrun && nodepp && !*nodepp)