From patchwork Tue Jul 25 21:44:27 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Herring X-Patchwork-Id: 108715 Delivered-To: patch@linaro.org Received: by 10.182.45.195 with SMTP id p3csp91689obm; Tue, 25 Jul 2017 14:45:17 -0700 (PDT) X-Received: by 10.99.111.131 with SMTP id k125mr3008786pgc.8.1501019116899; Tue, 25 Jul 2017 14:45:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1501019116; cv=none; d=google.com; s=arc-20160816; b=ZBKQy4UTVzaCPQHgHYACss+PrxgzzLbiskLwDMr9M2I79EPb4djhm1BkKKWaj5F3zN uYtsGu/GQwcGF42dOgwpIX9lcTj5ZvO/gJMOmUkqSDjVbyf0lgWwA7Xrut1WaJk6oQGJ UC1pcCWgpz1nn3DAp8zoAks0etyfDRLQ9GhflGUQRx8ITptlqXMMX+eTxA51t0wLSIxU 1H41IIOgJLtvGymVSqPY4KwOv5xSvY4CI3y5HeK+Ou9bzXa0glX2DTBV4ZNJBhLRD88O N5PxJFHCxtEqE5XFJwpAsFHfd0jqee0U4ozVqz7OTiqy0+NgULmdSBJ70VKUpTQouNPu ynVw== 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=Y+KNQmzd4TESkuDDD54Qn98tMFXL87R0JaO/X1yWMb8=; b=u4wffMQvLVtDtAAev0zJjytIODSoD2KQuJUbR1IMKzTCw+Fr4ELbE1TdKh/rudI04e l97p2rzDjApn0Htgglka/PmxtYjHveb+AMLmrML9lCQRumo7cljz7CTlpS2OOlVR5a0N 9dB+3jsV/3bVDc2+j2ZyRYowaIbgBi+QZ8yUfv/VLWv14Dcg8IegFx5S83FArYdz687N dckjclRE0KjCVOPEnZZ//AS5OJjMQQUkQ0hqNz0relkDlPm1FXA8O/6PvSHosPwsw/29 STeMBuTH2+Oj7I8NVIqnLwBnUFU9uvKjjD/L4f6HzrTDjPRZeYQpC9T9r9L91eGlsHr5 FWVg== 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 i78si8573658pfk.198.2017.07.25.14.45.16; Tue, 25 Jul 2017 14:45: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 S1751726AbdGYVpO (ORCPT + 26 others); Tue, 25 Jul 2017 17:45:14 -0400 Received: from mail-yw0-f195.google.com ([209.85.161.195]:34434 "EHLO mail-yw0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751595AbdGYVom (ORCPT ); Tue, 25 Jul 2017 17:44:42 -0400 Received: by mail-yw0-f195.google.com with SMTP id t139so1398269ywg.1; Tue, 25 Jul 2017 14:44:41 -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=Y+KNQmzd4TESkuDDD54Qn98tMFXL87R0JaO/X1yWMb8=; b=EWzHo2OBzRAtMly6OyDOShChfmhylt0nOQZKI4GAETbUpriPTmuMae80jau4a2sCEe MmqOReKrh4DQsKG41jJX8PdPrKOSbQOCRe4yyA1dgyD4kcNQr3dLWIjX5Nh191KKH/Zy cDxlXgTm0XkY//4+qm4EHxP1KQUI/3p4HQ01peYwd3s9MLZKWwMW7AfqbqzUAY3Nrrwu pP5KKNfQOJGLwnXUsF7Dj+6qR0DMETKp0ROqlbbXF0uc39rQYQr8H1+nqMllu8fgQDyC 7RfzyHLdduE6jff1yqlBSBepS59ThpeXRx9zulN4YiAyGVnAr1MRYbgvRstZGyWqtl+A 04Lg== X-Gm-Message-State: AIVw113oyUNuRmgJlEwRzpzPkmkUDZ0gFT/RgZY0kq88eiHCL/GKbC+v LBAJL8XOPRYQysMGbTs= X-Received: by 10.13.246.65 with SMTP id g62mr18611556ywf.205.1501019081425; Tue, 25 Jul 2017 14:44:41 -0700 (PDT) Received: from localhost.localdomain (24-223-123-72.static.usa-companies.net. [24.223.123.72]) by smtp.googlemail.com with ESMTPSA id 204sm2386383ywx.35.2017.07.25.14.44.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 25 Jul 2017 14:44:40 -0700 (PDT) From: Rob Herring To: devicetree@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Cc: linux-kernel@vger.kernel.org, Frank Rowand , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman Subject: [PATCH 4/4] of/fdt: only store the device node basename in full_name Date: Tue, 25 Jul 2017 16:44:27 -0500 Message-Id: <20170725214427.25768-5-robh@kernel.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170725214427.25768-1-robh@kernel.org> References: <20170725214427.25768-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 --- 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)