From patchwork Sat Oct 13 04:53:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Rowand X-Patchwork-Id: 983422 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="lh5oQUyJ"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42XC7M2hJTz9sCs for ; Sat, 13 Oct 2018 15:55:11 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726273AbeJMMar (ORCPT ); Sat, 13 Oct 2018 08:30:47 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:44971 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726031AbeJMMar (ORCPT ); Sat, 13 Oct 2018 08:30:47 -0400 Received: by mail-pf1-f193.google.com with SMTP id r9-v6so7148392pff.11; Fri, 12 Oct 2018 21:55:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=lPoDioj489a2/oR5DkZXnv7vgj2sX9AQIbb7kmBjERc=; b=lh5oQUyJnhXfsWUjCV150ZQZLfszGKvr9dQ2KOaEL0JF5Ok/yPR84a20Lpw4nKVWnq 6Eud/ck3dVEunIBkPl32CwmF5A6YwNqPef0VT61SdtByymFuAxiAF7G5Zm3GvjRF2A2k E6vWAO/aP1Ht2dsggvK4yeRUZ4JAQ+x6WMaMg+vnZYEUfChG7VhjgsnGi9Yt2x4qurbk 7U67zsBe4+ZPiheSXpkgYeDeWJda6BWGzAc1Lz+8ATg+HyT3NLwnl6n35n0NfSQ3kTjB 9rJZf1FzASTWzLPAWI0QWplAZX/3/HwggERoRJ+dJIx/x2c6v8sSuM8Ns7nZq+5zN/GJ JhDA== 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=lPoDioj489a2/oR5DkZXnv7vgj2sX9AQIbb7kmBjERc=; b=hA8KWgdEE7zncvpVgER1bqnlUKT4xFOtgAKjhlV+nYI0CGFrVLe9E5of108uFw3os6 oQZTILmG9Svqdjn+Ytrp8UNSyRfqmDKlWy6oLUofkJDFCWWKklv5WT6VSI6lG7sWMqHb GIoqlO/v/MHviyqBE0T2okkY3tAhv8Q1rFslynhOQ9qYtahTR7mGaD/M7pVyM9hNrukA 9DO2yRDrVHsfBBDbLYXaj5TBsRS0ZZLaFtLjmQTSuc1fPV3C9+A3VMkjKoOwQwJcYx4P vvI6rzGIR4pZUYnDipMfixu7f9yBLnJHNpIpIf1C+jPD/Quw+UAIfU3gVPotsSK2Z4NL xCQg== X-Gm-Message-State: ABuFfog6Sx7gF0IHPNb3TUtyBJJmVKmUddtjs1amViq264jlJCmD/4X7 erXwJez8mk4JHYluTdxeWhI= X-Google-Smtp-Source: ACcGV60LxgKR3YKKUmt9YIFZo1BNO2d0ZgSYfQh5taAJl+ZcvxxzfD9BkNGicvF6Itm5OiVueGWLUQ== X-Received: by 2002:a62:2982:: with SMTP id p124-v6mr8799687pfp.128.1539406505782; Fri, 12 Oct 2018 21:55:05 -0700 (PDT) Received: from localhost.localdomain (c-24-6-192-50.hsd1.ca.comcast.net. [24.6.192.50]) by smtp.gmail.com with ESMTPSA id h87-v6sm6959462pfj.78.2018.10.12.21.55.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Oct 2018 21:55:05 -0700 (PDT) From: frowand.list@gmail.com To: Rob Herring , Pantelis Antoniou , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Alan Tull , Moritz Fischer Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, devicetree@vger.kernel.org, linux-fpga@vger.kernel.org Subject: [PATCH v2 01/18] of: overlay: add tests to validate kfrees from overlay removal Date: Fri, 12 Oct 2018 21:53:21 -0700 Message-Id: <1539406418-18162-2-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1539406418-18162-1-git-send-email-frowand.list@gmail.com> References: <1539406418-18162-1-git-send-email-frowand.list@gmail.com> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Frank Rowand Add checks: - attempted kfree due to refcount reaching zero before overlay is removed - properties linked to an overlay node when the node is removed - node refcount > one during node removal in a changeset destroy, if the node was created by the changeset After applying this patch, several validation warnings will be reported from the devicetree unittest during boot due to pre-existing devicetree bugs. The warnings will be similar to: OF: ERROR: of_node_release() overlay node /testcase-data/overlay-node/test-bus/test-unittest11/test-unittest111 contains unexpected properties OF: ERROR: memory leak - destroy cset entry: attach overlay node /testcase-data-2/substation@100/hvac-medium-2 with refcount 2 Signed-off-by: Frank Rowand --- drivers/of/dynamic.c | 29 +++++++++++++++++++++++++++++ drivers/of/overlay.c | 1 + include/linux/of.h | 15 ++++++++++----- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c index f4f8ed9b5454..b04ee021a891 100644 --- a/drivers/of/dynamic.c +++ b/drivers/of/dynamic.c @@ -330,6 +330,25 @@ void of_node_release(struct kobject *kobj) if (!of_node_check_flag(node, OF_DYNAMIC)) return; + if (of_node_check_flag(node, OF_OVERLAY)) { + + if (!of_node_check_flag(node, OF_OVERLAY_FREE_CSET)) { + /* premature refcount of zero, do not free memory */ + pr_err("ERROR: memory leak %s() overlay node %pOF before free overlay changeset\n", + __func__, node); + return; + } + + /* + * If node->properties non-empty then properties were added + * to this node either by different overlay that has not + * yet been removed, or by a non-overlay mechanism. + */ + if (node->properties) + pr_err("ERROR: %s() overlay node %pOF contains unexpected properties\n", + __func__, node); + } + property_list_free(node->properties); property_list_free(node->deadprops); @@ -434,6 +453,16 @@ struct device_node *__of_node_dup(const struct device_node *np, static void __of_changeset_entry_destroy(struct of_changeset_entry *ce) { + if (ce->action == OF_RECONFIG_ATTACH_NODE && + of_node_check_flag(ce->np, OF_OVERLAY)) { + if (kref_read(&ce->np->kobj.kref) > 1) { + pr_err("ERROR: memory leak - destroy cset entry: attach overlay node %pOF with refcount %d\n", + ce->np, kref_read(&ce->np->kobj.kref)); + } else { + of_node_set_flag(ce->np, OF_OVERLAY_FREE_CSET); + } + } + of_node_put(ce->np); list_del(&ce->node); kfree(ce); diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c index eda57ef12fd0..1176cb4b6e4e 100644 --- a/drivers/of/overlay.c +++ b/drivers/of/overlay.c @@ -373,6 +373,7 @@ static int add_changeset_node(struct overlay_changeset *ovcs, return -ENOMEM; tchild->parent = target_node; + of_node_set_flag(tchild, OF_OVERLAY); ret = of_changeset_attach_node(&ovcs->cset, tchild); if (ret) diff --git a/include/linux/of.h b/include/linux/of.h index 4d25e4f952d9..aa1dafaec6ae 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -138,11 +138,16 @@ static inline void of_node_put(struct device_node *node) { } extern struct device_node *of_stdout; extern raw_spinlock_t devtree_lock; -/* flag descriptions (need to be visible even when !CONFIG_OF) */ -#define OF_DYNAMIC 1 /* node and properties were allocated via kmalloc */ -#define OF_DETACHED 2 /* node has been detached from the device tree */ -#define OF_POPULATED 3 /* device already created for the node */ -#define OF_POPULATED_BUS 4 /* of_platform_populate recursed to children of this node */ +/* + * struct device_node flag descriptions + * (need to be visible even when !CONFIG_OF) + */ +#define OF_DYNAMIC 1 /* (and properties) allocated via kmalloc */ +#define OF_DETACHED 2 /* detached from the device tree */ +#define OF_POPULATED 3 /* device already created */ +#define OF_POPULATED_BUS 4 /* platform bus created for children */ +#define OF_OVERLAY 5 /* allocated for an overlay */ +#define OF_OVERLAY_FREE_CSET 6 /* in overlay cset being freed */ #define OF_BAD_ADDR ((u64)-1) From patchwork Sat Oct 13 04:53:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Rowand X-Patchwork-Id: 983423 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="MydkuL+k"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42XC7N3Fw3z9sBh for ; Sat, 13 Oct 2018 15:55:12 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726388AbeJMMas (ORCPT ); Sat, 13 Oct 2018 08:30:48 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:45151 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726031AbeJMMar (ORCPT ); Sat, 13 Oct 2018 08:30:47 -0400 Received: by mail-pl1-f193.google.com with SMTP id y15-v6so6816481plr.12; Fri, 12 Oct 2018 21:55:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6jwtNAKUA0bImQ+OzjBieSYaakSLUGtiTllRPSG9WlA=; b=MydkuL+kvbcHS1s2I/c5iiBymR1vJcXEfrx9eRB6MsqaqBlxpv77t1V31NVXbg1+Q2 cBsw95pb83+KDWFQ/sVdbH9dNaBhnQEZJoeKR8j5RJ6CGXLyAkfPAoLfwtH6cv7F4mbV AkV/BMca5jxzMvSUe5pSB9p866bzhxxnstDmizSIB8CFotOaj5uggnURBA1UCzmq2DQM mBTzHABgnBLG/r78RD3iKc3483a1p1kCFRE5Nqtoy+7wPBKukYzwNpJAKvcf7hUQ/ejH eDBCNik1FszHiK7qaqH1V/SHTRmGUqC4N0wO7w6P7l8aWLrc03JqrAFD/Btu3FX540Kr fBkg== 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=6jwtNAKUA0bImQ+OzjBieSYaakSLUGtiTllRPSG9WlA=; b=XbVLNiMqbVLGirXgTBOmxJxfJUo87OC9Bkaucgc/2PkJrLuF5ustmlLGTdDtcMcWLM qlAFsTq730shvWjcha2BTPj6Uv5mWB5MiHxFIjj2MZlY5IrVXWgd6UwEFtHOE79bDm+Z JLfkZYOkr32k4UK3UQJL+uujl53Yko/lKMKTMAYWVrwE1cozA9A1lI29+FaG8+hzfbf7 2ddD0QNrZUrG9reZeLUorIpL80A0LZBaWePEfYkTiD+nXWWVkkVlYUbR8NQ7mIKy5mPQ ARoobj6iznTWE017Jf4p3cUgFw+aVxyXYwuE2RinLWUic/nLFk/nW5Gs6siwdiPTKsyy YVIA== X-Gm-Message-State: ABuFfogpAlnF1Kx9hm0alZ/39DrT6ThZyKpB5bcRaadQJRyC21tdutEL P+Iy1pyqWngr+0BU7S90jYU= X-Google-Smtp-Source: ACcGV60ogMqaNuCx7/IRfcjG5cSWNSMtzhQHNelsFGhuzfo5VZv6KdpnFX7NYhjQJVM4Y9Le8Obo+Q== X-Received: by 2002:a17:902:5a4d:: with SMTP id f13-v6mr2083052plm.114.1539406507004; Fri, 12 Oct 2018 21:55:07 -0700 (PDT) Received: from localhost.localdomain (c-24-6-192-50.hsd1.ca.comcast.net. [24.6.192.50]) by smtp.gmail.com with ESMTPSA id h87-v6sm6959462pfj.78.2018.10.12.21.55.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Oct 2018 21:55:06 -0700 (PDT) From: frowand.list@gmail.com To: Rob Herring , Pantelis Antoniou , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Alan Tull , Moritz Fischer Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, devicetree@vger.kernel.org, linux-fpga@vger.kernel.org Subject: [PATCH v2 02/18] of: overlay: add missing of_node_put() after add new node to changeset Date: Fri, 12 Oct 2018 21:53:22 -0700 Message-Id: <1539406418-18162-3-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1539406418-18162-1-git-send-email-frowand.list@gmail.com> References: <1539406418-18162-1-git-send-email-frowand.list@gmail.com> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Frank Rowand The refcount of a newly added overlay node decrements to one (instead of zero) when the overlay changeset is destroyed. This change will cause the final decrement be to zero. After applying this patch, new validation warnings will be reported from the devicetree unittest during boot due to a pre-existing devicetree bug. The warnings will be similar to: OF: ERROR: memory leak of_node_release() overlay node /testcase-data/overlay-node/test-bus/test-unittest4 before free overlay changeset This pre-existing devicetree bug will also trigger a WARN_ONCE() from refcount_sub_and_test_checked() when an overlay changeset is destroyed without having first been applied. This scenario occurs when an error in the overlay is detected during the overlay changeset creation: WARNING: CPU: 0 PID: 1 at lib/refcount.c:187 refcount_sub_and_test_checked+0xa8/0xbc refcount_t: underflow; use-after-free. (unwind_backtrace) from (show_stack+0x10/0x14) (show_stack) from (dump_stack+0x6c/0x8c) (dump_stack) from (__warn+0xdc/0x104) (__warn) from (warn_slowpath_fmt+0x44/0x6c) (warn_slowpath_fmt) from (refcount_sub_and_test_checked+0xa8/0xbc) (refcount_sub_and_test_checked) from (kobject_put+0x24/0x208) (kobject_put) from (of_changeset_destroy+0x2c/0xb4) (of_changeset_destroy) from (free_overlay_changeset+0x1c/0x9c) (free_overlay_changeset) from (of_overlay_remove+0x284/0x2cc) (of_overlay_remove) from (of_unittest_apply_revert_overlay_check.constprop.4+0xf8/0x1e8) (of_unittest_apply_revert_overlay_check.constprop.4) from (of_unittest_overlay+0x960/0xed8) (of_unittest_overlay) from (of_unittest+0x1cc4/0x2138) (of_unittest) from (do_one_initcall+0x4c/0x28c) (do_one_initcall) from (kernel_init_freeable+0x29c/0x378) (kernel_init_freeable) from (kernel_init+0x8/0x110) (kernel_init) from (ret_from_fork+0x14/0x2c) Signed-off-by: Frank Rowand --- drivers/of/overlay.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c index 1176cb4b6e4e..32cfee68f2e3 100644 --- a/drivers/of/overlay.c +++ b/drivers/of/overlay.c @@ -379,7 +379,9 @@ static int add_changeset_node(struct overlay_changeset *ovcs, if (ret) return ret; - return build_changeset_next_level(ovcs, tchild, node); + ret = build_changeset_next_level(ovcs, tchild, node); + of_node_put(tchild); + return ret; } if (node->phandle && tchild->phandle) From patchwork Sat Oct 13 04:53:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Rowand X-Patchwork-Id: 983438 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="DkE69wQR"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42XC940ff4z9sBq for ; Sat, 13 Oct 2018 15:56:39 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726707AbeJMMaw (ORCPT ); Sat, 13 Oct 2018 08:30:52 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:42794 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726031AbeJMMat (ORCPT ); Sat, 13 Oct 2018 08:30:49 -0400 Received: by mail-pg1-f195.google.com with SMTP id i4-v6so6736470pgq.9; Fri, 12 Oct 2018 21:55:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=XMDnNdUW/sDd17o9F9TmJbiIxv65t1vRquMBQw128TM=; b=DkE69wQRrK5yz6q10N0/zzSN4tjKocDLbD5B/P1nMv+DQSSvO/PKPv4D4ZCzfXYeo1 bfYK3FzpeulvPJguvMj28f8znYmQCUW6k6gg6CquRQ8CuPsaay/Ce5FLCP7o4Z783IX3 6LrKeUbowH7A/sQ/xaQMVzi9X5v+SYYZWBZIJk3JI6eskCfxyKuwDP+8cfv0C5lXhn8q Mxpa+SD+ZewIgd3wO6wT7NUkJLNUuz8U+3XIF+TLm4smM9mfgAExDgNK3lyyex8k8OFF /RW3UUG1ZlLTKKRhqyQ5Exhwuo9cyiCFWfjAMNBQbJBrvEun3jDZmmu7/EPhme6mLJI7 xE2g== 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=XMDnNdUW/sDd17o9F9TmJbiIxv65t1vRquMBQw128TM=; b=og31tXh7XoIn8QZwP5stDW5a+0bAT7MKCyb86JYbzpOHWEnbyIqakt3DXR8dLZTl3Z K+J+1mmQPtNEV/G896hQe/7x+SrPOeVjA5s5WDsyoy0UEO34eEG9uMg6lXjZ0yBKbtvv DbCQzNi92Mv1QvbvXUif4dR+3WC1NSIdttjY3T64cNLMjBhKkX/o8JDU/vRIqtowS0lr +xD5+efdHLnzlVgjxq4HLFdmVQRiTFbIa/ZfVSUp0MNipC/+BG2jHn3XncaG2rVRrqrM +1Sj2OgpadI0RuwCAVxtI12GB3ujVlwQ9ogegEqBeNvAwZLSbZD0GLUiZ8VwBbeJvfPj 0YXw== X-Gm-Message-State: ABuFfoiNom/sWhTSlG8jkTSrDrifK9YZOYjSYRyPY0iGpQrt8oMTRXEB QXDsnhakpv3nvgkKhliFzoo= X-Google-Smtp-Source: ACcGV63O/Z7W+La/xikCOyTH2Em6nqwV6pogOiouMWZHCDyZ2FkSu3kUqaV7Qveg8yjYowc513kDsA== X-Received: by 2002:a62:7a81:: with SMTP id v123-v6mr9097572pfc.240.1539406508248; Fri, 12 Oct 2018 21:55:08 -0700 (PDT) Received: from localhost.localdomain (c-24-6-192-50.hsd1.ca.comcast.net. [24.6.192.50]) by smtp.gmail.com with ESMTPSA id h87-v6sm6959462pfj.78.2018.10.12.21.55.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Oct 2018 21:55:07 -0700 (PDT) From: frowand.list@gmail.com To: Rob Herring , Pantelis Antoniou , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Alan Tull , Moritz Fischer Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, devicetree@vger.kernel.org, linux-fpga@vger.kernel.org Subject: [PATCH v2 03/18] of: overlay: add missing of_node_get() in __of_attach_node_sysfs Date: Fri, 12 Oct 2018 21:53:23 -0700 Message-Id: <1539406418-18162-4-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1539406418-18162-1-git-send-email-frowand.list@gmail.com> References: <1539406418-18162-1-git-send-email-frowand.list@gmail.com> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Frank Rowand There is a matching of_node_put() in __of_detach_node_sysfs() Remove misleading comment from function header comment for of_detach_node(). This patch may result in memory leaks from code that directly calls the dynamic node add and delete functions directly instead of using changesets. Signed-off-by: Frank Rowand --- This patch should result in powerpc systems that dynamically allocate a node, then later deallocate the node to have a memory leak when the node is deallocated. The next patch in the series will fix the leak. drivers/of/dynamic.c | 3 --- drivers/of/kobj.c | 4 +++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c index b04ee021a891..275c0d7e2268 100644 --- a/drivers/of/dynamic.c +++ b/drivers/of/dynamic.c @@ -272,9 +272,6 @@ void __of_detach_node(struct device_node *np) /** * of_detach_node() - "Unplug" a node from the device tree. - * - * The caller must hold a reference to the node. The memory associated with - * the node is not freed until its refcount goes to zero. */ int of_detach_node(struct device_node *np) { diff --git a/drivers/of/kobj.c b/drivers/of/kobj.c index 7a0a18980b98..c72eef988041 100644 --- a/drivers/of/kobj.c +++ b/drivers/of/kobj.c @@ -133,6 +133,9 @@ int __of_attach_node_sysfs(struct device_node *np) } if (!name) return -ENOMEM; + + of_node_get(np); + rc = kobject_add(&np->kobj, parent, "%s", name); kfree(name); if (rc) @@ -159,6 +162,5 @@ void __of_detach_node_sysfs(struct device_node *np) kobject_del(&np->kobj); } - /* finally remove the kobj_init ref */ of_node_put(np); } From patchwork Sat Oct 13 04:53:25 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Rowand X-Patchwork-Id: 983436 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="GZwq3bMa"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42XC8w2147z9sBh for ; Sat, 13 Oct 2018 15:56:32 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726798AbeJMMay (ORCPT ); Sat, 13 Oct 2018 08:30:54 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:37767 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726567AbeJMMaw (ORCPT ); Sat, 13 Oct 2018 08:30:52 -0400 Received: by mail-pg1-f195.google.com with SMTP id c10-v6so6751649pgq.4; Fri, 12 Oct 2018 21:55:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=X9whLFxCvCOQHnac7vrrqYFzn2VcjvgM2D68co/cxdk=; b=GZwq3bMaqn4FgxNA3WNkkP9g+7FZLEPKFDCk6J917OAtoaDx8S8OxfTzHBifI1JkAD uGilOJc9lAVPZvt3+rO6Xb2XDXcq2E4XrIn7DHPVGK+KXwoV7NW3hNNlFIu9WhHh58ET KqL59Hac3qGh0NXOsU1JPHyMIzsmNpexIH7KLDMleaOkIlcQ3FCKLY8M9c4ycKwFyLnq nIGBk0IGCJZaLZ9CO3yCPLZyebYBqTKGFIR5C0eRq+DYCXYjvjXv7OC3EY4I3kJMO0m2 BLt+HhLrfYpH199giiF1tydJJHESbTcdKo1TSCoEhcHX2FquWg3y3RWJohZ0CTULhtHQ xZ7A== 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=X9whLFxCvCOQHnac7vrrqYFzn2VcjvgM2D68co/cxdk=; b=Mg87Bg1ijoK/kO9mHYV2SmFrBZaVEeXwzYKjY30bSMncY9x3xqn5Ct9y0KrnvpmrPG av0PpfrTH4C/QeYsuzo/wLheMTyL7PQCu2DMWYDefBLrJErsR35s5XjGvgCOwBjNvQta o/ZiCPuQXmJAb023md4KhXrzbXodS9OPeZyzcvpRoO1QBBZBIXgEFizozMB56yvp5iyB N93r60XzBFpFkjVs+R5ppuTN1G2EKblWEX7BnVeeaXuYZD4BBRxZzrWBy+NCEFF2AA5N GvxMqhMCNdFUZ47MALJi+X+VgCruF+7ueY/HtTnyLYzQUgrTWHZORtUv25bOcIxZuvHW Fc9g== X-Gm-Message-State: ABuFfoiNLxf9fvbDKAjKiPudlG1k7yMsrlR1bUXmwuf9RuwCjfk4z8zt i0GSKvJ5KTH3iJBneKEs5hk= X-Google-Smtp-Source: ACcGV636rbEso9+0j/P9ne+5ohvngVvVbv++uoG2KimFoSeZuDGiM+CjCcVR2A2tTnTyUv5fJJMEHQ== X-Received: by 2002:a63:fa09:: with SMTP id y9-v6mr8101564pgh.177.1539406510814; Fri, 12 Oct 2018 21:55:10 -0700 (PDT) Received: from localhost.localdomain (c-24-6-192-50.hsd1.ca.comcast.net. [24.6.192.50]) by smtp.gmail.com with ESMTPSA id h87-v6sm6959462pfj.78.2018.10.12.21.55.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Oct 2018 21:55:10 -0700 (PDT) From: frowand.list@gmail.com To: Rob Herring , Pantelis Antoniou , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Alan Tull , Moritz Fischer Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, devicetree@vger.kernel.org, linux-fpga@vger.kernel.org Subject: [PATCH v2 05/18] of: overlay: use prop add changeset entry for property in new nodes Date: Fri, 12 Oct 2018 21:53:25 -0700 Message-Id: <1539406418-18162-6-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1539406418-18162-1-git-send-email-frowand.list@gmail.com> References: <1539406418-18162-1-git-send-email-frowand.list@gmail.com> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Frank Rowand The changeset entry 'update property' was used for new properties in an overlay instead of 'add property'. The decision of whether to use 'update property' was based on whether the property already exists in the subtree where the node is being spliced into. At the top level of creating a changeset describing the overlay, the target node is in the live devicetree, so checking whether the property exists in the target node returns the correct result. As soon as the changeset creation algorithm recurses into a new node, the target is no longer in the live devicetree, but is instead in the detached overlay tree, thus all properties are incorrectly found to already exist in the target. This fix will expose another devicetree bug that will be fixed in the following patch in the series. When this patch is applied the errors reported by the devictree unittest will change, and the unittest results will change from: ### dt-test ### end of unittest - 210 passed, 0 failed to ### dt-test ### end of unittest - 203 passed, 7 failed Signed-off-by: Frank Rowand --- changes since v1: - add_changeset_node() header comment: incorrect comment for @target drivers/of/overlay.c | 112 ++++++++++++++++++++++++++++++++++----------------- 1 file changed, 74 insertions(+), 38 deletions(-) diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c index 32cfee68f2e3..94740f4ee34c 100644 --- a/drivers/of/overlay.c +++ b/drivers/of/overlay.c @@ -24,6 +24,26 @@ #include "of_private.h" /** + * struct target - info about current target node as recursing through overlay + * @np: node where current level of overlay will be applied + * @in_livetree: @np is a node in the live devicetree + * + * Used in the algorithm to create the portion of a changeset that describes + * an overlay fragment, which is a devicetree subtree. Initially @np is a node + * in the live devicetree where the overlay subtree is targeted to be grafted + * into. When recursing to the next level of the overlay subtree, the target + * also recurses to the next level of the live devicetree, as long as overlay + * subtree node also exists in the live devicetree. When a node in the overlay + * subtree does not exist at the same level in the live devicetree, target->np + * points to a newly allocated node, and all subsequent targets in the subtree + * will be newly allocated nodes. + */ +struct target { + struct device_node *np; + bool in_livetree; +}; + +/** * struct fragment - info about fragment nodes in overlay expanded device tree * @target: target of the overlay operation * @overlay: pointer to the __overlay__ node @@ -72,8 +92,7 @@ static int devicetree_corrupt(void) } static int build_changeset_next_level(struct overlay_changeset *ovcs, - struct device_node *target_node, - const struct device_node *overlay_node); + struct target *target, const struct device_node *overlay_node); /* * of_resolve_phandles() finds the largest phandle in the live tree. @@ -257,14 +276,17 @@ static struct property *dup_and_fixup_symbol_prop( /** * add_changeset_property() - add @overlay_prop to overlay changeset * @ovcs: overlay changeset - * @target_node: where to place @overlay_prop in live tree + * @target: where @overlay_prop will be placed * @overlay_prop: property to add or update, from overlay tree * @is_symbols_prop: 1 if @overlay_prop is from node "/__symbols__" * - * If @overlay_prop does not already exist in @target_node, add changeset entry - * to add @overlay_prop in @target_node, else add changeset entry to update + * If @overlay_prop does not already exist in live devicetree, add changeset + * entry to add @overlay_prop in @target, else add changeset entry to update * value of @overlay_prop. * + * @target may be either in the live devicetree or in a new subtree that + * is contained in the changeset. + * * Some special properties are not updated (no error returned). * * Update of property in symbols node is not allowed. @@ -273,20 +295,22 @@ static struct property *dup_and_fixup_symbol_prop( * invalid @overlay. */ static int add_changeset_property(struct overlay_changeset *ovcs, - struct device_node *target_node, - struct property *overlay_prop, + struct target *target, struct property *overlay_prop, bool is_symbols_prop) { struct property *new_prop = NULL, *prop; int ret = 0; - prop = of_find_property(target_node, overlay_prop->name, NULL); - if (!of_prop_cmp(overlay_prop->name, "name") || !of_prop_cmp(overlay_prop->name, "phandle") || !of_prop_cmp(overlay_prop->name, "linux,phandle")) return 0; + if (target->in_livetree) + prop = of_find_property(target->np, overlay_prop->name, NULL); + else + prop = NULL; + if (is_symbols_prop) { if (prop) return -EINVAL; @@ -299,10 +323,10 @@ static int add_changeset_property(struct overlay_changeset *ovcs, return -ENOMEM; if (!prop) - ret = of_changeset_add_property(&ovcs->cset, target_node, + ret = of_changeset_add_property(&ovcs->cset, target->np, new_prop); else - ret = of_changeset_update_property(&ovcs->cset, target_node, + ret = of_changeset_update_property(&ovcs->cset, target->np, new_prop); if (ret) { @@ -315,14 +339,14 @@ static int add_changeset_property(struct overlay_changeset *ovcs, /** * add_changeset_node() - add @node (and children) to overlay changeset - * @ovcs: overlay changeset - * @target_node: where to place @node in live tree - * @node: node from within overlay device tree fragment + * @ovcs: overlay changeset + * @target: where @node will be placed in live tree or changeset + * @node: node from within overlay device tree fragment * - * If @node does not already exist in @target_node, add changeset entry - * to add @node in @target_node. + * If @node does not already exist in @target, add changeset entry + * to add @node in @target. * - * If @node already exists in @target_node, and the existing node has + * If @node already exists in @target, and the existing node has * a phandle, the overlay node is not allowed to have a phandle. * * If @node has child nodes, add the children recursively via @@ -355,15 +379,16 @@ static int add_changeset_property(struct overlay_changeset *ovcs, * invalid @overlay. */ static int add_changeset_node(struct overlay_changeset *ovcs, - struct device_node *target_node, struct device_node *node) + struct target *target, struct device_node *node) { const char *node_kbasename; struct device_node *tchild; + struct target target_child; int ret = 0; node_kbasename = kbasename(node->full_name); - for_each_child_of_node(target_node, tchild) + for_each_child_of_node(target->np, tchild) if (!of_node_cmp(node_kbasename, kbasename(tchild->full_name))) break; @@ -372,22 +397,28 @@ static int add_changeset_node(struct overlay_changeset *ovcs, if (!tchild) return -ENOMEM; - tchild->parent = target_node; + tchild->parent = target->np; of_node_set_flag(tchild, OF_OVERLAY); ret = of_changeset_attach_node(&ovcs->cset, tchild); if (ret) return ret; - ret = build_changeset_next_level(ovcs, tchild, node); + target_child.np = tchild; + target_child.in_livetree = false; + + ret = build_changeset_next_level(ovcs, &target_child, node); of_node_put(tchild); return ret; } - if (node->phandle && tchild->phandle) + if (node->phandle && tchild->phandle) { ret = -EINVAL; - else - ret = build_changeset_next_level(ovcs, tchild, node); + } else { + target_child.np = tchild; + target_child.in_livetree = target->in_livetree; + ret = build_changeset_next_level(ovcs, &target_child, node); + } of_node_put(tchild); return ret; @@ -396,7 +427,7 @@ static int add_changeset_node(struct overlay_changeset *ovcs, /** * build_changeset_next_level() - add level of overlay changeset * @ovcs: overlay changeset - * @target_node: where to place @overlay_node in live tree + * @target: where to place @overlay_node in live tree * @overlay_node: node from within an overlay device tree fragment * * Add the properties (if any) and nodes (if any) from @overlay_node to the @@ -409,27 +440,26 @@ static int add_changeset_node(struct overlay_changeset *ovcs, * invalid @overlay_node. */ static int build_changeset_next_level(struct overlay_changeset *ovcs, - struct device_node *target_node, - const struct device_node *overlay_node) + struct target *target, const struct device_node *overlay_node) { struct device_node *child; struct property *prop; int ret; for_each_property_of_node(overlay_node, prop) { - ret = add_changeset_property(ovcs, target_node, prop, 0); + ret = add_changeset_property(ovcs, target, prop, 0); if (ret) { pr_debug("Failed to apply prop @%pOF/%s, err=%d\n", - target_node, prop->name, ret); + target->np, prop->name, ret); return ret; } } for_each_child_of_node(overlay_node, child) { - ret = add_changeset_node(ovcs, target_node, child); + ret = add_changeset_node(ovcs, target, child); if (ret) { pr_debug("Failed to apply node @%pOF/%s, err=%d\n", - target_node, child->name, ret); + target->np, child->name, ret); of_node_put(child); return ret; } @@ -442,17 +472,17 @@ static int build_changeset_next_level(struct overlay_changeset *ovcs, * Add the properties from __overlay__ node to the @ovcs->cset changeset. */ static int build_changeset_symbols_node(struct overlay_changeset *ovcs, - struct device_node *target_node, + struct target *target, const struct device_node *overlay_symbols_node) { struct property *prop; int ret; for_each_property_of_node(overlay_symbols_node, prop) { - ret = add_changeset_property(ovcs, target_node, prop, 1); + ret = add_changeset_property(ovcs, target, prop, 1); if (ret) { pr_debug("Failed to apply prop @%pOF/%s, err=%d\n", - target_node, prop->name, ret); + target->np, prop->name, ret); return ret; } } @@ -475,6 +505,7 @@ static int build_changeset_symbols_node(struct overlay_changeset *ovcs, static int build_changeset(struct overlay_changeset *ovcs) { struct fragment *fragment; + struct target target; int fragments_count, i, ret; /* @@ -489,7 +520,9 @@ static int build_changeset(struct overlay_changeset *ovcs) for (i = 0; i < fragments_count; i++) { fragment = &ovcs->fragments[i]; - ret = build_changeset_next_level(ovcs, fragment->target, + target.np = fragment->target; + target.in_livetree = true; + ret = build_changeset_next_level(ovcs, &target, fragment->overlay); if (ret) { pr_debug("apply failed '%pOF'\n", fragment->target); @@ -499,7 +532,10 @@ static int build_changeset(struct overlay_changeset *ovcs) if (ovcs->symbols_fragment) { fragment = &ovcs->fragments[ovcs->count - 1]; - ret = build_changeset_symbols_node(ovcs, fragment->target, + + target.np = fragment->target; + target.in_livetree = true; + ret = build_changeset_symbols_node(ovcs, &target, fragment->overlay); if (ret) { pr_debug("apply failed '%pOF'\n", fragment->target); @@ -517,7 +553,7 @@ static int build_changeset(struct overlay_changeset *ovcs) * 1) "target" property containing the phandle of the target * 2) "target-path" property containing the path of the target */ -static struct device_node *find_target_node(struct device_node *info_node) +static struct device_node *find_target(struct device_node *info_node) { struct device_node *node; const char *path; @@ -623,7 +659,7 @@ static int init_overlay_changeset(struct overlay_changeset *ovcs, fragment = &fragments[cnt]; fragment->overlay = overlay_node; - fragment->target = find_target_node(node); + fragment->target = find_target(node); if (!fragment->target) { of_node_put(fragment->overlay); ret = -EINVAL; From patchwork Sat Oct 13 04:53:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Rowand X-Patchwork-Id: 983437 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="TN0C2NGh"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42XC8z370Qz9sBh for ; Sat, 13 Oct 2018 15:56:35 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726762AbeJMMay (ORCPT ); Sat, 13 Oct 2018 08:30:54 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:44980 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726031AbeJMMax (ORCPT ); Sat, 13 Oct 2018 08:30:53 -0400 Received: by mail-pf1-f193.google.com with SMTP id r9-v6so7148478pff.11; Fri, 12 Oct 2018 21:55:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Y8f+zX4OUAoqVg/3NA0TrDwr4Zjok9K4JF3715XNZDg=; b=TN0C2NGhYjK88hDnYMJu04tPsvFFVQF89aayf5OmNyzWECQvEkD9ulD0urAGCZP40I 5fptg6J9R/ZumR/RQz/ABDlVWOXynH/hsJuzy4xE4l4aggHZYuslxbeEzDK7Ncw1bx0o d+6OuWgSdHZYvNw4OAgPK8BbD5AkaRyJvyTcY1H1LToN61kZXEfrnNqpLwq6BXuWUDfh T8mHJ2+ti0xk2gTVmR3tgGIcyOOfivfQae6ymBFUT8aZdJY2ZjDcqwZS085aKyrJVfWk u4Sz3n6iKFyfDqxdzcZQY8hWUN2opLuOSIq4Gr3jHfBQAJeWAObvyUo8ErSXj5eDR41/ 453g== 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=Y8f+zX4OUAoqVg/3NA0TrDwr4Zjok9K4JF3715XNZDg=; b=B0mCuWEazXrSCCk+6ajk/ERnE5L/clVavYn92leDxUgZ6J/QOl7IZCBQvn7hHRmybc iG2pk5h3JYANwMAkZozJV6zlmdEpKdLtVXW4+HEHzVATYeL33YvaqLzmJHwBqtzfS+BD wQahKP445MEJEh5rA9Rfw+eX9UKUpyIp0keRCkxxytxMDVnR2gAMACXrx98gZyc2eO/f h35B7Zj0flXiiA+oxU+mz5bzmILfaFQBzGBn8hQnxjIh8R5UScFPWSdDKEoPvJWsvW3v INATGboUjpijAt8oPnr8bjFpVTuwGq+P/lsgERnYdPj72J4fwPEYN/ddQ7PKO1XNyvda 08qQ== X-Gm-Message-State: ABuFfogCUHipAASJQs1s3BmUL4/YF5v3nPyPUYhyUWKkXW+zYw1Rr9Yt sCFVe7OlAUBWFZvGI9DNfZg= X-Google-Smtp-Source: ACcGV63QjsrJbRwU5cAl0MzKeHSMW/wwfoQ5OxrsVSViU8k1wPBAVs/y59uPeF9znxjnDgYruHnI7g== X-Received: by 2002:a63:78cc:: with SMTP id t195-v6mr8146071pgc.329.1539406512206; Fri, 12 Oct 2018 21:55:12 -0700 (PDT) Received: from localhost.localdomain (c-24-6-192-50.hsd1.ca.comcast.net. [24.6.192.50]) by smtp.gmail.com with ESMTPSA id h87-v6sm6959462pfj.78.2018.10.12.21.55.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Oct 2018 21:55:11 -0700 (PDT) From: frowand.list@gmail.com To: Rob Herring , Pantelis Antoniou , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Alan Tull , Moritz Fischer Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, devicetree@vger.kernel.org, linux-fpga@vger.kernel.org Subject: [PATCH v2 06/18] of: overlay: do not duplicate properties from overlay for new nodes Date: Fri, 12 Oct 2018 21:53:26 -0700 Message-Id: <1539406418-18162-7-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1539406418-18162-1-git-send-email-frowand.list@gmail.com> References: <1539406418-18162-1-git-send-email-frowand.list@gmail.com> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Frank Rowand When allocating a new node, add_changeset_node() was duplicating the properties from the respective node in the overlay instead of allocating a node with no properties. When this patch is applied the errors reported by the devictree unittest from patch "of: overlay: add tests to validate kfrees from overlay removal" will no longer occur. These error messages are of the form: "OF: ERROR: ..." and the unittest results will change from: ### dt-test ### end of unittest - 203 passed, 7 failed to ### dt-test ### end of unittest - 210 passed, 0 failed Signed-off-by: Frank Rowand --- drivers/of/overlay.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c index 94740f4ee34c..7fcf4a812d06 100644 --- a/drivers/of/overlay.c +++ b/drivers/of/overlay.c @@ -393,7 +393,7 @@ static int add_changeset_node(struct overlay_changeset *ovcs, break; if (!tchild) { - tchild = __of_node_dup(node, node_kbasename); + tchild = __of_node_dup(NULL, node_kbasename); if (!tchild) return -ENOMEM; From patchwork Sat Oct 13 04:53:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Rowand X-Patchwork-Id: 983435 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="aieeOH44"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42XC8m4PXHz9s8F for ; Sat, 13 Oct 2018 15:56:24 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726567AbeJMMaz (ORCPT ); Sat, 13 Oct 2018 08:30:55 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:39712 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726758AbeJMMay (ORCPT ); Sat, 13 Oct 2018 08:30:54 -0400 Received: by mail-pf1-f194.google.com with SMTP id c25-v6so7159406pfe.6; Fri, 12 Oct 2018 21:55:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zTyDK37nEPqC274OyD1pd7pErEfzjwmbQUNIOEBPW0Q=; b=aieeOH447DK7DbUWKRAuufp+TSvCLIH9Rp/TPjAtgUAGo+gtvb5ewKzkM/5Rt18e5g Le2oQVWZLORA4kcDvaUFKqWkQD3cRf0lBuoMEmVmRNe6LcWWb9+WEMZTqbIZ+anm2fvB f9Wzm7LrAjeMhQrVsCB2wNNp0EDP6ZPcfrRRQQskfQWBdB1PRx2TMyXaiSB/HAElTEkl OgMPwPrV4o4WMs6hvpTWFZuHWmmApAbq2stoG+tLjVZKxDMp1etZB3I4dX9oEbxqvS1j Eb6AKOynY0+5ZOdI0N8pqsQBdRi5jesy2XZfWLHmQCSBbdvHLs9JaPaiiai2e7OSbCeR cKPA== 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=zTyDK37nEPqC274OyD1pd7pErEfzjwmbQUNIOEBPW0Q=; b=OcDccU62RCI4YEAvR6qZ9Z7tG5zc9r2ZJE9cgSHKWxc0Cw89pP4eZyBcgWttDMeu+u GYhLEBmq/OKUCsno3gbxIMgwPAiMC6Uur7lLepUAJ8IsAk4uGImCfwpxjB3gQUo6HlJE Ca7ia3Nn+iThCwFgUqqudzxNjLp7vpq7qZ4B27bhAg686YjNctNm7vJHPZ2DuldwruAk B8BBpQxVwq2NAKwAfPUvI4YQxI8VrfDOKJ9G5YfM6VJiNStNHfiBQM3nEPdRHwjM7I5d FHvthpDkAS7/f6cuA5LePWNDdyaIwQXqrAVk0NEBH2YRPyDz5I6hhM65OUq9HqQLaBSJ DcWw== X-Gm-Message-State: ABuFfoipRbOBl/J8xShag/MBKxqmUuA8guEFKE7rFWIw+GAbmZ/Ou2RE hjCh7nK9hygogTmsbsbb85I= X-Google-Smtp-Source: ACcGV61PB3Rukpoq9wJ9i50cIlkmUabvNFAR6aRAw2f8WPXSqiFNPINvqWdGiFrkPQnntC7TRX7Nzw== X-Received: by 2002:a63:e601:: with SMTP id g1-v6mr8232082pgh.290.1539406513472; Fri, 12 Oct 2018 21:55:13 -0700 (PDT) Received: from localhost.localdomain (c-24-6-192-50.hsd1.ca.comcast.net. [24.6.192.50]) by smtp.gmail.com with ESMTPSA id h87-v6sm6959462pfj.78.2018.10.12.21.55.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Oct 2018 21:55:12 -0700 (PDT) From: frowand.list@gmail.com To: Rob Herring , Pantelis Antoniou , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Alan Tull , Moritz Fischer Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, devicetree@vger.kernel.org, linux-fpga@vger.kernel.org Subject: [PATCH v2 07/18] of: dynamic: change type of of_{at, de}tach_node() to void Date: Fri, 12 Oct 2018 21:53:27 -0700 Message-Id: <1539406418-18162-8-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1539406418-18162-1-git-send-email-frowand.list@gmail.com> References: <1539406418-18162-1-git-send-email-frowand.list@gmail.com> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Frank Rowand of_attach_node() and of_detach_node() always return zero, so their return value is meaningless. Change their type to void and fix all callers to ignore return value. Signed-off-by: Frank Rowand --- arch/powerpc/platforms/pseries/dlpar.c | 13 ++----------- arch/powerpc/platforms/pseries/reconfig.c | 6 +----- drivers/of/dynamic.c | 9 ++------- include/linux/of.h | 4 ++-- 4 files changed, 7 insertions(+), 25 deletions(-) diff --git a/arch/powerpc/platforms/pseries/dlpar.c b/arch/powerpc/platforms/pseries/dlpar.c index e3010b14aea5..0027eea94a8b 100644 --- a/arch/powerpc/platforms/pseries/dlpar.c +++ b/arch/powerpc/platforms/pseries/dlpar.c @@ -244,15 +244,9 @@ struct device_node *dlpar_configure_connector(__be32 drc_index, int dlpar_attach_node(struct device_node *dn, struct device_node *parent) { - int rc; - dn->parent = parent; - rc = of_attach_node(dn); - if (rc) { - printk(KERN_ERR "Failed to add device node %pOF\n", dn); - return rc; - } + of_attach_node(dn); return 0; } @@ -260,7 +254,6 @@ int dlpar_attach_node(struct device_node *dn, struct device_node *parent) int dlpar_detach_node(struct device_node *dn) { struct device_node *child; - int rc; child = of_get_next_child(dn, NULL); while (child) { @@ -268,9 +261,7 @@ int dlpar_detach_node(struct device_node *dn) child = of_get_next_child(dn, child); } - rc = of_detach_node(dn); - if (rc) - return rc; + of_detach_node(dn); of_node_put(dn); diff --git a/arch/powerpc/platforms/pseries/reconfig.c b/arch/powerpc/platforms/pseries/reconfig.c index 0e0208117e77..0b72098da454 100644 --- a/arch/powerpc/platforms/pseries/reconfig.c +++ b/arch/powerpc/platforms/pseries/reconfig.c @@ -47,11 +47,7 @@ static int pSeries_reconfig_add_node(const char *path, struct property *proplist goto out_err; } - err = of_attach_node(np); - if (err) { - printk(KERN_ERR "Failed to add device node %s\n", path); - goto out_err; - } + of_attach_node(np); of_node_put(np->parent); diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c index 275c0d7e2268..5f7c99b9de0d 100644 --- a/drivers/of/dynamic.c +++ b/drivers/of/dynamic.c @@ -224,7 +224,7 @@ static void __of_attach_node(struct device_node *np) /** * of_attach_node() - Plug a device node into the tree and global list. */ -int of_attach_node(struct device_node *np) +void of_attach_node(struct device_node *np) { struct of_reconfig_data rd; unsigned long flags; @@ -241,8 +241,6 @@ int of_attach_node(struct device_node *np) mutex_unlock(&of_mutex); of_reconfig_notify(OF_RECONFIG_ATTACH_NODE, &rd); - - return 0; } void __of_detach_node(struct device_node *np) @@ -273,11 +271,10 @@ void __of_detach_node(struct device_node *np) /** * of_detach_node() - "Unplug" a node from the device tree. */ -int of_detach_node(struct device_node *np) +void of_detach_node(struct device_node *np) { struct of_reconfig_data rd; unsigned long flags; - int rc = 0; memset(&rd, 0, sizeof(rd)); rd.dn = np; @@ -291,8 +288,6 @@ int of_detach_node(struct device_node *np) mutex_unlock(&of_mutex); of_reconfig_notify(OF_RECONFIG_DETACH_NODE, &rd); - - return rc; } EXPORT_SYMBOL_GPL(of_detach_node); diff --git a/include/linux/of.h b/include/linux/of.h index aa1dafaec6ae..72c593455019 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -406,8 +406,8 @@ extern int of_phandle_iterator_args(struct of_phandle_iterator *it, #define OF_RECONFIG_REMOVE_PROPERTY 0x0004 #define OF_RECONFIG_UPDATE_PROPERTY 0x0005 -extern int of_attach_node(struct device_node *); -extern int of_detach_node(struct device_node *); +extern void of_attach_node(struct device_node *np); +extern void of_detach_node(struct device_node *np); #define of_match_ptr(_ptr) (_ptr) From patchwork Sat Oct 13 04:53:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Rowand X-Patchwork-Id: 983424 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="O9auGlgy"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42XC7f4P7tz9sBq for ; Sat, 13 Oct 2018 15:55:26 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726910AbeJMMaz (ORCPT ); Sat, 13 Oct 2018 08:30:55 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:36379 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726758AbeJMMaz (ORCPT ); Sat, 13 Oct 2018 08:30:55 -0400 Received: by mail-pg1-f193.google.com with SMTP id f18-v6so6757318pgv.3; Fri, 12 Oct 2018 21:55:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zdOcjsQSagxh/0ytfqlFE21zp3hEcz2hdT+yMst4gNc=; b=O9auGlgy9Z0x96YJvAYLdz2ST9vhVjlVWQVyAFSXEZqJqvQgoJSMX7PUxtVv1htyyn j6MdDUExsrb+fu88348j/h+zw7BCl5yhPdLFjcEkrNSH1Skg/Ts0bqF6I8ef0P9rkG0Y 4DbhknmzACpRxV1Gi2+1QuiTBqjX3xoXRGk3TMrb/nRl2JfSMvRwWTwZLxkxe+SOkD/I Zi7Ot06wyBOXbR/93+NNuhw/zpkVy/N1wS5lFroZjDp19WXcpzEjinIKuOpz18QDVgZu 4amOrTXFE15X6J8FYLvgmFFR9R2qZZATrL/ozteZDrt4glo8NVTOnCqLOJC3W7VhUPVP B3Bg== 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=zdOcjsQSagxh/0ytfqlFE21zp3hEcz2hdT+yMst4gNc=; b=Pi8zuKRHCrM1j1f63eS6XY9SEcK6tawwSz+9VbdE8sshhDhyEt1KvNuBpVd8dku6Hv 4lIwXb7l9pLegwlkge8F4rWnExxRAhTyEXLHUX2S7mD0r2OJAcl+0AdUFJE798S6rNZg 3wWs8jbIUfZiZ3Xqz32kYh22GCofKk724vv6pDInFkrrl8/LAoex4NVE0I9I3t09cQpf /n0SD6fH/qD2DI1Vq6nKliY4NxQ1XzivTFYVV5gsJiZevhsHMN525gRrPRIIG91NauWq LShiIKCijjRD+9GuckB7z87TorY+h0wJcrCgfrRM2IrKxDr1smTipctezDn/NhEhtkhl covg== X-Gm-Message-State: ABuFfojV03pxymOJ5nTWbTFPdIFirax+eBP53hUyomoQU0hvQ6GVPEjd m2i4AFgKImyfeyf7DXG/Lac= X-Google-Smtp-Source: ACcGV62/3cjHH3VSCDcqLdDQDe1vjv4RkZlK643dZfhmlauhKbpks3bxf0tdhPRVcJpdfMly1+U6Ig== X-Received: by 2002:a63:40c2:: with SMTP id n185-v6mr8236018pga.116.1539406514759; Fri, 12 Oct 2018 21:55:14 -0700 (PDT) Received: from localhost.localdomain (c-24-6-192-50.hsd1.ca.comcast.net. [24.6.192.50]) by smtp.gmail.com with ESMTPSA id h87-v6sm6959462pfj.78.2018.10.12.21.55.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Oct 2018 21:55:14 -0700 (PDT) From: frowand.list@gmail.com To: Rob Herring , Pantelis Antoniou , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Alan Tull , Moritz Fischer Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, devicetree@vger.kernel.org, linux-fpga@vger.kernel.org Subject: [PATCH v2 08/18] of: overlay: reorder fields in struct fragment Date: Fri, 12 Oct 2018 21:53:28 -0700 Message-Id: <1539406418-18162-9-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1539406418-18162-1-git-send-email-frowand.list@gmail.com> References: <1539406418-18162-1-git-send-email-frowand.list@gmail.com> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Frank Rowand Order the fields of struct fragment in the same order as struct of_overlay_notify_data. The order in struct fragment is not significant. If both structs are ordered the same then when examining the data in a debugger or dump the human involved does not have to remember which context they are examining. Signed-off-by: Frank Rowand --- drivers/of/overlay.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c index 7fcf4a812d06..272a0d1a5e18 100644 --- a/drivers/of/overlay.c +++ b/drivers/of/overlay.c @@ -49,8 +49,8 @@ struct target { * @overlay: pointer to the __overlay__ node */ struct fragment { - struct device_node *target; struct device_node *overlay; + struct device_node *target; }; /** From patchwork Sat Oct 13 04:53:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Rowand X-Patchwork-Id: 983434 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="XZ4qXCA6"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42XC8d21syz9s8F for ; Sat, 13 Oct 2018 15:56:17 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726943AbeJMMa5 (ORCPT ); Sat, 13 Oct 2018 08:30:57 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:39048 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726758AbeJMMa4 (ORCPT ); Sat, 13 Oct 2018 08:30:56 -0400 Received: by mail-pl1-f194.google.com with SMTP id w14-v6so6817214plp.6; Fri, 12 Oct 2018 21:55:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=BwKhWXvi9uObifIA2caG7KxBnrbJ0SRY7Oj5Ow4g1sM=; b=XZ4qXCA6jBwzs4BJQJHCEF4+8gTh9fFr52BmTGEckHBTT9Nra/WMAJ32F3wyt0umZg jZ/jQJJx5dBAt/rhoUf98Vv9w6ypT/t1mMO5oZH2qxL61LON4yddsoR/uRFTw5yHXkKj J5ZsNLbBRQ1gpU/EHhZoxab8VZViK0hPgMy6DtQa2+JdFaaOlUyQZ7zGguVWI42m/hD1 ecgYiRoFLOlxQOSs+CS/d8KW3UttiD/brvms5FD/0Oq4jr9g6nlC+4bZKnBYM9xqHsLI TkdT4gIDUMvA0QLBxMnlyNgnLkhFjzy0FtV4Bm2stIZbhi08mQkJZOREl5RA9E9SFrMO 2epg== 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=BwKhWXvi9uObifIA2caG7KxBnrbJ0SRY7Oj5Ow4g1sM=; b=Nr2IiXgtkwwl5Y4iR0GLZO0Q6MkmTJy9Utw9t9XSKjP0+hukqrq8hI8MXilAmKsWjA EFR832dsFTPCp5SnlYN/UKOdhJbfifrJnZmDNcSHCOPr29kGKXIO/CiykBjignX9XW+t xhwthHCxlX+n5y6DsnXoSO5KI86BmiVVbkLlr70Jt02Uhg9FdKw/Ys112m8FMsmN0JKv 0L98/W7WU/TtMj6Ox20+ZeYyK/p67lQXOPUsrtuOIzcfttG6nbVlZ581V7B6pa1PXeMo cd5llRJENCOiTD6d7056hy5jHMZtSW/xivWrhtuYwoZeA2GcAigdq7wlaPvJcNxYYr8W VEnQ== X-Gm-Message-State: ABuFfogUfzFcDIibAv3Zvkgqp4bWHbh1eZc5ILmCqvQRCNGVj8Lpb7Y8 hyv5dDFuPNQ8WfBCetD2ZXg= X-Google-Smtp-Source: ACcGV62f3udKGPelQenyfTrmljSknUmfOiXF7LK4m9fe8WDAEAmXINJzXsckXVJCGBO/ZFK64aRSTA== X-Received: by 2002:a17:902:2:: with SMTP id 2-v6mr8743154pla.178.1539406516046; Fri, 12 Oct 2018 21:55:16 -0700 (PDT) Received: from localhost.localdomain (c-24-6-192-50.hsd1.ca.comcast.net. [24.6.192.50]) by smtp.gmail.com with ESMTPSA id h87-v6sm6959462pfj.78.2018.10.12.21.55.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Oct 2018 21:55:15 -0700 (PDT) From: frowand.list@gmail.com To: Rob Herring , Pantelis Antoniou , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Alan Tull , Moritz Fischer Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, devicetree@vger.kernel.org, linux-fpga@vger.kernel.org Subject: [PATCH v2 09/18] of: overlay: validate overlay properties #address-cells and #size-cells Date: Fri, 12 Oct 2018 21:53:29 -0700 Message-Id: <1539406418-18162-10-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1539406418-18162-1-git-send-email-frowand.list@gmail.com> References: <1539406418-18162-1-git-send-email-frowand.list@gmail.com> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Frank Rowand If overlay properties #address-cells or #size-cells are already in the live devicetree for any given node, then the values in the overlay must match the values in the live tree. If the properties are already in the live tree then there is no need to create a changeset entry to add them since they must have the same value. This reduces the memory used by the changeset and eliminates a possible memory leak. This is verified by 12 fewer warnings during the devicetree unittest, as the possible memory leak warnings about #address-cells and Signed-off-by: Frank Rowand --- drivers/of/overlay.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c index 272a0d1a5e18..ee66651db553 100644 --- a/drivers/of/overlay.c +++ b/drivers/of/overlay.c @@ -287,7 +287,12 @@ static struct property *dup_and_fixup_symbol_prop( * @target may be either in the live devicetree or in a new subtree that * is contained in the changeset. * - * Some special properties are not updated (no error returned). + * Some special properties are not added or updated (no error returned): + * "name", "phandle", "linux,phandle". + * + * Properties "#address-cells" and "#size-cells" are not updated if they + * are already in the live tree, but if present in the live tree, the values + * in the overlay must match the values in the live tree. * * Update of property in symbols node is not allowed. * @@ -300,6 +305,7 @@ static int add_changeset_property(struct overlay_changeset *ovcs, { struct property *new_prop = NULL, *prop; int ret = 0; + bool check_for_non_overlay_node = false; if (!of_prop_cmp(overlay_prop->name, "name") || !of_prop_cmp(overlay_prop->name, "phandle") || @@ -322,13 +328,39 @@ static int add_changeset_property(struct overlay_changeset *ovcs, if (!new_prop) return -ENOMEM; - if (!prop) + if (!prop) { + + check_for_non_overlay_node = true; ret = of_changeset_add_property(&ovcs->cset, target->np, new_prop); - else + + } else if (!of_prop_cmp(prop->name, "#address-cells")) { + + if (prop->length != 4 || new_prop->length != 4 || + *(u32 *)prop->value != *(u32 *)new_prop->value) + pr_err("ERROR: overlay and/or live tree #address-cells invalid in node %pOF\n", + target->np); + + } else if (!of_prop_cmp(prop->name, "#size-cells")) { + + if (prop->length != 4 || new_prop->length != 4 || + *(u32 *)prop->value != *(u32 *)new_prop->value) + pr_err("ERROR: overlay and/or live tree #size-cells invalid in node %pOF\n", + target->np); + + } else { + + check_for_non_overlay_node = true; ret = of_changeset_update_property(&ovcs->cset, target->np, new_prop); + } + + if (check_for_non_overlay_node && + !of_node_check_flag(target->np, OF_OVERLAY)) + pr_err("WARNING: %s(), memory leak will occur if overlay removed. Property: %pOF/%s\n", + __func__, target->np, new_prop->name); + if (ret) { kfree(new_prop->name); kfree(new_prop->value); From patchwork Sat Oct 13 04:53:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Rowand X-Patchwork-Id: 983433 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="vDU/R59U"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42XC8X3nPmz9s8F for ; Sat, 13 Oct 2018 15:56:12 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726982AbeJMMa6 (ORCPT ); Sat, 13 Oct 2018 08:30:58 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:33372 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726964AbeJMMa6 (ORCPT ); Sat, 13 Oct 2018 08:30:58 -0400 Received: by mail-pf1-f193.google.com with SMTP id 78-v6so4778233pfq.0; Fri, 12 Oct 2018 21:55:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=7GuCPMc1W5/wwPeXRUqL1/hLo5USFMzrx8T5Pgg4dsU=; b=vDU/R59UxNgBUQdVIijhDfniVNLzjvH2HotEL1fSH5I9SWYnqEjIKe8VQWgSTQqCMa PNzB7hXsbj++52zYAxk6zYD0la1P/BJ/YF97yreSV8ZMo20FOi87nzlfXFvZd6PI0OuZ tK41qaQoS20V4oUOgrtFSSuRNndG/Mko4b7lXmrsNvp5VTFMsSmajRCg2brt5O6Q+aBp HX4K5MzZyY5bodEdhpbleIIZekaGjGSXR+HiXwA+aTP2kvASdT/DdeIoLT9Bsfz8Deaz 57XIvE//A8p+UcfvNNZAOEkY7tI6Jft+dugaGawBeLJPyVwp6KR7FWh7DuFUBoBn7Qcw YqMg== 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=7GuCPMc1W5/wwPeXRUqL1/hLo5USFMzrx8T5Pgg4dsU=; b=DviZZC65fAw46M/H+rCvyWOVAzJLpsxn1nMTqfUZgqZ5xWmGKIkJjaiT7cOHCRGpYC wRxxTCb9e24mYFCmqyK5fggpE/7vytur1hMK9Q3bZIOp8xGyUeed76lsPFgIu0u8xjYW fQZxPaACAVKpgQpboTmPCTWfaEmLNQomvt/0cLYaZKHJMwpNx8G1cQlNIsALsU7Yt4Fr 0+5a8mj2SImGMZ+UkJoPrCJYepQllkNMhJZSSrv1XafXpGGIXP8J+UHzQxE7gaIazYay PXnSp7GF5/WPU4NqhSumLbLJJv0hPQP3PPBWYUuC+em+W9Otfjo6To9Gg4+h1ELt2IJs aSug== X-Gm-Message-State: ABuFfohOhODO5P5PePo+xKhIJqCIh7h4XD5GJJEwjKTTFoK6OjQsVWgd QMH+fL0ZSG+whGqcIvPxJZU= X-Google-Smtp-Source: ACcGV62e03u9mIGxo9oTdxgRAgKIkA1RNREpFbyKgtmdMK14KbbsHddvmHYnNeN1VuPjGTsPm7c0Tg== X-Received: by 2002:a63:4a0e:: with SMTP id x14-v6mr7986852pga.34.1539406517331; Fri, 12 Oct 2018 21:55:17 -0700 (PDT) Received: from localhost.localdomain (c-24-6-192-50.hsd1.ca.comcast.net. [24.6.192.50]) by smtp.gmail.com with ESMTPSA id h87-v6sm6959462pfj.78.2018.10.12.21.55.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Oct 2018 21:55:16 -0700 (PDT) From: frowand.list@gmail.com To: Rob Herring , Pantelis Antoniou , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Alan Tull , Moritz Fischer Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, devicetree@vger.kernel.org, linux-fpga@vger.kernel.org Subject: [PATCH v2 10/18] of: overlay: make all pr_debug() and pr_err() messages unique Date: Fri, 12 Oct 2018 21:53:30 -0700 Message-Id: <1539406418-18162-11-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1539406418-18162-1-git-send-email-frowand.list@gmail.com> References: <1539406418-18162-1-git-send-email-frowand.list@gmail.com> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Frank Rowand Make overlay.c debug and error messages unique so that they can be unambiguously found by grep. Signed-off-by: Frank Rowand --- drivers/of/overlay.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c index ee66651db553..a3990c20e210 100644 --- a/drivers/of/overlay.c +++ b/drivers/of/overlay.c @@ -513,7 +513,7 @@ static int build_changeset_symbols_node(struct overlay_changeset *ovcs, for_each_property_of_node(overlay_symbols_node, prop) { ret = add_changeset_property(ovcs, target, prop, 1); if (ret) { - pr_debug("Failed to apply prop @%pOF/%s, err=%d\n", + pr_debug("Failed to apply symbols prop @%pOF/%s, err=%d\n", target->np, prop->name, ret); return ret; } @@ -557,7 +557,8 @@ static int build_changeset(struct overlay_changeset *ovcs) ret = build_changeset_next_level(ovcs, &target, fragment->overlay); if (ret) { - pr_debug("apply failed '%pOF'\n", fragment->target); + pr_debug("fragment apply failed '%pOF'\n", + fragment->target); return ret; } } @@ -570,7 +571,8 @@ static int build_changeset(struct overlay_changeset *ovcs) ret = build_changeset_symbols_node(ovcs, &target, fragment->overlay); if (ret) { - pr_debug("apply failed '%pOF'\n", fragment->target); + pr_debug("symbols fragment apply failed '%pOF'\n", + fragment->target); return ret; } } @@ -879,7 +881,7 @@ static int of_overlay_apply(const void *fdt, struct device_node *tree, ret = __of_changeset_apply_notify(&ovcs->cset); if (ret) - pr_err("overlay changeset entry notify error %d\n", ret); + pr_err("overlay apply changeset entry notify error %d\n", ret); /* notify failure is not fatal, continue */ list_add_tail(&ovcs->ovcs_list, &ovcs_list); @@ -1138,7 +1140,7 @@ int of_overlay_remove(int *ovcs_id) ret = __of_changeset_revert_notify(&ovcs->cset); if (ret) - pr_err("overlay changeset entry notify error %d\n", ret); + pr_err("overlay remove changeset entry notify error %d\n", ret); /* notify failure is not fatal, continue */ *ovcs_id = 0; From patchwork Sat Oct 13 04:53:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Rowand X-Patchwork-Id: 983432 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Edv51Tm5"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42XC8S5ngkz9sCt for ; Sat, 13 Oct 2018 15:56:08 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727028AbeJMMbA (ORCPT ); Sat, 13 Oct 2018 08:31:00 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:36304 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726964AbeJMMa7 (ORCPT ); Sat, 13 Oct 2018 08:30:59 -0400 Received: by mail-pl1-f196.google.com with SMTP id y11-v6so6820413plt.3; Fri, 12 Oct 2018 21:55:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=1eIq+bpAJjW92EtiaqYATBx5CfeVYNbB6/35CF3TsEg=; b=Edv51Tm5V+YnME4rTFQTKB40mZvmwboEh9HvLGiqvuiyZiH9Cp4Kost2sdbjNoYb4i tZexQpai48vDDvNZXqGzyPpes38YGfx7gqYLHsU74Y/t/8qlsA6toCz0PEdOaR5hZKAu X4tHVB4keiunliqmKHH3wQ0LEbl+ItUWJVlblRO2k0SjGu93yg99C+S14v9otBIohJKU rl4hphaqE2Z+NzWThHWzyRgjFiFk1AR+muRq4R5/TFHJWGZqmHIZnIQbgTHJZUJJINrJ ghENYWIquz6CzE3ETEX4jB4CpwmCU4ofZy33jLs72JeL4Q8A0Em9rgBiwRwo9kk4PEdA chsg== 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=1eIq+bpAJjW92EtiaqYATBx5CfeVYNbB6/35CF3TsEg=; b=hzdM2tYnxb2j5y00fRfv2lCWsodIS6kP7yJAQ9MYbtd61XoONCG/h99aJkHl8IP7mu GW/DIHkoktsWk3zKuo9NyOAhw9o41ugt/AddfkcwVMmCmHGKoSoi2mlPO5L2s+peF5DX RYj3C/7MYqqjSRfSWlhiR5sNZxoVWY5vnu0pqp8BUpdrt2cXub8b3SEmSzoIwxXm6zqW 5/7t3NompbYrkQdXBknEaZXqYYXpu7ywvIykea2aRZGtKBdCg2itYy0opCFOIy9rtKcD VrZ5g2FmYDZrXF905EeTZXgeMaAT6BKX5tfwE07C8EUJeeaUmdqc60HhdsKu6bJfAnlS 6O8g== X-Gm-Message-State: ABuFfogAm/7sp/+5TlBeJbDYJ0Hj/cCCOprFqNRQkVPc/pMSRIfw81fQ YKsjcMoN/uQZ27MZqvlslgk= X-Google-Smtp-Source: ACcGV61woqRWwwoYFG03zYGKvhxCyQJHofkGq8cRlGNjRk7Qf/1jSwjLk4sUjSdlxSHvUUGbVlpw1w== X-Received: by 2002:a17:902:8609:: with SMTP id f9-v6mr8577932plo.134.1539406518567; Fri, 12 Oct 2018 21:55:18 -0700 (PDT) Received: from localhost.localdomain (c-24-6-192-50.hsd1.ca.comcast.net. [24.6.192.50]) by smtp.gmail.com with ESMTPSA id h87-v6sm6959462pfj.78.2018.10.12.21.55.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Oct 2018 21:55:18 -0700 (PDT) From: frowand.list@gmail.com To: Rob Herring , Pantelis Antoniou , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Alan Tull , Moritz Fischer Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, devicetree@vger.kernel.org, linux-fpga@vger.kernel.org Subject: [PATCH v2 11/18] of: overlay: test case of two fragments adding same node Date: Fri, 12 Oct 2018 21:53:31 -0700 Message-Id: <1539406418-18162-12-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1539406418-18162-1-git-send-email-frowand.list@gmail.com> References: <1539406418-18162-1-git-send-email-frowand.list@gmail.com> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Frank Rowand Multiple overlay fragments adding or deleting the same node is not supported. An attempt to do so results in an incorrect devicetree. The node name will be munged for the second add. After adding this patch, the unittest messages will show: Duplicate name in motor-1, renamed to "controller#1" OF: overlay: of_overlay_apply() err=0 ### dt-test ### of_overlay_fdt_apply() expected -22, ret=0, overlay_bad_add_dup_node ### dt-test ### FAIL of_unittest_overlay_high_level():2419 Adding overlay 'overlay_bad_add_dup_node' failed ... ### dt-test ### end of unittest - 210 passed, 1 failed The incorrect (munged) node name "controller#1" can be seen in the /proc filesystem: $ pwd /proc/device-tree/testcase-data-2/substation@100/motor-1 $ ls compatible controller controller#1 name phandle spin $ ls controller power_bus $ ls controller#1 power_bus_emergency Signed-off-by: Frank Rowand --- drivers/of/unittest-data/Makefile | 1 + .../of/unittest-data/overlay_bad_add_dup_node.dts | 28 ++++++++++++++++++++++ drivers/of/unittest.c | 5 ++++ 3 files changed, 34 insertions(+) create mode 100644 drivers/of/unittest-data/overlay_bad_add_dup_node.dts diff --git a/drivers/of/unittest-data/Makefile b/drivers/of/unittest-data/Makefile index 013d85e694c6..166dbdbfd1c5 100644 --- a/drivers/of/unittest-data/Makefile +++ b/drivers/of/unittest-data/Makefile @@ -17,6 +17,7 @@ obj-$(CONFIG_OF_OVERLAY) += overlay.dtb.o \ overlay_12.dtb.o \ overlay_13.dtb.o \ overlay_15.dtb.o \ + overlay_bad_add_dup_node.dtb.o \ overlay_bad_phandle.dtb.o \ overlay_bad_symbol.dtb.o \ overlay_base.dtb.o diff --git a/drivers/of/unittest-data/overlay_bad_add_dup_node.dts b/drivers/of/unittest-data/overlay_bad_add_dup_node.dts new file mode 100644 index 000000000000..145dfc3b1024 --- /dev/null +++ b/drivers/of/unittest-data/overlay_bad_add_dup_node.dts @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: GPL-2.0 +/dts-v1/; +/plugin/; + +/* + * &electric_1/motor-1 and &spin_ctrl_1 are the same node: + * /testcase-data-2/substation@100/motor-1 + * + * Thus the new node "controller" in each fragment will + * result in an attempt to add the same node twice. + * This will result in an error and the overlay apply + * will fail. + */ + +&electric_1 { + + motor-1 { + controller { + power_bus = < 0x1 0x2 >; + }; + }; +}; + +&spin_ctrl_1 { + controller { + power_bus_emergency = < 0x101 0x102 >; + }; +}; diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 722537e14848..471b8eb6e842 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -2147,6 +2147,7 @@ struct overlay_info { OVERLAY_INFO_EXTERN(overlay_12); OVERLAY_INFO_EXTERN(overlay_13); OVERLAY_INFO_EXTERN(overlay_15); +OVERLAY_INFO_EXTERN(overlay_bad_add_dup_node); OVERLAY_INFO_EXTERN(overlay_bad_phandle); OVERLAY_INFO_EXTERN(overlay_bad_symbol); @@ -2169,6 +2170,7 @@ struct overlay_info { OVERLAY_INFO(overlay_12, 0), OVERLAY_INFO(overlay_13, 0), OVERLAY_INFO(overlay_15, 0), + OVERLAY_INFO(overlay_bad_add_dup_node, -EINVAL), OVERLAY_INFO(overlay_bad_phandle, -EINVAL), OVERLAY_INFO(overlay_bad_symbol, -EINVAL), {} @@ -2413,6 +2415,9 @@ static __init void of_unittest_overlay_high_level(void) unittest(overlay_data_apply("overlay", NULL), "Adding overlay 'overlay' failed\n"); + unittest(overlay_data_apply("overlay_bad_add_dup_node", NULL), + "Adding overlay 'overlay_bad_add_dup_node' failed\n"); + unittest(overlay_data_apply("overlay_bad_phandle", NULL), "Adding overlay 'overlay_bad_phandle' failed\n"); From patchwork Sat Oct 13 04:53:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Rowand X-Patchwork-Id: 983431 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="g99Xtb6J"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42XC8N6vMwz9sCs for ; Sat, 13 Oct 2018 15:56:04 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727074AbeJMMbB (ORCPT ); Sat, 13 Oct 2018 08:31:01 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:42749 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727034AbeJMMbA (ORCPT ); Sat, 13 Oct 2018 08:31:00 -0400 Received: by mail-pf1-f195.google.com with SMTP id f26-v6so7148459pfn.9; Fri, 12 Oct 2018 21:55:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MQkPQ3Ye7d3w5BiZWu8XQjh4/A63Ebp7lKxP6h4EbZE=; b=g99Xtb6JDwiEl3wyvYqXX2SmR2T5V42+LyhdkSzzDIpwQqu8NPCNq4rREWOttQ8wYR j6Li/rQ7fHUhoI57LZ0rd5IQccaFgExXuebrApHg+Mmymx3d4ge2db4Shm3POrdPi0xy 6ygDLHiCrj0t+ah/Hghpycbml23+FGwN32MJDaKnrItOzNCF40RqmerhMXu0gu3ynHfS GM3E8f5awZYTtRDZyduy/GL3J0uCKQ0geNDzRktqRsVq2V7wrHtYWI7NMC2UT47C3peB tzfBZ/xZ8zjXI4937k6S7pinsHZgy2WTr8BUZtKa217nHwCRX92xsliFWPnZBIb8if89 vXxg== 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=MQkPQ3Ye7d3w5BiZWu8XQjh4/A63Ebp7lKxP6h4EbZE=; b=f80GmtV1DAgu8DCtzoUcbz4COWmkScMpNylTnDmd/6CSTbcChUYx6Dsqz0aDTbavSf VWP3R2lQVeq2/TDy1ZVWX5QDCxSOttXJNlC5V/XZBLEv8hj8e4Jnz9OVpRyLqGRPYST6 oMm1day/Z53mhuR1svvU6U7yvZK8JfRKH+1HYK+wUch6q85TlKRox5Zh6J+1h+6YLMET A//kt09Q5Ci6LEpzXIPJDiArcBDgBqPtl43BOz1BJVyektdMOPUBRTTt+1WCLr2+e6Fp PNm3WGhch4d4kMRkVVxe+XOuBIWA+pQfk9FFROkZ2sWftr4MephkuUUY4zV1VypTvb1K GZMw== X-Gm-Message-State: ABuFfogQSJAYgQ6jtQ0BPOlVmiG6FYE5r9rHEJIn4ZZ1CxXIvbws7UDM aD9sJckZA0iaCQD+3W10wuk= X-Google-Smtp-Source: ACcGV62YEo8xl0qmURaRgThuPQJ8l+1RAltoTf1LqqDn+a+vGT6Ghz0UNjwxBNzW4dS/q0EUGSUnjA== X-Received: by 2002:aa7:86cc:: with SMTP id h12-v6mr8780573pfo.58.1539406519799; Fri, 12 Oct 2018 21:55:19 -0700 (PDT) Received: from localhost.localdomain (c-24-6-192-50.hsd1.ca.comcast.net. [24.6.192.50]) by smtp.gmail.com with ESMTPSA id h87-v6sm6959462pfj.78.2018.10.12.21.55.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Oct 2018 21:55:19 -0700 (PDT) From: frowand.list@gmail.com To: Rob Herring , Pantelis Antoniou , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Alan Tull , Moritz Fischer Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, devicetree@vger.kernel.org, linux-fpga@vger.kernel.org Subject: [PATCH v2 12/18] of: overlay: check prevents multiple fragments add or delete same node Date: Fri, 12 Oct 2018 21:53:32 -0700 Message-Id: <1539406418-18162-13-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1539406418-18162-1-git-send-email-frowand.list@gmail.com> References: <1539406418-18162-1-git-send-email-frowand.list@gmail.com> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Frank Rowand Multiple overlay fragments adding or deleting the same node is not supported. Replace code comment of such, with check to detect the attempt and fail the overlay apply. Devicetree unittest where multiple fragments added the same node was added in the previous patch in the series. After applying this patch the unittest messages will no longer include: Duplicate name in motor-1, renamed to "controller#1" OF: overlay: of_overlay_apply() err=0 ### dt-test ### of_overlay_fdt_apply() expected -22, ret=0, overlay_bad_add_dup_node ### dt-test ### FAIL of_unittest_overlay_high_level():2419 Adding overlay 'overlay_bad_add_dup_node' failed ... ### dt-test ### end of unittest - 210 passed, 1 failed but will instead include: OF: overlay: ERROR: multiple overlay fragments add and/or delete node /testcase-data-2/substation@100/motor-1/controller ... ### dt-test ### end of unittest - 211 passed, 0 failed Signed-off-by: Frank Rowand --- checkpatch errors "line over 80 characters" are ok, they will be fixed two patches later in this series drivers/of/overlay.c | 58 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 9 deletions(-) diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c index a3990c20e210..b0a0dafb6a13 100644 --- a/drivers/of/overlay.c +++ b/drivers/of/overlay.c @@ -398,14 +398,6 @@ static int add_changeset_property(struct overlay_changeset *ovcs, * a live devicetree created from Open Firmware. * * NOTE_2: Multiple mods of created nodes not supported. - * If more than one fragment contains a node that does not already exist - * in the live tree, then for each fragment of_changeset_attach_node() - * will add a changeset entry to add the node. When the changeset is - * applied, __of_attach_node() will attach the node twice (once for - * each fragment). At this point the device tree will be corrupted. - * - * TODO: add integrity check to ensure that multiple fragments do not - * create the same node. * * Returns 0 on success, -ENOMEM if memory allocation failure, or -EINVAL if * invalid @overlay. @@ -523,6 +515,54 @@ static int build_changeset_symbols_node(struct overlay_changeset *ovcs, } /** + * check_changeset_dup_add_node() - changeset validation: duplicate add node + * @ovcs: Overlay changeset + * + * Check changeset @ovcs->cset for multiple add node entries for the same + * node. + * + * Returns 0 on success, -ENOMEM if memory allocation failure, or -EINVAL if + * invalid overlay in @ovcs->fragments[]. + */ +static int check_changeset_dup_add_node(struct overlay_changeset *ovcs) +{ + struct of_changeset_entry *ce_1, *ce_2; + char *fn_1, *fn_2; + int name_match; + + list_for_each_entry(ce_1, &ovcs->cset.entries, node) { + + if (ce_1->action == OF_RECONFIG_ATTACH_NODE || + ce_1->action == OF_RECONFIG_DETACH_NODE) { + + ce_2 = ce_1; + list_for_each_entry_continue(ce_2, &ovcs->cset.entries, node) { + if (ce_2->action == OF_RECONFIG_ATTACH_NODE || + ce_2->action == OF_RECONFIG_DETACH_NODE) { + /* inexpensive name compare */ + if (!of_node_cmp(ce_1->np->full_name, + ce_2->np->full_name)) { + /* expensive full path name compare */ + fn_1 = kasprintf(GFP_KERNEL, "%pOF", ce_1->np); + fn_2 = kasprintf(GFP_KERNEL, "%pOF", ce_2->np); + name_match = !strcmp(fn_1, fn_2); + kfree(fn_1); + kfree(fn_2); + if (name_match) { + pr_err("ERROR: multiple overlay fragments add and/or delete node %pOF\n", + ce_1->np); + return -EINVAL; + } + } + } + } + } + } + + return 0; +} + +/** * build_changeset() - populate overlay changeset in @ovcs from @ovcs->fragments * @ovcs: Overlay changeset * @@ -577,7 +617,7 @@ static int build_changeset(struct overlay_changeset *ovcs) } } - return 0; + return check_changeset_dup_add_node(ovcs); } /* From patchwork Sat Oct 13 04:53:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Rowand X-Patchwork-Id: 983430 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="WohTrsre"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42XC8J62d5z9sCs for ; Sat, 13 Oct 2018 15:56:00 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727098AbeJMMbC (ORCPT ); Sat, 13 Oct 2018 08:31:02 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:34399 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726964AbeJMMbC (ORCPT ); Sat, 13 Oct 2018 08:31:02 -0400 Received: by mail-pl1-f196.google.com with SMTP id f18-v6so6831875plr.1; Fri, 12 Oct 2018 21:55:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=0tjXmIOZeYe99jwz16UIHULba0twA5UYndDfn4uoMbk=; b=WohTrsre9HO9Kn08nszvUwmj3TLoYX0ym9zm2IL9YbRFkX4tJmQhur6C9IkYJHPbGu A3TSuW5rKd+95wMJRso7gauj93wZMcv/7+gD6Kh8qruFLr0qD3VAqYS9iLJBvIFSQU7r EdBHksqVcURC2Umq/5ALg1R1VuQVkvJ09oNQJz16pEvqtC74A1ZInHzRVpyru6Xfzk8b pIOKNHiOtPK/VmmNJvZJTfNW4aBGkngBzhlUFNzXA+ImUUBwnvYKtPaBY68OSyMQYkGd SEiQpgfow/HmRCbzrH/tbgpTkEad24fVt7n9H5foDE3u8SZ/uohlza0lgyOoSE3UAOuZ etLg== 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=0tjXmIOZeYe99jwz16UIHULba0twA5UYndDfn4uoMbk=; b=ENUjfMRhE25g6XLdZV40qX3GS/NTMU9SiVCTFWfJYfbAbME+MdzhG+x4MKW+bAgvzN AJK6PMGm6sHzdbEz2JEnPmF8DT1cn97wAPSo2awEc+INxBBG81tN8j3oEMXMrjhz9jvc ZZBMsMq9BIQG9SwvSSOCZLIthYutDXfTiq2rVrOAhbrL2rlNAGxub4OxJ6nXRlu5fKXV npHq4oYH6Ocy95lMJaDIxc6/smFRqySia3wIrVr15t/5HopA6H82RsPU0dDzEHfxVeFB ASfFqiKhn3ke5XL08jtJtc2aigav4eGB32WlCrVbGPzTC4dlpJwexP9tAMsl7o3w31DL fSOQ== X-Gm-Message-State: ABuFfoh1WIIzwgPMmJ453AFS06IMhzvDcvPFBPtxeJJab72F66NnZ5Gv 469ac+bB0fgRD+AY0aW2Q/0= X-Google-Smtp-Source: ACcGV636//HHz10r+Ib1TEOnt+xZ5lU01W0MnR28q1HKdpFFJ3v5O+dg/vceUxhY7EwXOGvhlNTBCg== X-Received: by 2002:a17:902:9b89:: with SMTP id y9-v6mr8555494plp.239.1539406521027; Fri, 12 Oct 2018 21:55:21 -0700 (PDT) Received: from localhost.localdomain (c-24-6-192-50.hsd1.ca.comcast.net. [24.6.192.50]) by smtp.gmail.com with ESMTPSA id h87-v6sm6959462pfj.78.2018.10.12.21.55.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Oct 2018 21:55:20 -0700 (PDT) From: frowand.list@gmail.com To: Rob Herring , Pantelis Antoniou , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Alan Tull , Moritz Fischer Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, devicetree@vger.kernel.org, linux-fpga@vger.kernel.org Subject: [PATCH v2 13/18] of: overlay: check prevents multiple fragments touching same property Date: Fri, 12 Oct 2018 21:53:33 -0700 Message-Id: <1539406418-18162-14-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1539406418-18162-1-git-send-email-frowand.list@gmail.com> References: <1539406418-18162-1-git-send-email-frowand.list@gmail.com> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Frank Rowand Add test case of two fragments updating the same property. After adding the test case, the system hangs at end of boot, after after slub stack dumps from kfree() in crypto modprobe code. Multiple overlay fragments adding, modifying, or deleting the same property is not supported. Add check to detect the attempt and fail the overlay apply. After applying this patch, the devicetree unittest messages will include: OF: overlay: ERROR: multiple overlay fragments add, update, and/or delete property /testcase-data-2/substation@100/motor-1/rpm_avail ... ### dt-test ### end of unittest - 212 passed, 0 failed The check to detect two fragments updating the same property is folded into the patch that created the test case to maintain bisectability. Signed-off-by: Frank Rowand --- drivers/of/overlay.c | 118 ++++++++++++++------- drivers/of/unittest-data/Makefile | 1 + .../of/unittest-data/overlay_bad_add_dup_prop.dts | 24 +++++ drivers/of/unittest-data/overlay_base.dts | 1 + drivers/of/unittest.c | 5 + 5 files changed, 112 insertions(+), 37 deletions(-) create mode 100644 drivers/of/unittest-data/overlay_bad_add_dup_prop.dts diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c index b0a0dafb6a13..41f56091663b 100644 --- a/drivers/of/overlay.c +++ b/drivers/of/overlay.c @@ -514,52 +514,96 @@ static int build_changeset_symbols_node(struct overlay_changeset *ovcs, return 0; } +static int find_dup_cset_node_entry(struct overlay_changeset *ovcs, + struct of_changeset_entry *ce_1) +{ + struct of_changeset_entry *ce_2; + char *fn_1, *fn_2; + int node_path_match; + + if (ce_1->action != OF_RECONFIG_ATTACH_NODE && + ce_1->action != OF_RECONFIG_DETACH_NODE) + return 0; + + ce_2 = ce_1; + list_for_each_entry_continue(ce_2, &ovcs->cset.entries, node) { + if ((ce_2->action == OF_RECONFIG_ATTACH_NODE || + ce_2->action == OF_RECONFIG_DETACH_NODE) && + !of_node_cmp(ce_1->np->full_name, ce_2->np->full_name)) { + + fn_1 = kasprintf(GFP_KERNEL, "%pOF", ce_1->np); + fn_2 = kasprintf(GFP_KERNEL, "%pOF", ce_2->np); + node_path_match = !strcmp(fn_1, fn_2); + kfree(fn_1); + kfree(fn_2); + if (node_path_match) { + pr_err("ERROR: multiple overlay fragments add and/or delete node %pOF\n", + ce_1->np); + return -EINVAL; + } + } + } + + return 0; +} + +static int find_dup_cset_prop(struct overlay_changeset *ovcs, + struct of_changeset_entry *ce_1) +{ + struct of_changeset_entry *ce_2; + char *fn_1, *fn_2; + int node_path_match; + + if (ce_1->action != OF_RECONFIG_ADD_PROPERTY && + ce_1->action != OF_RECONFIG_REMOVE_PROPERTY && + ce_1->action != OF_RECONFIG_UPDATE_PROPERTY) + return 0; + + ce_2 = ce_1; + list_for_each_entry_continue(ce_2, &ovcs->cset.entries, node) { + if ((ce_2->action == OF_RECONFIG_ADD_PROPERTY || + ce_2->action == OF_RECONFIG_REMOVE_PROPERTY || + ce_2->action == OF_RECONFIG_UPDATE_PROPERTY) && + !of_node_cmp(ce_1->np->full_name, ce_2->np->full_name)) { + + fn_1 = kasprintf(GFP_KERNEL, "%pOF", ce_1->np); + fn_2 = kasprintf(GFP_KERNEL, "%pOF", ce_2->np); + node_path_match = !strcmp(fn_1, fn_2); + kfree(fn_1); + kfree(fn_2); + if (node_path_match && + !of_prop_cmp(ce_1->prop->name, ce_2->prop->name)) { + pr_err("ERROR: multiple overlay fragments add, update, and/or delete property %pOF/%s\n", + ce_1->np, ce_1->prop->name); + return -EINVAL; + } + } + } + + return 0; +} + /** - * check_changeset_dup_add_node() - changeset validation: duplicate add node + * changeset_dup_entry_check() - check for duplicate entries * @ovcs: Overlay changeset * - * Check changeset @ovcs->cset for multiple add node entries for the same - * node. + * Check changeset @ovcs->cset for multiple {add or delete} node entries for + * the same node or duplicate {add, delete, or update} properties entries + * for the same property. * - * Returns 0 on success, -ENOMEM if memory allocation failure, or -EINVAL if - * invalid overlay in @ovcs->fragments[]. + * Returns 0 on success, or -EINVAL if duplicate changeset entry found. */ -static int check_changeset_dup_add_node(struct overlay_changeset *ovcs) +static int changeset_dup_entry_check(struct overlay_changeset *ovcs) { - struct of_changeset_entry *ce_1, *ce_2; - char *fn_1, *fn_2; - int name_match; + struct of_changeset_entry *ce_1; + int dup_entry = 0; list_for_each_entry(ce_1, &ovcs->cset.entries, node) { - - if (ce_1->action == OF_RECONFIG_ATTACH_NODE || - ce_1->action == OF_RECONFIG_DETACH_NODE) { - - ce_2 = ce_1; - list_for_each_entry_continue(ce_2, &ovcs->cset.entries, node) { - if (ce_2->action == OF_RECONFIG_ATTACH_NODE || - ce_2->action == OF_RECONFIG_DETACH_NODE) { - /* inexpensive name compare */ - if (!of_node_cmp(ce_1->np->full_name, - ce_2->np->full_name)) { - /* expensive full path name compare */ - fn_1 = kasprintf(GFP_KERNEL, "%pOF", ce_1->np); - fn_2 = kasprintf(GFP_KERNEL, "%pOF", ce_2->np); - name_match = !strcmp(fn_1, fn_2); - kfree(fn_1); - kfree(fn_2); - if (name_match) { - pr_err("ERROR: multiple overlay fragments add and/or delete node %pOF\n", - ce_1->np); - return -EINVAL; - } - } - } - } - } + dup_entry |= find_dup_cset_node_entry(ovcs, ce_1); + dup_entry |= find_dup_cset_prop(ovcs, ce_1); } - return 0; + return dup_entry ? -EINVAL : 0; } /** @@ -617,7 +661,7 @@ static int build_changeset(struct overlay_changeset *ovcs) } } - return check_changeset_dup_add_node(ovcs); + return changeset_dup_entry_check(ovcs); } /* diff --git a/drivers/of/unittest-data/Makefile b/drivers/of/unittest-data/Makefile index 166dbdbfd1c5..9b6807065827 100644 --- a/drivers/of/unittest-data/Makefile +++ b/drivers/of/unittest-data/Makefile @@ -18,6 +18,7 @@ obj-$(CONFIG_OF_OVERLAY) += overlay.dtb.o \ overlay_13.dtb.o \ overlay_15.dtb.o \ overlay_bad_add_dup_node.dtb.o \ + overlay_bad_add_dup_prop.dtb.o \ overlay_bad_phandle.dtb.o \ overlay_bad_symbol.dtb.o \ overlay_base.dtb.o diff --git a/drivers/of/unittest-data/overlay_bad_add_dup_prop.dts b/drivers/of/unittest-data/overlay_bad_add_dup_prop.dts new file mode 100644 index 000000000000..c190da54f175 --- /dev/null +++ b/drivers/of/unittest-data/overlay_bad_add_dup_prop.dts @@ -0,0 +1,24 @@ +// SPDX-License-Identifier: GPL-2.0 +/dts-v1/; +/plugin/; + +/* + * &electric_1/motor-1 and &spin_ctrl_1 are the same node: + * /testcase-data-2/substation@100/motor-1 + * + * Thus the property "rpm_avail" in each fragment will + * result in an attempt to update the same property twice. + * This will result in an error and the overlay apply + * will fail. + */ + +&electric_1 { + + motor-1 { + rpm_avail = < 100 >; + }; +}; + +&spin_ctrl_1 { + rpm_avail = < 100 200 >; +}; diff --git a/drivers/of/unittest-data/overlay_base.dts b/drivers/of/unittest-data/overlay_base.dts index 820b79ca378a..99ab9d12d00b 100644 --- a/drivers/of/unittest-data/overlay_base.dts +++ b/drivers/of/unittest-data/overlay_base.dts @@ -30,6 +30,7 @@ spin_ctrl_1: motor-1 { compatible = "ot,ferris-wheel-motor"; spin = "clockwise"; + rpm_avail = < 50 >; }; spin_ctrl_2: motor-8 { diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 471b8eb6e842..efd9c947f192 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -2148,6 +2148,7 @@ struct overlay_info { OVERLAY_INFO_EXTERN(overlay_13); OVERLAY_INFO_EXTERN(overlay_15); OVERLAY_INFO_EXTERN(overlay_bad_add_dup_node); +OVERLAY_INFO_EXTERN(overlay_bad_add_dup_prop); OVERLAY_INFO_EXTERN(overlay_bad_phandle); OVERLAY_INFO_EXTERN(overlay_bad_symbol); @@ -2171,6 +2172,7 @@ struct overlay_info { OVERLAY_INFO(overlay_13, 0), OVERLAY_INFO(overlay_15, 0), OVERLAY_INFO(overlay_bad_add_dup_node, -EINVAL), + OVERLAY_INFO(overlay_bad_add_dup_prop, -EINVAL), OVERLAY_INFO(overlay_bad_phandle, -EINVAL), OVERLAY_INFO(overlay_bad_symbol, -EINVAL), {} @@ -2418,6 +2420,9 @@ static __init void of_unittest_overlay_high_level(void) unittest(overlay_data_apply("overlay_bad_add_dup_node", NULL), "Adding overlay 'overlay_bad_add_dup_node' failed\n"); + unittest(overlay_data_apply("overlay_bad_add_dup_prop", NULL), + "Adding overlay 'overlay_bad_add_dup_prop' failed\n"); + unittest(overlay_data_apply("overlay_bad_phandle", NULL), "Adding overlay 'overlay_bad_phandle' failed\n"); From patchwork Sat Oct 13 04:53:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Rowand X-Patchwork-Id: 983428 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="laCzalge"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42XC872SJKz9sj2 for ; Sat, 13 Oct 2018 15:55:51 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727148AbeJMMbF (ORCPT ); Sat, 13 Oct 2018 08:31:05 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:43478 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727034AbeJMMbD (ORCPT ); Sat, 13 Oct 2018 08:31:03 -0400 Received: by mail-pl1-f194.google.com with SMTP id 30-v6so6807710plb.10; Fri, 12 Oct 2018 21:55:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=PMEoU3Gz26JMyroIsJaDweM2uFKnZxU+TruAPOzAvDQ=; b=laCzalgeYZJRzC6FMlo4fpiPie/6r4Hc6a54c2Uj5Hy4Tm/eJIIPeV8VYqS8RF6hra O6Sd6K448eGR9X3uAylMFx1KvM71hnf2ozfenx51hRbBkSAJ6Qci6OR0lVnD2LgXg+b+ XyRzB+Zu2fsCRgO1McEDf2qQaMo946NU8/B3R6XxQkuzlm+5YptElzE0cowc83msF67f dHgEKVPRvqBhwepF8w3OLN65+hVj95YJgOghfwuvh7f6V5qGd8cj5RgkD8GCgomwVsD5 B8HnEls8H+wOP44MonWpzw2cWxSk4YCeeyOrx9iCnZjtOsmkKPATNgrwwc72c7Kj8geJ btuw== 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=PMEoU3Gz26JMyroIsJaDweM2uFKnZxU+TruAPOzAvDQ=; b=INrLImIBHql1pXnmCCIHjaV8l0ddvv10dqM56eWdnik4tw85mcXaxOUypJDsWgLkXv hZZ9/XOxqGLZilZtJlDP7IZWBnsxrU3xNr1vkmSXUoZskKzMsIFoGAEAh5zOWJfAnhKU azzaJIDaC0RufSfluo5fL8U61ZH9kko9vK9oqQZnOjKsXswZOZHa6Ry9wNj+DgyEOjS/ kcaT++QrFMg2u+rsVM3BhTu03oALmevFfjJvqGglBZMbdjC5AWRdBE0wae+K8pb4tfyj egzpKwbBphvACkzA97s4z75Niy4UyaVoaxq23bZNxqZupzMcPddvGb9+zheUf+VtvRXB z7mA== X-Gm-Message-State: ABuFfohreOOP+w3+mNtubi01NBCah96H63Af6I52qMF9B1mStCL67Q8b yobpnhnb9tlQPLCDnc7gUJNihHAE X-Google-Smtp-Source: ACcGV60a+yR4EpG1SMpmYOMGAUCaS10lPN9HlFu3ryMd+1zTThUgX1zRE5ZfZNkndCb0PyND3ZFxhg== X-Received: by 2002:a17:902:6903:: with SMTP id j3-v6mr4683450plk.74.1539406522244; Fri, 12 Oct 2018 21:55:22 -0700 (PDT) Received: from localhost.localdomain (c-24-6-192-50.hsd1.ca.comcast.net. [24.6.192.50]) by smtp.gmail.com with ESMTPSA id h87-v6sm6959462pfj.78.2018.10.12.21.55.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Oct 2018 21:55:21 -0700 (PDT) From: frowand.list@gmail.com To: Rob Herring , Pantelis Antoniou , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Alan Tull , Moritz Fischer Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, devicetree@vger.kernel.org, linux-fpga@vger.kernel.org Subject: [PATCH v2 14/18] of: unittest: remove unused of_unittest_apply_overlay() argument Date: Fri, 12 Oct 2018 21:53:34 -0700 Message-Id: <1539406418-18162-15-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1539406418-18162-1-git-send-email-frowand.list@gmail.com> References: <1539406418-18162-1-git-send-email-frowand.list@gmail.com> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Frank Rowand Argument unittest_nr is not used in of_unittest_apply_overlay(), remove it. Signed-off-by: Frank Rowand --- drivers/of/unittest.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index efd9c947f192..6d80f474c8f2 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -1419,8 +1419,7 @@ static void of_unittest_destroy_tracked_overlays(void) } while (defers > 0); } -static int __init of_unittest_apply_overlay(int overlay_nr, int unittest_nr, - int *overlay_id) +static int __init of_unittest_apply_overlay(int overlay_nr, int *overlay_id) { const char *overlay_name; @@ -1453,7 +1452,7 @@ static int __init of_unittest_apply_overlay_check(int overlay_nr, } ovcs_id = 0; - ret = of_unittest_apply_overlay(overlay_nr, unittest_nr, &ovcs_id); + ret = of_unittest_apply_overlay(overlay_nr, &ovcs_id); if (ret != 0) { /* of_unittest_apply_overlay already called unittest() */ return ret; @@ -1489,7 +1488,7 @@ static int __init of_unittest_apply_revert_overlay_check(int overlay_nr, /* apply the overlay */ ovcs_id = 0; - ret = of_unittest_apply_overlay(overlay_nr, unittest_nr, &ovcs_id); + ret = of_unittest_apply_overlay(overlay_nr, &ovcs_id); if (ret != 0) { /* of_unittest_apply_overlay already called unittest() */ return ret; From patchwork Sat Oct 13 04:53:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Rowand X-Patchwork-Id: 983429 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="RH4fu3ia"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42XC8F2vjYz9sCt for ; Sat, 13 Oct 2018 15:55:57 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727308AbeJMMbb (ORCPT ); Sat, 13 Oct 2018 08:31:31 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:34266 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726964AbeJMMbE (ORCPT ); Sat, 13 Oct 2018 08:31:04 -0400 Received: by mail-pg1-f196.google.com with SMTP id g12-v6so6752973pgs.1; Fri, 12 Oct 2018 21:55:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Jn/ZX3hb0+yTSU6k3OosQBetoXzlV4oZREJuCtMHGxI=; b=RH4fu3iasPalfHrG537wWspyJP+KLdb8/OuQOHtQmIf3nCZKiTqjes9z68nKRxflQW 6GHVGwKKa413z5m7fP8/SKkEu5BemSpOA6mKKdLygrot7O4mEQ9pK1xMZk4Mlgjc3cuH 744gyQJU7XtV7X1eWDu8MfyVSQtCfMSJsadfuaxS7eVBxnwQBXjA9nCQohAQ5g35VECX sluFaR779u8G+YimKhPRhTdAuW9LFSDB7z9HjpBOgmsVIS/iAnzVG6yaFfEXSbicsR2d oVlOem0r5jfIicJ8jvd7mMX36Sb4YB1BL9lAFzNnuxyopJ+5dm1f2QaEB95Jsy6fh6gu BtTQ== 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=Jn/ZX3hb0+yTSU6k3OosQBetoXzlV4oZREJuCtMHGxI=; b=CdbbPJmhjq3r2/qZzSSPX3JBDbbEcizzkpuisLFctWA18CsYcJLnuJ56pW8xyQ0xxa ZsFcquXrFnRQHcfHe+Cv9yYdh95KXQC2f9/1fDBu2dZiQfJzZhAv2GF0P4udmFG9pQGP n257+RMICdSKvZZcd5WjZLmTp9gRN/yeZSohgbeb3rq7sZRmo26igXXP1pMNQ1GlXd9i 66RGW9lK8nQVPUJUvLEPY2M2+D3DPGR8O9yVWlBbhTFEh508I6gg1xHZxYxyMsjqIWbV rJCeTWfrrIpHGBwzIKJWQXwUHAUf3W3tUu3U7ljkRu0KeHJfe0SGrKVJUhoihMiJqHlm tm4A== X-Gm-Message-State: ABuFfohPtAzvXaEApwk8vy+nWvR/PV4QZWw4o3YQmmyeCiaXO5UZ3FX8 qbwA3f50aqTymVaTatq+k0M= X-Google-Smtp-Source: ACcGV60Wv46/MYJhfWLjYTnKw+vP92HN4giuGWayXDZ+2rB6mkOnpa+h7cC8WZ2QmOqjPugW7Tkcfg== X-Received: by 2002:a62:c08b:: with SMTP id g11-v6mr8926427pfk.72.1539406523453; Fri, 12 Oct 2018 21:55:23 -0700 (PDT) Received: from localhost.localdomain (c-24-6-192-50.hsd1.ca.comcast.net. [24.6.192.50]) by smtp.gmail.com with ESMTPSA id h87-v6sm6959462pfj.78.2018.10.12.21.55.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Oct 2018 21:55:22 -0700 (PDT) From: frowand.list@gmail.com To: Rob Herring , Pantelis Antoniou , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Alan Tull , Moritz Fischer Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, devicetree@vger.kernel.org, linux-fpga@vger.kernel.org Subject: [PATCH v2 15/18] of: overlay: set node fields from properties when add new overlay node Date: Fri, 12 Oct 2018 21:53:35 -0700 Message-Id: <1539406418-18162-16-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1539406418-18162-1-git-send-email-frowand.list@gmail.com> References: <1539406418-18162-1-git-send-email-frowand.list@gmail.com> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Frank Rowand Overlay nodes added by add_changeset_node() do not have the node fields name, phandle, and type set. The node passed to __of_attach_node() when the add node changeset entry is processed does not contain any properties. The node's properties are located in add property changeset entries that will be processed after the add node changeset is applied. Set the node's fields in the node contained in the add node changeset entry and do not set them to incorrect values in add_changeset_node(). A visible symptom that is fixed by this patch is the names of nodes added by overlays that have an entry in /sys/bus/platform/drivers/*/ will contain the unit-address but the node-name will be , for example, "fc4ab000.". After applying the patch the name, in this example, for node restart@fc4ab000 is "fc4ab000.restart". Signed-off-by: Frank Rowand --- drivers/of/dynamic.c | 27 ++++++++++++++++++--------- drivers/of/overlay.c | 29 ++++++++++++++++++++++++----- 2 files changed, 42 insertions(+), 14 deletions(-) diff --git a/drivers/of/dynamic.c b/drivers/of/dynamic.c index 5f7c99b9de0d..5b740114dbdc 100644 --- a/drivers/of/dynamic.c +++ b/drivers/of/dynamic.c @@ -205,15 +205,24 @@ static void __of_attach_node(struct device_node *np) const __be32 *phandle; int sz; - np->name = __of_get_property(np, "name", NULL) ? : ""; - np->type = __of_get_property(np, "device_type", NULL) ? : ""; - - phandle = __of_get_property(np, "phandle", &sz); - if (!phandle) - phandle = __of_get_property(np, "linux,phandle", &sz); - if (IS_ENABLED(CONFIG_PPC_PSERIES) && !phandle) - phandle = __of_get_property(np, "ibm,phandle", &sz); - np->phandle = (phandle && (sz >= 4)) ? be32_to_cpup(phandle) : 0; + if (!of_node_check_flag(np, OF_OVERLAY)) { + np->name = __of_get_property(np, "name", NULL); + np->type = __of_get_property(np, "device_type", NULL); + if (!np->name) + np->name = ""; + if (!np->type) + np->type = ""; + + phandle = __of_get_property(np, "phandle", &sz); + if (!phandle) + phandle = __of_get_property(np, "linux,phandle", &sz); + if (IS_ENABLED(CONFIG_PPC_PSERIES) && !phandle) + phandle = __of_get_property(np, "ibm,phandle", &sz); + if (phandle && (sz >= 4)) + np->phandle = be32_to_cpup(phandle); + else + np->phandle = 0; + } np->child = NULL; np->sibling = np->parent->child; diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c index 41f56091663b..df808f73918e 100644 --- a/drivers/of/overlay.c +++ b/drivers/of/overlay.c @@ -307,10 +307,11 @@ static int add_changeset_property(struct overlay_changeset *ovcs, int ret = 0; bool check_for_non_overlay_node = false; - if (!of_prop_cmp(overlay_prop->name, "name") || - !of_prop_cmp(overlay_prop->name, "phandle") || - !of_prop_cmp(overlay_prop->name, "linux,phandle")) - return 0; + if (target->in_livetree) + if (!of_prop_cmp(overlay_prop->name, "name") || + !of_prop_cmp(overlay_prop->name, "phandle") || + !of_prop_cmp(overlay_prop->name, "linux,phandle")) + return 0; if (target->in_livetree) prop = of_find_property(target->np, overlay_prop->name, NULL); @@ -331,6 +332,10 @@ static int add_changeset_property(struct overlay_changeset *ovcs, if (!prop) { check_for_non_overlay_node = true; + if (!target->in_livetree) { + new_prop->next = target->np->deadprops; + target->np->deadprops = new_prop; + } ret = of_changeset_add_property(&ovcs->cset, target->np, new_prop); @@ -406,9 +411,10 @@ static int add_changeset_node(struct overlay_changeset *ovcs, struct target *target, struct device_node *node) { const char *node_kbasename; + const __be32 *phandle; struct device_node *tchild; struct target target_child; - int ret = 0; + int ret = 0, size; node_kbasename = kbasename(node->full_name); @@ -422,6 +428,19 @@ static int add_changeset_node(struct overlay_changeset *ovcs, return -ENOMEM; tchild->parent = target->np; + tchild->name = __of_get_property(node, "name", NULL); + tchild->type = __of_get_property(node, "device_type", NULL); + + if (!tchild->name) + tchild->name = ""; + if (!tchild->type) + tchild->type = ""; + + /* ignore obsolete "linux,phandle" */ + phandle = __of_get_property(node, "phandle", &size); + if (phandle && (size == 4)) + tchild->phandle = be32_to_cpup(phandle); + of_node_set_flag(tchild, OF_OVERLAY); ret = of_changeset_attach_node(&ovcs->cset, tchild); From patchwork Sat Oct 13 04:53:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Rowand X-Patchwork-Id: 983425 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="S3o6SlIa"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42XC7q2k3rz9vZs for ; Sat, 13 Oct 2018 15:55:35 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727245AbeJMMbJ (ORCPT ); Sat, 13 Oct 2018 08:31:09 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:45001 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727164AbeJMMbG (ORCPT ); Sat, 13 Oct 2018 08:31:06 -0400 Received: by mail-pf1-f196.google.com with SMTP id r9-v6so7148632pff.11; Fri, 12 Oct 2018 21:55:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=M4dGHNWK9yvMCplN74sEUY4ZcqWQ+poGeb6zjVC5TlY=; b=S3o6SlIagmxnHfGrZI34r2HygKejAau1DPnNDbTQCEXLsdkEHMURCgMKM2hiSXKucQ GPmURtlvC/py9Hvtwx82PdYeCK+1JhVRuCiasUOBgeBJam8O8/kHdDk+qZpNLFJ6qGgk 5RpSRHDuUyi6ebBOsmdfZdUQS4NYZCiUO2hucgejZIIu10fnOjOIIODj/ORaJnMuQcy2 96deMshDa1STmPN/f2GVNywsH2V9RTM32EG/SKy50NZ98vHB+WTp4dHwVC89dWjzlRO7 yHU+n828MdpsXCF2wt/uo0qdzDKQoCt0EUFSnXW4eN3o0NxANyd/a0ZiEfiI981ceyBy NZhA== 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=M4dGHNWK9yvMCplN74sEUY4ZcqWQ+poGeb6zjVC5TlY=; b=M//kWHewnTRQn9uuv4WQLgQrAjkoZ2CoWO2xDjmhK+G67gwggE7vclsdVuutrPBrp5 vSnY0EbnO1kxgwpkmGcvTjdZtz3sGLnmklfLeMCOnTEpxGrIPxyHGfw5mEELNwmoTTrw kaEusMLmTRW86y/dLR+mw1daGfZAiy9XLXu2RpybOifhYzgThppAHnIYnek6OzX2xTUG X5/34tssDdaw6oRomW6BQhulUwLrUOij7rBSw9eEM8tqGEveIrNLgMOOKDc/1Qq75rOh GhOWriatslnPqzpovBr6BZpKLL6F3IRwnCgPIHxzMaxHkkyy7fy0c3wYeVxLzbYFMM1b CckQ== X-Gm-Message-State: ABuFfogsZqka7J0Cm1nTU0zOQM5cmdahxYlYatTHsz3xQBn6Ie5jHHIS vqfnWXyIFcCofu2SamsIZk4= X-Google-Smtp-Source: ACcGV60vRUunZJMX+N8YwJwVcENXCI6zkkcPu3pWwg+A1ei+wf5ZAed2gu6okwiTBfo4Ne0KfSTbwg== X-Received: by 2002:a62:5ac6:: with SMTP id o189-v6mr9102764pfb.40.1539406524814; Fri, 12 Oct 2018 21:55:24 -0700 (PDT) Received: from localhost.localdomain (c-24-6-192-50.hsd1.ca.comcast.net. [24.6.192.50]) by smtp.gmail.com with ESMTPSA id h87-v6sm6959462pfj.78.2018.10.12.21.55.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Oct 2018 21:55:24 -0700 (PDT) From: frowand.list@gmail.com To: Rob Herring , Pantelis Antoniou , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Alan Tull , Moritz Fischer Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, devicetree@vger.kernel.org, linux-fpga@vger.kernel.org Subject: [PATCH v2 16/18] of: unittest: allow base devicetree to have symbol metadata Date: Fri, 12 Oct 2018 21:53:36 -0700 Message-Id: <1539406418-18162-17-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1539406418-18162-1-git-send-email-frowand.list@gmail.com> References: <1539406418-18162-1-git-send-email-frowand.list@gmail.com> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Frank Rowand The overlay metadata nodes in the FDT created from testcases.dts are not handled properly. The __fixups__ and __local_fixups__ node were added to the live devicetree, but should not be. Only the first property in the /__symbols__ node was added to the live devicetree if the live devicetree already contained a /__symbols node. All of the node's properties must be added. Signed-off-by: Frank Rowand --- drivers/of/unittest.c | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 6d80f474c8f2..1c2bd8503095 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -1057,20 +1057,44 @@ static void __init of_unittest_platform_populate(void) * of np into dup node (present in live tree) and * updates parent of children of np to dup. * - * @np: node already present in live tree + * @np: node whose properties are being added to the live tree * @dup: node present in live tree to be updated */ static void update_node_properties(struct device_node *np, struct device_node *dup) { struct property *prop; + struct property *save_next; struct device_node *child; - - for_each_property_of_node(np, prop) - of_add_property(dup, prop); + int ret; for_each_child_of_node(np, child) child->parent = dup; + + /* + * "unittest internal error: unable to add testdata property" + * + * If this message reports a property in node '/__symbols__' then + * the respective unittest overlay contains a label that has the + * same name as a label in the live devicetree. The label will + * be in the live devicetree only if the devicetree source was + * compiled with the '-@' option. If you encounter this error, + * please consider renaming __all__ of the labels in the unittest + * overlay dts files with an odd prefix that is unlikely to be + * used in a real devicetree. + */ + + /* + * open code for_each_property_of_node() because of_add_property() + * sets prop->next to NULL + */ + for (prop = np->properties; prop != NULL; prop = save_next) { + save_next = prop->next; + ret = of_add_property(dup, prop); + if (ret) + pr_err("unittest internal error: unable to add testdata property %pOF/%s", + np, prop->name); + } } /** @@ -1079,18 +1103,23 @@ static void update_node_properties(struct device_node *np, * * @np: Node to attach to live tree */ -static int attach_node_and_children(struct device_node *np) +static void attach_node_and_children(struct device_node *np) { struct device_node *next, *dup, *child; unsigned long flags; const char *full_name; full_name = kasprintf(GFP_KERNEL, "%pOF", np); + + if (!strcmp(full_name, "/__local_fixups__") || + !strcmp(full_name, "/__fixups__")) + return; + dup = of_find_node_by_path(full_name); kfree(full_name); if (dup) { update_node_properties(np, dup); - return 0; + return; } child = np->child; @@ -1111,8 +1140,6 @@ static int attach_node_and_children(struct device_node *np) attach_node_and_children(child); child = next; } - - return 0; } /** From patchwork Sat Oct 13 04:53:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Rowand X-Patchwork-Id: 983427 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="iqVjDp7q"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42XC833ZWkz9vZs for ; Sat, 13 Oct 2018 15:55:47 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727197AbeJMMbI (ORCPT ); Sat, 13 Oct 2018 08:31:08 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:36908 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727034AbeJMMbH (ORCPT ); Sat, 13 Oct 2018 08:31:07 -0400 Received: by mail-pf1-f194.google.com with SMTP id j23-v6so7155975pfi.4; Fri, 12 Oct 2018 21:55:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=VS64Bboo/cHvVCqyzYbNqD36WUkYJGIhe/8UN1uSi10=; b=iqVjDp7qSRCludwpzhZP+T2vAI8HXUGH5Z9VFN/X4D3GMsHivxJLSy2VErbzNb9hpA 6Cw1/VoT8y7Cvuvz+I0YCGphDsLaWbFGNzLdJgvui22gql3obyQOsLqEKB2TwgDquK1A dgMznPoWaz5NzpeYREodOyaJRopS6qCVWAuLJ+KzGJpwIQZWB4+zdPid97XrAkXI6qx6 7LHVawMRJwSFQSn+Ya2FaQNgcrUhvXmkx+j1ZZDnqYAGug1xzPUFg1wtnwR3QYT+TuSL +3Kdksst9QFm7W4Hf4JbZantLprYvW8qWONjBM0Ic3ETvimX0rP7s53aDT8C7HRJxSBG W8QA== 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=VS64Bboo/cHvVCqyzYbNqD36WUkYJGIhe/8UN1uSi10=; b=stqEPAgdl925nu3aKLyq3frFn8aG1GayfCX75SpYxZg7JKY6udMe+vxYWo/QVFKxvD X2u4tz1bg606Cd63g+umAU5ocvzYO9zt4LMPOwW+DsBhWw+tPutx9vrLu8KI6+CAijVJ FRZEH5NiRPgZ1IrFuUD134P0AXd3egNOExMaW4lJ7IEnZMBfkf2PkCjHRQ0dTYIbRMQ8 e1n32CTE/kgYytGFpYmrvaCJTsHMdX4c0O3qbNEQQBoDpICfdkGH9mdzzyn+eNKBLRX7 bzzq1BNUGK+iJB4aqjCLJKeTMAFp2sflA+fmAZSiB7U8VKzHkE7hFUbtmPBkILI5+e5c 79/Q== X-Gm-Message-State: ABuFfoh/sAS1cH+fbmfla0as9R5Zj+gym0PL9vE79o+ZucohXEzaksyb pul/aY4Y/V6eW8BAmURzaBM= X-Google-Smtp-Source: ACcGV62Bd6RAtLtKnP6cElZw5npSSURIJkel2eVB4JUXUPV5Htp+9aoA5iJdYKliJjPhQ23Yfztxbw== X-Received: by 2002:a62:1551:: with SMTP id 78-v6mr8879371pfv.178.1539406526080; Fri, 12 Oct 2018 21:55:26 -0700 (PDT) Received: from localhost.localdomain (c-24-6-192-50.hsd1.ca.comcast.net. [24.6.192.50]) by smtp.gmail.com with ESMTPSA id h87-v6sm6959462pfj.78.2018.10.12.21.55.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Oct 2018 21:55:25 -0700 (PDT) From: frowand.list@gmail.com To: Rob Herring , Pantelis Antoniou , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Alan Tull , Moritz Fischer Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, devicetree@vger.kernel.org, linux-fpga@vger.kernel.org Subject: [PATCH v2 17/18] of: unittest: find overlays[] entry by name instead of index Date: Fri, 12 Oct 2018 21:53:37 -0700 Message-Id: <1539406418-18162-18-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1539406418-18162-1-git-send-email-frowand.list@gmail.com> References: <1539406418-18162-1-git-send-email-frowand.list@gmail.com> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Frank Rowand One accessor of overlays[] was using a hard coded index value to find the correct array entry instead of searching for the entry containing the correct name. Signed-off-by: Frank Rowand --- drivers/of/unittest.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 1c2bd8503095..785985bdbfa6 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -2178,7 +2178,7 @@ struct overlay_info { OVERLAY_INFO_EXTERN(overlay_bad_phandle); OVERLAY_INFO_EXTERN(overlay_bad_symbol); -/* order of entries is hard-coded into users of overlays[] */ +/* entries found by name */ static struct overlay_info overlays[] = { OVERLAY_INFO(overlay_base, -9999), OVERLAY_INFO(overlay, 0), @@ -2201,7 +2201,8 @@ struct overlay_info { OVERLAY_INFO(overlay_bad_add_dup_prop, -EINVAL), OVERLAY_INFO(overlay_bad_phandle, -EINVAL), OVERLAY_INFO(overlay_bad_symbol, -EINVAL), - {} + /* end marker */ + {.dtb_begin = NULL, .dtb_end = NULL, .expected_result = 0, .name = NULL} }; static struct device_node *overlay_base_root; @@ -2231,6 +2232,19 @@ void __init unittest_unflatten_overlay_base(void) u32 data_size; void *new_fdt; u32 size; + int found = 0; + const char *overlay_name = "overlay_base"; + + for (info = overlays; info && info->name; info++) { + if (!strcmp(overlay_name, info->name)) { + found = 1; + break; + } + } + if (!found) { + pr_err("no overlay data for %s\n", overlay_name); + return; + } info = &overlays[0]; @@ -2278,11 +2292,10 @@ static int __init overlay_data_apply(const char *overlay_name, int *overlay_id) { struct overlay_info *info; int found = 0; - int k; int ret; u32 size; - for (k = 0, info = overlays; info && info->name; info++, k++) { + for (info = overlays; info && info->name; info++) { if (!strcmp(overlay_name, info->name)) { found = 1; break; From patchwork Sat Oct 13 04:53:38 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Rowand X-Patchwork-Id: 983426 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=devicetree-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="EBE0enLF"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 42XC7y6KNYz9vZs for ; Sat, 13 Oct 2018 15:55:42 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727300AbeJMMbT (ORCPT ); Sat, 13 Oct 2018 08:31:19 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:38627 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727195AbeJMMbI (ORCPT ); Sat, 13 Oct 2018 08:31:08 -0400 Received: by mail-pf1-f196.google.com with SMTP id f29-v6so7166015pff.5; Fri, 12 Oct 2018 21:55:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=c4g80DvyuudoX+LPD+xlMBYx8TzUWy649W9bh+/3Apk=; b=EBE0enLFfZS00Q4vrKlNiFa455XytYgOWZqS/oM4Ln9QGgwPT/7BO13cvxIOpS/czO jBq/WJJoqKV3FDKdOsuk2RKrPh+jn9AbcxrBExEQFwEmUYWtnFQzBNjFHGwMH2i9j4IH hgeVskYmNiL5O7ayDrweoVr0Jb5VkNBwJjzl3u6H1b1YmX1P5pfPs48SV8beLyvcj2ex ijwDIm7+ruP8bA/mMsmmuvhm8ci47KyEdW8pgrMw0nU1btPZ5u7hhl4ZK9qs2vRLHvsP /aJxslL8DLNitvpH45H/jpRAOpLsNufpKrsBMnxyLZfycpJ3s6vjTDZwNhCGz45bTq4L gJbA== 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=c4g80DvyuudoX+LPD+xlMBYx8TzUWy649W9bh+/3Apk=; b=A+RnhOEEYLjSWxqufAQ3gpfGmxhdHtIp4pRdH8LQ5Xro98dMY6OYX8N7mJLCwQACyZ /3dV1MLrBCvvnFWL2YZi01OKpJmLPb/gSw/xpieA1dOP/gj2t5oF1RDdHdndIyCls1P+ 0+LMB86Hw4t0YwNgKRgqjt5cEBcKU/ENzb+z/mdo3JAESQWdnb5PHuXRL1vyCRdfZxiX ewms19ca3EvlBWjXVY+Fx+5RTst/7TlgS4Yx1kyqXXxSW7BEDIqi1D181YLdOISPKfpq DXAXN+0pTrW794Y57nUFFRCj1ORhS8/8ulCU+qcuVt1kARdmR1mEUBmyV2V07Q/xm4aX r3hQ== X-Gm-Message-State: ABuFfoih6SAprG4bC8rfZPFIzdxECajB8Hg9F0kFN5ljNo4Xy7URch0c 6vSgihJX5kcIuwNpeErHMXQ= X-Google-Smtp-Source: ACcGV63+XntGfxxxUG3x6CDkSZ6opwjM9Ve/81S/R175COQs/W+AWHCB8Rw/XJ3wl4fLwlWDYNwnXA== X-Received: by 2002:a65:528b:: with SMTP id y11-v6mr8134116pgp.269.1539406527279; Fri, 12 Oct 2018 21:55:27 -0700 (PDT) Received: from localhost.localdomain (c-24-6-192-50.hsd1.ca.comcast.net. [24.6.192.50]) by smtp.gmail.com with ESMTPSA id h87-v6sm6959462pfj.78.2018.10.12.21.55.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Oct 2018 21:55:26 -0700 (PDT) From: frowand.list@gmail.com To: Rob Herring , Pantelis Antoniou , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Alan Tull , Moritz Fischer , Guenter Roeck Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, devicetree@vger.kernel.org, linux-fpga@vger.kernel.org Subject: [PATCH v2 18/18] of: unittest: initialize args before calling of_*parse_*() Date: Fri, 12 Oct 2018 21:53:38 -0700 Message-Id: <1539406418-18162-19-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1539406418-18162-1-git-send-email-frowand.list@gmail.com> References: <1539406418-18162-1-git-send-email-frowand.list@gmail.com> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Frank Rowand Callers of of_irq_parse_one() blindly use the pointer args.np without checking whether of_irq_parse_one() had an error and thus did not set the value of args.np. Initialize args to zero so that using the format "%pOF" to show the value of args.np will show "(null)" when of_irq_parse_one() has an error. This prevents the dereference of a random value. Make the same fix for callers of of_parse_phandle_with_args() and of_parse_phandle_with_args_map(). Reported-by: Guenter Roeck Signed-off-by: Frank Rowand --- changes since v1: - add same fix for of_parse_phandle_with_args() - add same fix for of_parse_phandle_with_args_map() drivers/of/unittest.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 785985bdbfa6..5f4db23e4752 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -375,6 +375,7 @@ static void __init of_unittest_parse_phandle_with_args(void) for (i = 0; i < 8; i++) { bool passed = true; + memset(&args, 0, sizeof(args)); rc = of_parse_phandle_with_args(np, "phandle-list", "#phandle-cells", i, &args); @@ -428,6 +429,7 @@ static void __init of_unittest_parse_phandle_with_args(void) } /* Check for missing list property */ + memset(&args, 0, sizeof(args)); rc = of_parse_phandle_with_args(np, "phandle-list-missing", "#phandle-cells", 0, &args); unittest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc); @@ -436,6 +438,7 @@ static void __init of_unittest_parse_phandle_with_args(void) unittest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc); /* Check for missing cells property */ + memset(&args, 0, sizeof(args)); rc = of_parse_phandle_with_args(np, "phandle-list", "#phandle-cells-missing", 0, &args); unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); @@ -444,6 +447,7 @@ static void __init of_unittest_parse_phandle_with_args(void) unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); /* Check for bad phandle in list */ + memset(&args, 0, sizeof(args)); rc = of_parse_phandle_with_args(np, "phandle-list-bad-phandle", "#phandle-cells", 0, &args); unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); @@ -452,6 +456,7 @@ static void __init of_unittest_parse_phandle_with_args(void) unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); /* Check for incorrectly formed argument list */ + memset(&args, 0, sizeof(args)); rc = of_parse_phandle_with_args(np, "phandle-list-bad-args", "#phandle-cells", 1, &args); unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); @@ -502,6 +507,7 @@ static void __init of_unittest_parse_phandle_with_args_map(void) for (i = 0; i < 8; i++) { bool passed = true; + memset(&args, 0, sizeof(args)); rc = of_parse_phandle_with_args_map(np, "phandle-list", "phandle", i, &args); @@ -559,21 +565,25 @@ static void __init of_unittest_parse_phandle_with_args_map(void) } /* Check for missing list property */ + memset(&args, 0, sizeof(args)); rc = of_parse_phandle_with_args_map(np, "phandle-list-missing", "phandle", 0, &args); unittest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc); /* Check for missing cells,map,mask property */ + memset(&args, 0, sizeof(args)); rc = of_parse_phandle_with_args_map(np, "phandle-list", "phandle-missing", 0, &args); unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); /* Check for bad phandle in list */ + memset(&args, 0, sizeof(args)); rc = of_parse_phandle_with_args_map(np, "phandle-list-bad-phandle", "phandle", 0, &args); unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); /* Check for incorrectly formed argument list */ + memset(&args, 0, sizeof(args)); rc = of_parse_phandle_with_args_map(np, "phandle-list-bad-args", "phandle", 1, &args); unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); @@ -780,7 +790,7 @@ static void __init of_unittest_parse_interrupts(void) for (i = 0; i < 4; i++) { bool passed = true; - args.args_count = 0; + memset(&args, 0, sizeof(args)); rc = of_irq_parse_one(np, i, &args); passed &= !rc; @@ -801,7 +811,7 @@ static void __init of_unittest_parse_interrupts(void) for (i = 0; i < 4; i++) { bool passed = true; - args.args_count = 0; + memset(&args, 0, sizeof(args)); rc = of_irq_parse_one(np, i, &args); /* Test the values from tests-phandle.dtsi */ @@ -854,6 +864,7 @@ static void __init of_unittest_parse_interrupts_extended(void) for (i = 0; i < 7; i++) { bool passed = true; + memset(&args, 0, sizeof(args)); rc = of_irq_parse_one(np, i, &args); /* Test the values from tests-phandle.dtsi */