From patchwork Fri Oct 5 04:12: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: 10627395 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9CD911731 for ; Fri, 5 Oct 2018 04:15:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C61B2954B for ; Fri, 5 Oct 2018 04:15:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 80B1D29551; Fri, 5 Oct 2018 04:15:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 112DE2954B for ; Fri, 5 Oct 2018 04:15:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727608AbeJELLF (ORCPT ); Fri, 5 Oct 2018 07:11:05 -0400 Received: from mail-pg1-f195.google.com ([209.85.215.195]:33156 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727036AbeJELLE (ORCPT ); Fri, 5 Oct 2018 07:11:04 -0400 Received: by mail-pg1-f195.google.com with SMTP id y18-v6so4148781pge.0; Thu, 04 Oct 2018 21:14: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=lPoDioj489a2/oR5DkZXnv7vgj2sX9AQIbb7kmBjERc=; b=BesHESeR2OkWfLm2eP+lH9kJfeYT3yZJjIVYrS+7g+Y1yN14yPrKCEPwZuZVpu4UQT Y2TU6UhnalnRt9tsYWlBrDmO7/zufQzIIc4VPr41i1xeX9HfD8c3+mVfxRT/G6+li04t /VkqmDVHI+DYo51NjkC5ExsmwFbd5XVwa27b6LqfQEu9/KExiY1IpqiqFMFx8+RfmTHo IEKBL1CBSPHehuYJUH6PLCdfyxxWkNBrLbbsHXf8v+nSn7i/AWHvTsCcNoXrzP1qK1yP UsUpzZgLCXLzzbtUldlNs1VmnTGGXTdqs7b0PtROqUoZhqTzJKRb1BI/kG+UEgUxPD7E 9zww== 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=Gly3HDGIbKXoowaqwkLEcFhvaV5HDCLxTlZTnYCP2gn8kroHQWNnMzaXzioEbaAqaL b7e9eFoz37KBdMC6Kc5IdA0uBXbdV5FHRYH8L99JnrUV3A+za0UveN2S7y2vfbqaKZAF I2cyl2rh6UAWBT7XJWtv8RsEI8qOodDAi/W/Xc7EscObZUH8L8NRirhpQ/hRtfb2O5ho 3GOBrAwNrmi9QvCn5caQhDcDXwFCHjDW9kr982K0B86PWQ2S9HyqGyyoAY+6ITwKqN2G C436PCoGJ7QgQjd14CnWV4KtnU/NtVHh38hDLWA14yUVvWTe+hwHD4T3VBaeOb3rbIoK LJgA== X-Gm-Message-State: ABuFfojasb5Att8WJkuLgfXtacMJKL0fnsivBkmDr7qFJ7rRTV79pxqy Bgq8Z6R2HNctR4vdgCVmDqth9lNT X-Google-Smtp-Source: ACcGV60qGtIYm4CVvnzhXTBVTS1/PXbbEd8WCXt28OLqSX+Q1tOOMyxTBi6zG/nI4jrXuTHLaNMZ1Q== X-Received: by 2002:a63:64c2:: with SMTP id y185-v6mr8320372pgb.411.1538712853292; Thu, 04 Oct 2018 21:14: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 n63-v6sm277975pfn.9.2018.10.04.21.14.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 Oct 2018 21:14: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 01/16] of: overlay: add tests to validate kfrees from overlay removal Date: Thu, 4 Oct 2018 21:12:32 -0700 Message-Id: <1538712767-30394-2-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1538712767-30394-1-git-send-email-frowand.list@gmail.com> References: <1538712767-30394-1-git-send-email-frowand.list@gmail.com> Sender: linux-fpga-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Fri Oct 5 04:12: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: 10627365 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B76AB1731 for ; Fri, 5 Oct 2018 04:14:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A67FA29546 for ; Fri, 5 Oct 2018 04:14:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 994212954C; Fri, 5 Oct 2018 04:14:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3B9DB29546 for ; Fri, 5 Oct 2018 04:14:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727047AbeJELLH (ORCPT ); Fri, 5 Oct 2018 07:11:07 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:40001 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727599AbeJELLG (ORCPT ); Fri, 5 Oct 2018 07:11:06 -0400 Received: by mail-pg1-f193.google.com with SMTP id n31-v6so4129597pgm.7; Thu, 04 Oct 2018 21:14:14 -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=MCBx9lrMtMdsz9cEW+CMd3QgO3hI+ZEPnUcsSEe7WFZdG+UobXlVKJOVX7ZGbYEIMT oa2rVq+Lo7V7wvGwBLZK/kdv+DC6yFUwC8QyN3E39GUtBX7bGj+itjAa8Dz41mTpTNOQ hy9O90b/jXdseEi+/FDQihD+OxzBjv6aAmt4MK12eclhqdEF1ZU+I2F0eU/GBHPzjjW9 zePCXjN7k2pxIYTz7N1y7CYw+BMWw3SYM3kDXV+Kf5OiWBkM62kY2T+61Qy1Hv6DvJEr 8aiC/7e4LHCg8b+r1VPawJzQTcU5mUfAdZHHfGM967yjFrOsQSpAJttv+nXyEmdAaj/z 2/1w== 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=aiMfHynKZofFPRXoiZGDiAfERK71hkY8gvx8iW+qegSZ4nwzdKHFoY7uQp+Ym9aOj+ hBHkUG5pHRbG46hp5i8PUFjGqFoJduze8or5Ne0RQEzoNu1C/vLL0QBFhLH2j6fpebbr BcHFqM0bImCHjBF7O5aSWgW5bL9fPQVtFl1UHP8Ej3lMqv1B97g9p4BBOPnexYHvjNDl Wx6M3h0qVjtM8j5mfn2vKfilBtoU7efDxSroadnxR2etIim2ykkyCYmdX06y0WIX6ae2 gLCO58uALQ4faANe3cRb916VBCrMn4BkLrOGCJQZcEeMnoQq7XKwddcvYhSQ0axk3jSm 2Sag== X-Gm-Message-State: ABuFfojtQEl9qXiFmMiOr9AmLi2OFw1k7SEV34k6OqoKFG/OmZI085rq m+hUEGvnl8+p+KpPE+9T+Nk= X-Google-Smtp-Source: ACcGV63m5HexPKfKLuGqqO0tFRNmbENYi3UjC/7hSN83HFe9jfdxDst5U1GMAGI6elYY4PSnNHIOKQ== X-Received: by 2002:a65:41c6:: with SMTP id b6-v6mr8617935pgq.421.1538712854589; Thu, 04 Oct 2018 21:14: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 n63-v6sm277975pfn.9.2018.10.04.21.14.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 Oct 2018 21:14: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 02/16] of: overlay: add missing of_node_put() after add new node to changeset Date: Thu, 4 Oct 2018 21:12:33 -0700 Message-Id: <1538712767-30394-3-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1538712767-30394-1-git-send-email-frowand.list@gmail.com> References: <1538712767-30394-1-git-send-email-frowand.list@gmail.com> Sender: linux-fpga-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Fri Oct 5 04:12: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: 10627393 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 272DE1731 for ; Fri, 5 Oct 2018 04:15:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 16B0729546 for ; Fri, 5 Oct 2018 04:15:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0ABBB2954C; Fri, 5 Oct 2018 04:15:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F2D0229546 for ; Fri, 5 Oct 2018 04:15:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727980AbeJELMd (ORCPT ); Fri, 5 Oct 2018 07:12:33 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:36152 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727036AbeJELLG (ORCPT ); Fri, 5 Oct 2018 07:11:06 -0400 Received: by mail-pl1-f193.google.com with SMTP id y11-v6so3043030plt.3; Thu, 04 Oct 2018 21:14: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=XMDnNdUW/sDd17o9F9TmJbiIxv65t1vRquMBQw128TM=; b=FWijAGp6UNxBHqBzov0/qbX2B/wvdSAZrUN0u/24mwyFoVqvS6E3w6ECjRtCldkNBx VjfCXEhuUL1ZYRfX3vFKR8KCpcNATiZE6tj7BsK3/jm651cYEMLN2zAHwDFRr9fUPTC7 VfcX6rMEktI6fjjqQniXGoGydN5ZmGb1xZVW2h4ymbrsoihJrBjoCsnEtFvd7mA+/D6M YhiVjmS9NmjLYTo70iEkEMUTbt5/ojx/Y7r3L0I4lufS9WA0SIdb6ox/fEIlzq8VhaAx F1YTJpxZNpQ9zb2bjIueeZmARE3uf91XicaLRsXJ5xoBdCt7gsmyiVqrvRw4/RZb7e+M vQEw== 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=nqOeIT10068XUTajtzj2sz9s7pOsFxeYnTYE+ekEwJgUpPUAF2OhZpVGor5zvjrbLW fxfC+qmoubehvozpIY05m2J/Lz92ykqwGJWL16YCO5NOoJb2TB2W6x2iZ2SEwf8ydP6j 2FgulFPZzmt90CVwBY5sC1/9QAuFmC4G/BjGO2BbQ9CJzWJeCUCcZe+7FdUlqpVFPS72 +PsU7eln5CVUaDMEm6QPebEtmblkYRaXq/JB8cfNz6xpKJWBE41T6KF9114BE8rENtI2 UD+JB/q+qToiVNNRt01mkfQMARZr56DD0KtHMoqMhRtwyZXxis+Vj3gVWSi4dyYuS+Ww lhjA== X-Gm-Message-State: ABuFfoikzaU1Az+lh8vEYRxfxpAKkD6v25wbzTwFIYUvy5cSjmUVIl0C ACm/14azLxCW1AjpzMY44OM= X-Google-Smtp-Source: ACcGV62FRy9PwqCLrqEV60+HHZ3O1e1z0Ny95+n/XrtRw1XEZSWFfXnts+GaZzMFvQ4CWZaGDvB2eQ== X-Received: by 2002:a17:902:9893:: with SMTP id s19-v6mr9579926plp.130.1538712855820; Thu, 04 Oct 2018 21:14:15 -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 n63-v6sm277975pfn.9.2018.10.04.21.14.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 Oct 2018 21:14: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 03/16] of: overlay: add missing of_node_get() in __of_attach_node_sysfs Date: Thu, 4 Oct 2018 21:12:34 -0700 Message-Id: <1538712767-30394-4-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1538712767-30394-1-git-send-email-frowand.list@gmail.com> References: <1538712767-30394-1-git-send-email-frowand.list@gmail.com> Sender: linux-fpga-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Fri Oct 5 04:12: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: 10627391 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DE8371515 for ; Fri, 5 Oct 2018 04:15:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CF12829546 for ; Fri, 5 Oct 2018 04:15:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C2DDA2954C; Fri, 5 Oct 2018 04:15:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 739422954B for ; Fri, 5 Oct 2018 04:15:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727690AbeJELLJ (ORCPT ); Fri, 5 Oct 2018 07:11:09 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:36259 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727599AbeJELLI (ORCPT ); Fri, 5 Oct 2018 07:11:08 -0400 Received: by mail-pg1-f193.google.com with SMTP id f18-v6so4143846pgv.3; Thu, 04 Oct 2018 21:14: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=CCjwtqQtCAOwIXfabE6A59py+g67jCSp+upDI4OtmXg=; b=aB/pc7f8FxZc7uvWjU1rnHCfgnfN0z8C3vWsTvXR9xDr0ZaXu3l+aKzPSrD4J/PtBZ g6Nuvdx+FJHvQzlFn43EqB/Z0MzHmEKcv1sd7dlaF3rQKM0RC8DzbbXZ7AYmPTj0YgP7 JaNzyAfaTGpL3cArYhv5Hh70vUMvjcEmFJ84jyhunUzqBjEFYxl6x84NDxj7okW3QMqC YeTjxPW8riexKDFWU3ZxE+A+p0Xfw+CoXkCmw+TbQsh7MqEXC4l5jCGSIC+Ldz5whgSA Yt2TKSKwgjN0TIYIlZPyDhu4d4r4EkSPrEFm8W/G3FlffIMGXsztEQkdK2uW60nMD21l HzeA== 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=CCjwtqQtCAOwIXfabE6A59py+g67jCSp+upDI4OtmXg=; b=pf0K7/0B4FRTkRjJbey/XkZeO63U6OYcr31EvAd0kL1iEU+DpC6N2MUeby8MglynDd 9BvVky8F7rmonMVh54lfYtGFiI2/+2jLnd1/WrEnH8Y59y0TX4meNqpVD4hvHvXmwfCr AEhA/aT5JPH/a4H8P456MC6ca1pYdfIFRIOBgH7HMC93nRlD5kwbT8UfgaZ0xp0Uzr9o v9NyLaAhgAGi3gwUqZWjDWhkniADfQZcyKcId7zjDD14EkxBmEDHfAW3CE+oH+REiW3s zxP1bYPdzEELCqF9z41U1+lhhDqVdQylhoVNdXqXImeHXAKghTYKfdsPBXYGCK97Xh8T cJtg== X-Gm-Message-State: ABuFfogQaIgJobBafBEuYgMe++uQONxZkOv288fW7DBwc5kz6y0TVCN6 8bOZG7+LR2+/fD2QEj4pZGxUpdNJ X-Google-Smtp-Source: ACcGV61470fq1TFoZi6jkEm12Z57jOx/YB0UTtMISFtSwg/fGVSHpMljSvPiU4o8Onwg3riTLIACxg== X-Received: by 2002:a63:6203:: with SMTP id w3-v6mr8425138pgb.53.1538712857052; Thu, 04 Oct 2018 21:14: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 n63-v6sm277975pfn.9.2018.10.04.21.14.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 Oct 2018 21:14: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 04/16] powerpc/pseries: add of_node_put() in dlpar_detach_node() Date: Thu, 4 Oct 2018 21:12:35 -0700 Message-Id: <1538712767-30394-5-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1538712767-30394-1-git-send-email-frowand.list@gmail.com> References: <1538712767-30394-1-git-send-email-frowand.list@gmail.com> Sender: linux-fpga-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Frank Rowand "of: overlay: add missing of_node_get() in __of_attach_node_sysfs" added a missing of_node_get() to __of_attach_node_sysfs(). This results in a refcount imbalance for nodes attached with dlpar_attach_node(). The calling sequence from dlpar_attach_node() to __of_attach_node_sysfs() is: dlpar_attach_node() of_attach_node() __of_attach_node_sysfs() Signed-off-by: Frank Rowand --- ***** UNTESTED. I need people with the affected PowerPC systems ***** (systems that dynamically allocate and deallocate ***** devicetree nodes) to test this patch. arch/powerpc/platforms/pseries/dlpar.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/powerpc/platforms/pseries/dlpar.c b/arch/powerpc/platforms/pseries/dlpar.c index a0b20c03f078..e3010b14aea5 100644 --- a/arch/powerpc/platforms/pseries/dlpar.c +++ b/arch/powerpc/platforms/pseries/dlpar.c @@ -272,6 +272,8 @@ int dlpar_detach_node(struct device_node *dn) if (rc) return rc; + of_node_put(dn); + return 0; } From patchwork Fri Oct 5 04:12: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: 10627389 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EB1341731 for ; Fri, 5 Oct 2018 04:15:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D87C629546 for ; Fri, 5 Oct 2018 04:15:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CC00A2954C; Fri, 5 Oct 2018 04:15:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E697729546 for ; Fri, 5 Oct 2018 04:15:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727803AbeJELMU (ORCPT ); Fri, 5 Oct 2018 07:12:20 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:46089 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727653AbeJELLJ (ORCPT ); Fri, 5 Oct 2018 07:11:09 -0400 Received: by mail-pg1-f193.google.com with SMTP id a5-v6so4109790pgv.13; Thu, 04 Oct 2018 21:14: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=0710V2isUTAp0B57FjDvvIC154//Eemc4BzI1k4BjDY=; b=nreav5XXBZ39xCeo+7gHeDdOlmDcMNuY8+mMXztJvt3bcfT94WvF5rrk6wiFdW2RUk f+5NaDHl8g9yt5KVuJq21gEZuEBNmcTk3Hfr0xjOR2yIdbB8/e8bzKDSE3Bw+pZj5CYx YSC3IqC7CfD1rfW3Zdiwe9h4yp6yHVZT+6OnMvp+S+DHygEYAq6sPoZY9Gbaw0iONSgH XeRjjoghF9+ih/udy+NmpNtc/OWpxafkkgaGNJrMEjc+I5vdGeO9JmzxVZr7QkTwOx0n mKNX5iz3OXOJsUYPc/NhzbEqW8Syjw1CEDU2/nVsytLugc669PfeIInhXLwZ6ycs0HJZ QHcQ== 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=0710V2isUTAp0B57FjDvvIC154//Eemc4BzI1k4BjDY=; b=X5gZNM67eC46CLP/owRvsio60bE/5fLYzD3Z5hOE9xjOCOsG/fVu8SiI3K5/UPhtQC l90v503t6MoWxWqsCQ4zseKVnRij3FFvg9/xHOFoIwu62uICmu5aAJAAYjBLBkf/Nvdu cv3M3qruxDKuYGX4az638r6GVBdSKQu3W7SrBgit2PPjGNctzMJ1nSrhoCXLcvTpWlNX HO3Zk0u6mUPtQ6UUZWaoWk1xXh1iKsaJMo7XhssZF8EG70q/l2rBg6bu2THBzjrFh247 mgzEhWTf/qKxQHnntcKkxn2dmE6dbvmZvBE/1bghqKS3NR5Ppxqr9TWYbyoytOffA3Fr xOmw== X-Gm-Message-State: ABuFfojTFVTv8r7CSqgo4wTjNIRdA6rXmvl5qWRTtIOEqqjpmTOFrb3Z 4ALwYVmAJWjbqLZLXsZzCrc= X-Google-Smtp-Source: ACcGV60P0SfITnKITg9+GJTTwfvEXaRfVovWQ0+g6bDgFxsCPA/TsA7aTgfNY3wumyKOJ06+BN4+nQ== X-Received: by 2002:a63:1520:: with SMTP id v32-v6mr4184841pgl.150.1538712858270; Thu, 04 Oct 2018 21:14: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 n63-v6sm277975pfn.9.2018.10.04.21.14.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 Oct 2018 21:14:17 -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 05/16] of: overlay: use prop add changeset entry for property in new nodes Date: Thu, 4 Oct 2018 21:12:36 -0700 Message-Id: <1538712767-30394-6-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1538712767-30394-1-git-send-email-frowand.list@gmail.com> References: <1538712767-30394-1-git-send-email-frowand.list@gmail.com> Sender: linux-fpga-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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..0b0904f44bc7 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 @overlay_prop 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 Fri Oct 5 04:12: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: 10627387 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5D69A1731 for ; Fri, 5 Oct 2018 04:15:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4A39929546 for ; Fri, 5 Oct 2018 04:15:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3E8B02954C; Fri, 5 Oct 2018 04:15:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E693429546 for ; Fri, 5 Oct 2018 04:15:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727735AbeJELLL (ORCPT ); Fri, 5 Oct 2018 07:11:11 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:37729 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727599AbeJELLK (ORCPT ); Fri, 5 Oct 2018 07:11:10 -0400 Received: by mail-pg1-f193.google.com with SMTP id c10-v6so4139188pgq.4; Thu, 04 Oct 2018 21:14:19 -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=TSvuFcg8dSVKckHCq64beWOdH/WxX+9HQwnn/E0dljs=; b=Txvvydwn/k63hOxYlZwYdwaQIAjsth2Jaw4zbDNdTvqPzUBK/bEWuzmAxECzPr/rYB 5ee7eBaNw1FbEYKkJ4M/WHi1t1nNCDk5vVrtbTuzDmVpBWywMHZMCbtMkyDjKD+IEShv Fshm8YpT/NObVTDG3rnXVe9X1gblxeezdCDtpJNZ6XLbQc01eR7O2FLjyBGIcN4G6a+V WHIFJ4Mp/4B0eZ2NxalIRlvpGQaQx8112Pd0FQJX3TymYYILDXlRQ1T4QgysP/e8XVsX dikNHoa/BUjMAwOGD35MjuM2ynoK/ZjKzfpqn+GqHfMZZUmhddS/DuBQPxc4FUro5AW8 rA3A== 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=TSvuFcg8dSVKckHCq64beWOdH/WxX+9HQwnn/E0dljs=; b=SuZgAzny+5lna4E2tbMo68bcvWM6rMw4s+n5tBBOOH/4t7VQjjmE/2ajjpdyS7tsYw IA07TR8bFLGT+RCir4Fb9FEOaeyKAyO6N8zwfx6xSd6ehRgiOAOJA6XgTkp58nUBdtum l6l1LxSyRxzHzMrNevZhiasCwu1IMh2QoNs+bSgOpp+QVGYfpKHayjAbiPUd60CK4/5x ZXFt6MtBEptInqFPEQG/gAVSvZrIV4sijoQvYd2oPieeUQBc863jQFH4LcfqiRhRNjsD TU0qL7UZZJPk9T+rc8FiC80HM1yIzJqme7EQ/nBvHg+ygn52bOl8NlDKuFbAgPf4Fk+c wAxA== X-Gm-Message-State: ABuFfogUqeeLfEgJOWHAHoHOgPj6m6JuCFu9K7c9iM+sMAselSgIV1uv mS10ci9Le9BVqad9G2Z2KI0= X-Google-Smtp-Source: ACcGV60Nq66DYWpjLNnNkOqwngvmQOK1t9t7z+KD3D9MvbeI/Z+r0dGjkV540jzK0as9aN/rEEhBDw== X-Received: by 2002:a63:eb07:: with SMTP id t7-v6mr8409158pgh.441.1538712859586; Thu, 04 Oct 2018 21:14: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 n63-v6sm277975pfn.9.2018.10.04.21.14.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 Oct 2018 21:14: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 06/16] of: overlay: do not duplicate properties from overlay for new nodes Date: Thu, 4 Oct 2018 21:12:37 -0700 Message-Id: <1538712767-30394-7-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1538712767-30394-1-git-send-email-frowand.list@gmail.com> References: <1538712767-30394-1-git-send-email-frowand.list@gmail.com> Sender: linux-fpga-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 0b0904f44bc7..c113186e222c 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 Fri Oct 5 04:12: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: 10627385 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3333A1515 for ; Fri, 5 Oct 2018 04:15:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 22AC929546 for ; Fri, 5 Oct 2018 04:15:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 172932954C; Fri, 5 Oct 2018 04:15:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A0D8F29546 for ; Fri, 5 Oct 2018 04:15:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727185AbeJELLN (ORCPT ); Fri, 5 Oct 2018 07:11:13 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:33166 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727599AbeJELLM (ORCPT ); Fri, 5 Oct 2018 07:11:12 -0400 Received: by mail-pg1-f196.google.com with SMTP id y18-v6so4148925pge.0; Thu, 04 Oct 2018 21:14: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=13Uv0Hfs4/ntC09BePszlnDUCQa1RtKNfNFOAls9wrk=; b=pmV+gvcJHSf4YdFmb92Ae64KwhXyt69qdjDo4jjS7f/jRx2+TuHqAXlF2P4BKbgmhV 4zvkKkKyd9oG0oPLdwgdPs+osUOJ4YmQXGl2gLumNo6dJz8DXx1s6xmqs2dxgbNZcmUJ seiNeQF82aP3xOMjQd4XZ7x+V81qx11mYo3B6JMIjam9bV5xvlEOWEM1KKATKOKNoetr vL7jMimXHO3BRxYDU1FBrkTGDMfuNjzO4O2wcPUHTAEdYUgus552cWctk+9dDbt5phzf 121j2gAJpJBLwTAngBe8qKTYR1Dd9XE8cPXSpZaXeZoZqM5gfNOMjcx0lLAWVWdt/5gv JvxA== 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=13Uv0Hfs4/ntC09BePszlnDUCQa1RtKNfNFOAls9wrk=; b=q/mqeBE1TGSMxzX+c82mF05XxPAlBDWVOmmWWDzPz0avEiDzuO8BMwADCU+kdLSfCC bOX9Pe1sgAwyDLEpddRV8oMQmFWSWHxBf1ojG3vuQ3vaT9SCRqDa0uDl9WcTBAOQqa8q zNscVRuO6fUlKbh155sICuDYhupovDCAMZJ0cKX6+F6NXxNN08eY4DE8E0KM7ZfF1RBR MIDonTfBjro1V4l7m5FtWberit0DmkFcrbLkmDMR4/tdomusiIvX4jcFqz4kRSyg2HDA qKnh/I1SGVc/QTGVNJGEtt+RmGMtAzyMDYq29NHJur7EM8ThUDJUS/5Kz2RhQHcrNhox kD+Q== X-Gm-Message-State: ABuFfoiovDNVStMXNQ6Emd/X0eXXlzwvZ+X/tvswEYA/7nRnzgiI70YO 07l9AfaVAowvK4dLF/LcDos= X-Google-Smtp-Source: ACcGV62d20VGbvyyroQzD8oc2KRAGrFicGuw2UjeVMoMttmoKedSCFn87aoeREyJ+rBo8d27k/6ECg== X-Received: by 2002:a63:e645:: with SMTP id p5-v6mr8145953pgj.218.1538712860977; Thu, 04 Oct 2018 21:14:20 -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 n63-v6sm277975pfn.9.2018.10.04.21.14.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 Oct 2018 21:14: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 07/16] of: dynamic: change type of of_{at,de}tach_node() to void Date: Thu, 4 Oct 2018 21:12:38 -0700 Message-Id: <1538712767-30394-8-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1538712767-30394-1-git-send-email-frowand.list@gmail.com> References: <1538712767-30394-1-git-send-email-frowand.list@gmail.com> Sender: linux-fpga-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- Powerpc files not tested 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 Fri Oct 5 04:12:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Rowand X-Patchwork-Id: 10627383 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 020821515 for ; Fri, 5 Oct 2018 04:15:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E641029546 for ; Fri, 5 Oct 2018 04:15:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DA1132954C; Fri, 5 Oct 2018 04:15:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 87A8E29546 for ; Fri, 5 Oct 2018 04:15:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727809AbeJELLQ (ORCPT ); Fri, 5 Oct 2018 07:11:16 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:39652 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726894AbeJELLN (ORCPT ); Fri, 5 Oct 2018 07:11:13 -0400 Received: by mail-pl1-f195.google.com with SMTP id w14-v6so6191473plp.6; Thu, 04 Oct 2018 21:14: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=aHk2/msirjmyKqS+4FgQGJlEqHm8O56cobU/W37vLhc=; b=WPHDFL1AZ4qHSKkELUE2W1LvCrnK6Pxi8/u4Gxz7KiTGTf2de0QmdT8Dpjo90P2m50 tBLYvaNIeDrkpCXs5dSvLOloAqmcZJyfUNsU+wtkKNStmHC/lmU5rGpSPeOUWshkGI4U 3DIoYXkLaRQI6NpX+4XS3alki+OyGC+MXy2YJ9QpsYnZknlzAu75STLnCPs76y3je3YB csaYIytF5bx1OxdE/uIl0V1v5FhuVPH5qN3legSD4bV7qal8t0e+R9kw23xhoI1VrgHr rTCD6MSXx02IxTgsB8no6OvCzU1aJ2KJWbapwUBCkUR2Sg/gUBN8VzEOTqiRWP0FWlyz 1BnA== 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=aHk2/msirjmyKqS+4FgQGJlEqHm8O56cobU/W37vLhc=; b=L4VwSEig/AiPoZTeMKLNZKSVf6T+d308IxMivXioEdSCzdHWUNC2Emtr/AkHp9oNrX YTy+Vsbqdxxgy+TB08jFkImNqNUxWbAEUk7yedZufzzK3oCfQLZG1Tusi8oXxTm59f07 ObZZTIoR34MVgyhNnE35YwArKNXh7AAX68CU6r1yUhyBGqvqVPWLnfGHfk+b4qoS0Kas Ya1JpgtARrDgHtCE6tpk/J0WoDstBHTkZuh6QrtqFN6SGpPiItj0n+7bz0VuaGyL6Mpi WyI1k9sXXZax5RNpYDjCqRXrjnikPhklbvoUgchPYTyeV+9OxJzGY60lf8QRY7t7TZ6C AHtg== X-Gm-Message-State: ABuFfoj+B7b7uFZsFvbcOv6RyBYUdghVF9U5K0swA61AJKsa6S9Feelb B05qYfzo1XH1onUcVtAGUYPiMOX0 X-Google-Smtp-Source: ACcGV630SMvEEH91kwNT67O2vqkxPbPUjcKTqO0n6Bwy5xOdSqnPdJwHrDaByoBnEzLWOL/j30P/3w== X-Received: by 2002:a17:902:8644:: with SMTP id y4-v6mr9699660plt.48.1538712862216; Thu, 04 Oct 2018 21:14: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 n63-v6sm277975pfn.9.2018.10.04.21.14.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 Oct 2018 21:14: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 08/16] of: overlay: reorder fields in struct fragment Date: Thu, 4 Oct 2018 21:12:39 -0700 Message-Id: <1538712767-30394-9-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1538712767-30394-1-git-send-email-frowand.list@gmail.com> References: <1538712767-30394-1-git-send-email-frowand.list@gmail.com> Sender: linux-fpga-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 c113186e222c..29c33a5c533f 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 Fri Oct 5 04:12:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Rowand X-Patchwork-Id: 10627367 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 86BD115A6 for ; Fri, 5 Oct 2018 04:14:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7712929546 for ; Fri, 5 Oct 2018 04:14:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6ABCA29551; Fri, 5 Oct 2018 04:14:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E58C629546 for ; Fri, 5 Oct 2018 04:14:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727803AbeJELLQ (ORCPT ); Fri, 5 Oct 2018 07:11:16 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:38758 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727599AbeJELLO (ORCPT ); Fri, 5 Oct 2018 07:11:14 -0400 Received: by mail-pf1-f194.google.com with SMTP id f29-v6so1571072pff.5; Thu, 04 Oct 2018 21:14: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=x6RsE6B32jH9hlMthMfkJbAudeY/LWQ22o5761C0YKc=; b=Z/1SuIMsHvY4P/Wvq52yu6Tpz5748wuGfzI52GSTUidtdi6hgpVk+DFRGKvL0E5YO8 ojh4CpNk7A78xTPfQlqN3JIcQmzyvLBFn1KXpTuDrkF01NObrutwWejYXWfQgrO89JEo JPlxXLo0/Lp1IOgMtQ8KIeGa0lOZaPJUZyLTeFANuWL53JIqHrXGEXSW+Mnn3Vgx54/t wCt3Q4MGac8CHLt+dnMex21rhXpz/ZzK51w270PEKVGLYCsQ9TEvRRim/2UknR4dsm+v X//COZ1jj/xrHzV+HJUnoP9Bv3SH6zP1odpipg37FW4yK3fMx8bBWPS7zDJ+bRAJuAAK xXjA== 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=x6RsE6B32jH9hlMthMfkJbAudeY/LWQ22o5761C0YKc=; b=fc8jA/qauI1YNLe4bnLhJKbYDH58IYUzCzzzUta+8U+OsTCwM7jDHrzN9r6j1B88/M lXNtFcijk8KPhdpC7UAYK8ZXm/Pzi59752VC3aOOOQjRaSfu4d0nW/uB+jncZ6ltefuZ FWgtQ0BlIQxTqlv7xAvdRQI+nQ0t6+Hd2KDjqZbNByrZo0JTRrsLnGdJ7qwmNf37t1Sz cCt1HjK875pveiJPN0OlNzHPE+YyY31TiusHpKsgtVhEUpJpTSHLNFrp7D4lgrQpvF2s SYGgFX4qGOvUSajZePQ1Hyr4vJAGnBZHXAjKkcGWnNiCr0oaB5mbVUN6Z/tb7ltc1Hv9 qECg== X-Gm-Message-State: ABuFfohWobjXl22ppjEyyRJOxNzGjxuu2KR+vmw4C44/j9NCRzlgA2AD 3xGFXU55Q4PEO0zQHzaXmi8= X-Google-Smtp-Source: ACcGV62SjcOJ/wWZO7AFf9ddQELGCShXDeQYJYde7dA5KVJqhTByjWpNjfn4Db9kYb1ESDjqlI07kA== X-Received: by 2002:a62:4ec9:: with SMTP id c192-v6mr9873713pfb.221.1538712863474; Thu, 04 Oct 2018 21:14: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 n63-v6sm277975pfn.9.2018.10.04.21.14.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 Oct 2018 21:14: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 09/16] of: overlay: validate overlay properties #address-cells and #size-cells Date: Thu, 4 Oct 2018 21:12:40 -0700 Message-Id: <1538712767-30394-10-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1538712767-30394-1-git-send-email-frowand.list@gmail.com> References: <1538712767-30394-1-git-send-email-frowand.list@gmail.com> Sender: linux-fpga-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 29c33a5c533f..e6fb3ffe9d93 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 Fri Oct 5 04:12:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Rowand X-Patchwork-Id: 10627369 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C1E561731 for ; Fri, 5 Oct 2018 04:14:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B0C0529546 for ; Fri, 5 Oct 2018 04:14:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A4E3D2954C; Fri, 5 Oct 2018 04:14:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4984A2954B for ; Fri, 5 Oct 2018 04:14:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727599AbeJELLR (ORCPT ); Fri, 5 Oct 2018 07:11:17 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:46242 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727802AbeJELLQ (ORCPT ); Fri, 5 Oct 2018 07:11:16 -0400 Received: by mail-pf1-f194.google.com with SMTP id r64-v6so4408157pfb.13; Thu, 04 Oct 2018 21:14:24 -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=CpxCZytTE2DMCbEh/CJMp/oXOlBJtuApwHXbU+m9rIM=; b=bzTluJeC/Tmbyz4ERw1iVHsYT8vdIdsZoU6Lpdmg0uJmxQ+mzOXuMhZj8PKrSpRMuA qGlt7DeoV6k4xW2CfE9DkiMVKseaAx2Oy0lnwLetYxnpxxqjuWazNovCZn3Wrp/3nC64 H4sYwh66s9070KUJMi2Iaun6XsvhtWE1WHXXNWLyu5MgDkmWb4g8sUYr70qZrQEhBGFd yqAS3M7p1fERdirBM4Ct0LIARet26yKDMxhrJjNUXVVSIRofQOffseBiweV3X9JH5jKJ xeUlLMWLzb6h0o1DZb/+mXGwVQDQmb5OY2XJ18H8O+R/N5qQT9sTLl/cmc2MQ5u5eKp3 OY3w== 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=CpxCZytTE2DMCbEh/CJMp/oXOlBJtuApwHXbU+m9rIM=; b=KZCr9eZSckHNe+EcRAE1AQS1dIeTiw5Zx80gOVsfQHmbh8DRG9guMua7omkXB3ZUrI r5HUaM0Cd6G42nn1aTWxNV9UHyw2DJdcB8XmXORRnc7SsTBauM9rNKXP7MhBX6X4kO2y fY/UuLCdjuNNjvBWTV/tThYs2p0GMSnrnryjBDxPD7drIBxHrg0q3EOzIyuK7a8yhoKS YKLO7rkxV7IsVBt2NzGB1+gFSZ64Ac5EPRxxWNvoV4QQ3YyiKHYIS5rHqyoTD3zG/Lbn et3sWq03kT/VQLPHULVx2Z7FoyDO2rCtOKxrwTgEoVGBIyYbKB0eZJgPE8l1OETb8S/g KeDQ== X-Gm-Message-State: ABuFfoi8Yy24xYYnN+rvysIlxNe9PF5MeqxzLsYS+O/h1lNr3bdysgwf mC8fHLVtrFIbCodIqn5/FAY= X-Google-Smtp-Source: ACcGV60XDvqIPx+3U41poUeNqK5p8QfF/qqKJ7ruL10hXJmIq3qiAHQ1HUQ+5E6K57ZDMhbs4aCsww== X-Received: by 2002:a63:2483:: with SMTP id k125-v6mr8451738pgk.287.1538712864682; Thu, 04 Oct 2018 21:14: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 n63-v6sm277975pfn.9.2018.10.04.21.14.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 Oct 2018 21:14: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 10/16] of: overlay: make all pr_debug() and pr_err() messages unique Date: Thu, 4 Oct 2018 21:12:41 -0700 Message-Id: <1538712767-30394-11-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1538712767-30394-1-git-send-email-frowand.list@gmail.com> References: <1538712767-30394-1-git-send-email-frowand.list@gmail.com> Sender: linux-fpga-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 e6fb3ffe9d93..f89383331b88 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 Fri Oct 5 04:12:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Rowand X-Patchwork-Id: 10627381 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6C6C31515 for ; Fri, 5 Oct 2018 04:15:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5A94E29546 for ; Fri, 5 Oct 2018 04:15:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4E55B2954C; Fri, 5 Oct 2018 04:15:15 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD5F029546 for ; Fri, 5 Oct 2018 04:15:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727047AbeJELL6 (ORCPT ); Fri, 5 Oct 2018 07:11:58 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:32811 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727804AbeJELLR (ORCPT ); Fri, 5 Oct 2018 07:11:17 -0400 Received: by mail-pf1-f194.google.com with SMTP id d4-v6so4449306pfn.0; Thu, 04 Oct 2018 21:14: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=1eIq+bpAJjW92EtiaqYATBx5CfeVYNbB6/35CF3TsEg=; b=VD1oZyd6nZR5s6eoeZziT7Q/Ua+T8neq0Su8P0DImQMz3a+/1O63Jk034001UHACeV IHbJnfBq58HIHGH7UOFxisD8zJ8H4v+VgTVzR1bTCSyxOwg3LWrfu9LNEmJuBdri1ET4 NH88d9H7ORpxIp6fuxYKIll13miXNBuMiTm6pVyJJ6qWaPzG0p7pc52Vp8Y8aPh/1qYr VYVjjueaaer0maZGtBNiEZmc/yhnch2bud6Dld9CcNbN7mDi1wS2T4iCtV+2wu2VgE4/ LZLhPkmOWKUoVThhgRAq/VKZraeu0xaTDkpyEc+frBQQF1h9YBgS85hW//IUfThe71WK 0ahg== 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=ju13LHTyeJgA9tz9oXpzL7IM3sv1IwBV6Dwv1DrdJRaiXrvvxJwAdf61vA5paM3he6 EM3Sf18N8sZfUZIULmb5LcTL+U7Exh4EUiEdoA7cWBclrPpCaY2Lb8zw0W0ZhhIerKh5 2j2X3DVAHZaXbIYKqserA+nJXCBAH0RlHAy6gCpeS/XNFlFn5aVR6Mw4Eq1RPxloK2aR BiiO2WlaL0A1A6uDlXsKpHy1tvZqJ/Be0TVrGjP9YbbhJpgKdbqASCUdWZh95Wl56vHA WG7brYiyXL8YlHPcYVl8ZqrPEFkkIB/rPUuzwnGPufkUuEV9L5UrmsKn78cGgQGf0Xoh vXdQ== X-Gm-Message-State: ABuFfojRBl5kB+g2ZxcQIl3NcMDnZ7BVgSIE0HQWIbpubJVO65T5+sWd OsQmV5qdnW6ZGB4HvDITbd4= X-Google-Smtp-Source: ACcGV604c4MC54e8MAXqw2eowfRjQIppMKzaL9j5NUOQvRQtOIKfJm8S+4u7TalFkxz8KVMNAKpjLw== X-Received: by 2002:a62:41d6:: with SMTP id g83-v6mr9907768pfd.44.1538712865912; Thu, 04 Oct 2018 21:14:25 -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 n63-v6sm277975pfn.9.2018.10.04.21.14.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 Oct 2018 21:14: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 11/16] of: overlay: test case of two fragments adding same node Date: Thu, 4 Oct 2018 21:12:42 -0700 Message-Id: <1538712767-30394-12-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1538712767-30394-1-git-send-email-frowand.list@gmail.com> References: <1538712767-30394-1-git-send-email-frowand.list@gmail.com> Sender: linux-fpga-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Fri Oct 5 04:12:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Rowand X-Patchwork-Id: 10627379 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0A93615A6 for ; Fri, 5 Oct 2018 04:15:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ED04A29546 for ; Fri, 5 Oct 2018 04:15:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E02F72954C; Fri, 5 Oct 2018 04:15:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 64DF929546 for ; Fri, 5 Oct 2018 04:15:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727802AbeJELLT (ORCPT ); Fri, 5 Oct 2018 07:11:19 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:42862 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726894AbeJELLS (ORCPT ); Fri, 5 Oct 2018 07:11:18 -0400 Received: by mail-pf1-f196.google.com with SMTP id f26-v6so4280497pfn.9; Thu, 04 Oct 2018 21:14:27 -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=lm95wF8mJddYm0VhxCngjpzPemT2/wn0EO2jGZN6AyE=; b=RXtCl+Pt8I5TiW0IoK8WaIIw+0Vop4aa9q/LAGN55Kebp2FAqNwu215I3/MLVyT/Qm hAoEcySv92yL0DWdr3N25zW0vOZk4e1KGAbp2XM6krxU8mq8A+xqlOyqwN4LWQtQnHrX T6vJGWmA3dtdZXNif9lfpdirK8+95HQWDyRGQf+YPLYEahV3gln00ENl6CRWrhvCrl0E P659t2ziFQ35yGWbnrG/ogSdh1jx1LnLm/uv8dB2hLbJZYfvI7RdcYq/H9WP4CYA9F6U voU4w+vLlNfLzLWg2yaoNEvsS/WqBmmJm9mTFl+sxJ3zjYARYxztK88nl7CCtQnn9Uwf ox6Q== 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=lm95wF8mJddYm0VhxCngjpzPemT2/wn0EO2jGZN6AyE=; b=A6a3lz84tETjS87qhxi9F3LSbQITtdZnvC/OXRcghAv8gZGS8d4iGTuMdTQvvRXwMU r0vBcTYRxmZcygI4/1Dza6KkXTVuolGqTh1l8FtXQH7JyJojC5NYjhRHsmn/6B6Cd8Ba mL4lRR92BzH/NAa4f9Rc7Fd7MXzt5dKoYYqIhNgzwa4zC05ZXRW3O0JilkQZ73nA3Qqd r3dyUbeFkk3hjH47KDJbSW2khLsX0Vbvtf4xSXLUXS7rpk+rbLoXQyl06cBKkXfqWv3L GMYpFPQfhrdITIeY5aRrxRDngMpfZtws/y9F9k0jtWQ3xaAbcx+/hDA38qWkkMFAlPjk qAaw== X-Gm-Message-State: ABuFfoglgzdxfX56WweUTFGIncy1SXfUfo21q6ecMgzna7DC3DgnBHUy 2qWUWwVHPtQYoCGnOwTlUPM= X-Google-Smtp-Source: ACcGV63TQERvIoWWZhel2GHtFYgr9GqEeJFOImMPpydca6W9J95SIbyqnEz50FyYzcIrTk+zy7AozQ== X-Received: by 2002:a62:1ccb:: with SMTP id c194-v6mr9830932pfc.203.1538712867133; Thu, 04 Oct 2018 21:14: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 n63-v6sm277975pfn.9.2018.10.04.21.14.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 Oct 2018 21:14:26 -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 12/16] of: overlay: check prevents multiple fragments add or delete same node Date: Thu, 4 Oct 2018 21:12:43 -0700 Message-Id: <1538712767-30394-13-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1538712767-30394-1-git-send-email-frowand.list@gmail.com> References: <1538712767-30394-1-git-send-email-frowand.list@gmail.com> Sender: linux-fpga-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 f89383331b88..5376ae166caf 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 Fri Oct 5 04:12:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Rowand X-Patchwork-Id: 10627371 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 919C915A6 for ; Fri, 5 Oct 2018 04:14:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8150029546 for ; Fri, 5 Oct 2018 04:14:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 750E82954C; Fri, 5 Oct 2018 04:14:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5399A29546 for ; Fri, 5 Oct 2018 04:14:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728010AbeJELLU (ORCPT ); Fri, 5 Oct 2018 07:11:20 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:37604 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727799AbeJELLT (ORCPT ); Fri, 5 Oct 2018 07:11:19 -0400 Received: by mail-pl1-f196.google.com with SMTP id az3-v6so6186041plb.4; Thu, 04 Oct 2018 21:14: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=1fnOpPM1kiapy4QHrlrobEosYyapb5Ay5UrBG0KvRxc=; b=n13DsC+2iz1vpq3/NTsv7m6uOV0oQacGkoATZot6finfcebdxUsCosCXvSEZafbLlC flSdYVPFZxkvk3vKscivI9omvZUcP9MvP5eu1RmiNjR0RVQxgtPlkk+65v2h7FgYNAg0 0srjPgRQZSZyPAnf1GsOjGZMCAcnmPB+7Y11J/JRPQLXHq4my9N1I8n8mZBd0ZzOdBn6 BOfI3U6pISrCTaA6kStSX4oSbFsCAiEgSGj01/+YlLzgGReZzmBWdcDUdgBBBy5XOqpx 754crHAMNRJZpV9WgcmIBFYrn7gh+/3c6vTGmDH6kZP1OKyw1JXu0DKkve0lPi6+1xeh 9SMA== 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=1fnOpPM1kiapy4QHrlrobEosYyapb5Ay5UrBG0KvRxc=; b=L06p05kVY9RMIWZ6OTHZxgu0j5yVjraxxAIgye1k1WphV8j+JrU2Tac9bQBJFu5gY+ xiHY37lpUAMOnFw6ejPiqJ/agph3iQ95xuceCj6BoiwCLYglVwk5DEiMuofCKhRVqnse C3GX19kp/vULew0SkIKgiMkzikCegr3L3H/Amj1BoXvJheFXouQKQMzkVFDmAhnUe0YP UTP/NzqK1bkt8IkrEC5R7iRV8TDvV7XArbIGYrJTGTh+waLfZbJNP21kl6eAQDTKFdVL KYBq38ukndUmUEkyQmeJcmqlajsjg87DKhhftrYg4Op73CKS1QDS3QaMKIlsCdPmuoTW QJuw== X-Gm-Message-State: ABuFfoiLdsko4Cb2ICztkeOsCajcE2s92eA1G1tPcXqNFT8PE0kbQ96/ xioRAlROmGscH0fgYBO/6hUu3WcJ X-Google-Smtp-Source: ACcGV63SLRwAN3ru9qVoH9krxSJ9C2yaGSpf65+8GpK+SAd/BsbEllXRqofVjyqZdzPFOHrsqtmgIQ== X-Received: by 2002:a17:902:158b:: with SMTP id m11-v6mr9565869pla.102.1538712868355; Thu, 04 Oct 2018 21:14:28 -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 n63-v6sm277975pfn.9.2018.10.04.21.14.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 Oct 2018 21:14:27 -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 13/16] of: overlay: check prevents multiple fragments touching same property Date: Thu, 4 Oct 2018 21:12:44 -0700 Message-Id: <1538712767-30394-14-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1538712767-30394-1-git-send-email-frowand.list@gmail.com> References: <1538712767-30394-1-git-send-email-frowand.list@gmail.com> Sender: linux-fpga-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 5376ae166caf..640435534675 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 Fri Oct 5 04:12:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Rowand X-Patchwork-Id: 10627377 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 427EB1731 for ; Fri, 5 Oct 2018 04:14:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 310E929546 for ; Fri, 5 Oct 2018 04:14:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 21A192954C; Fri, 5 Oct 2018 04:14:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C05CE29546 for ; Fri, 5 Oct 2018 04:14:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727980AbeJELLV (ORCPT ); Fri, 5 Oct 2018 07:11:21 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:44330 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726894AbeJELLV (ORCPT ); Fri, 5 Oct 2018 07:11:21 -0400 Received: by mail-pf1-f195.google.com with SMTP id r9-v6so4278982pff.11; Thu, 04 Oct 2018 21:14:29 -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=f8CHGg/dP0+tyxFniBtsAkZ11FN05WqHDiWqCxA2mcK4De/aYj8RKLtwAiMoReNHYs jK49xD2xSDlU+mQUMjunMF1tXiDhv7I9xArb4a6mWx2HfBGvNSZLH4GndqG07vxKMT93 uMRm6mxDVZ9bSYCtuLfCz9Q5qsiNbpN/X0NvpZcyEBBeRJ4DLzeXX4oRCrBSDg8B9o5k zVwlLdjqDdDjaTnn0sPDi26neQk44sout3j2Z4FG4GNCKUfHcsPNuVUIdjTOP52EBDad RNekrT0mk2oT4NaKT0b7RiSeMuwPoXKowxdOiUhM+Jy/5cJDMeQJw3+JL+yt6vfRtMox ms8Q== 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=eUT+FXP8x77oiXls1Mp9kN/Cb0hdtqKuRZGrDCpWEvf4TNOaWq2gop+0BbJ6ozdUxD TkCyVOxphyvEy6LwyJuZXb+E/S8mb/rwAxmhS9u+Uk7+GJNBbPlgKaeeSTi5OXkX09LW cdHrW9xfxoJLZXsgw439fQR+zfjtHiULII+qj08eEpKf7w/cVQE7nTI0jI/7gKtUCKMo nmyIXA3tYlFsSocz71RaLStStbd+w7TwrAb9W2hV5JxkTjUnd3N4iIGibKtwF+wsivgT 60ewaLWHb3O2oYc6mBOPCGMsoZIe9bK7GB8ppbzgHUfrVAtUz+sopg+45RujhV8BcF0i keDQ== X-Gm-Message-State: ABuFfohfzLVqlf9v2sNXAxNxvbDac94tuQE3IFzaJsLUtiuo0X+yH3fC 782WIO14j6yEKZ+V5THmo+0= X-Google-Smtp-Source: ACcGV616sfBSeWdhY65vuwJ347vlXuWjFMzvd8rfSFxev4MhtCvsl9HFe0cPVapvQHbAn0zPVFYAEA== X-Received: by 2002:a63:3507:: with SMTP id c7-v6mr8359856pga.158.1538712869669; Thu, 04 Oct 2018 21:14:29 -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 n63-v6sm277975pfn.9.2018.10.04.21.14.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 Oct 2018 21:14:29 -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 14/16] of: unittest: remove unused of_unittest_apply_overlay() argument Date: Thu, 4 Oct 2018 21:12:45 -0700 Message-Id: <1538712767-30394-15-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1538712767-30394-1-git-send-email-frowand.list@gmail.com> References: <1538712767-30394-1-git-send-email-frowand.list@gmail.com> Sender: linux-fpga-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Fri Oct 5 04:12:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Rowand X-Patchwork-Id: 10627373 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2190815A6 for ; Fri, 5 Oct 2018 04:14:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 11EC129546 for ; Fri, 5 Oct 2018 04:14:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 062A12954C; Fri, 5 Oct 2018 04:14:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.4 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, URIBL_SBL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A0D3729546 for ; Fri, 5 Oct 2018 04:14:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726894AbeJELLY (ORCPT ); Fri, 5 Oct 2018 07:11:24 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:43723 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727799AbeJELLW (ORCPT ); Fri, 5 Oct 2018 07:11:22 -0400 Received: by mail-pg1-f196.google.com with SMTP id 80-v6so4121333pgh.10; Thu, 04 Oct 2018 21:14:31 -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=6rXTsHTXEu0ePfav46SJfn/0WRudrcKzA2MYy/8i5Ig=; b=M8OeIxicV23kcfKfRr40LQOmdI4hpD/+kDesn8YVAAjltVpo1dI3FqLGaJVHSc4uWP nLLrT4Yxi4gx5TPfxzY+4jEjp3pUaLZgD+5YX7BlbFYNwgLgyVjBVIpRkjv7qdJsBTan T2gLvI3hIj5EuP8VNsEIu4q4Atzy0mObD9NjJatbIDFI0dE8bTR1wtmVkfoF2+fSVPy4 DWdA/3dmk+36dDH7kOkO+Z9/FcTo5ResY+lbPkfYrZnZ6Mur1c7ed/DHW03gjIvaR4w/ dcYwN+3vTawpW4lC8VcH53+mmW53+S3MePTv6hMnhAmwJo1NJxVLozLDYKl7hQ5qhjbF hEWw== 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=6rXTsHTXEu0ePfav46SJfn/0WRudrcKzA2MYy/8i5Ig=; b=URb7gfwz12t3FmVr1hCA5/VhhPsWYy/tibwT6rVwBkqQzK6cUd/CHNBgJN3cgaCpUQ Ovgutm1mOwcYvgmi+RyFYkZwkzvufzNdIanB3KUWGbfeW1NOYVrDyKrf3S7IN1Vzmlhu LYRqc40nLG+bdk96JGuhTgAkK0FvlDGsE+6RY/btTFssCEUC6pmaqCqr7azzxc6tSD7R HpyswRoWfAKYtLlu50WY5cXT2YA4o8nJQfUX+kS7oC79FjENmCeo9C3DSwo02HzPJb8z AJOq/GikeHfwazx7bAxbPgMqKMl39RHfjtOqrgEHBICiMGshJc/bVIC18FYiNB69PnkO 9+UQ== X-Gm-Message-State: ABuFfojG6s6KZQ+i2m1o9hOkcCvU+z25AjxtohgM6lCEENAeu0Au6pRH a5FnSg15jdaDrHGpNsQEbG4= X-Google-Smtp-Source: ACcGV60l4DiJgSXgQsIpQlpzSGrx51ZqCYckt/Rte/iMrTnZBmL5KdiqoUETladn6nlZgQDe8/KQ6g== X-Received: by 2002:a63:7506:: with SMTP id q6-v6mr8396282pgc.137.1538712870907; Thu, 04 Oct 2018 21:14:30 -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 n63-v6sm277975pfn.9.2018.10.04.21.14.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 Oct 2018 21:14:30 -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 15/16] of: unittest: initialize args before calling of_irq_parse_one() Date: Thu, 4 Oct 2018 21:12:46 -0700 Message-Id: <1538712767-30394-16-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1538712767-30394-1-git-send-email-frowand.list@gmail.com> References: <1538712767-30394-1-git-send-email-frowand.list@gmail.com> Sender: linux-fpga-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 and does not set args.np instead of trying to dereference a random value. Reported-by: Guenter Roeck Signed-off-by: Frank Rowand Reviewed-by: Guenter Roeck --- drivers/of/unittest.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 6d80f474c8f2..b61a33f30a56 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -780,7 +780,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 +801,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 +854,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 */ From patchwork Fri Oct 5 04:12:47 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Rowand X-Patchwork-Id: 10627375 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 133FF1731 for ; Fri, 5 Oct 2018 04:14:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 00F9B29546 for ; Fri, 5 Oct 2018 04:14:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E92E22954C; Fri, 5 Oct 2018 04:14:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 946A029546 for ; Fri, 5 Oct 2018 04:14:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728039AbeJELLX (ORCPT ); Fri, 5 Oct 2018 07:11:23 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:37897 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726894AbeJELLX (ORCPT ); Fri, 5 Oct 2018 07:11:23 -0400 Received: by mail-pl1-f196.google.com with SMTP id b5-v6so6193289plr.5; Thu, 04 Oct 2018 21:14:32 -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=jnKR2PoeAIKjHuDWgCk3o7QuZS8LEHYAoeREGeLzT+w=; b=dAvKvohZsVxx9kvawvTGHS6nMcBizZ2VDXINM1YFkWeD2QgzVzadpwyop5UgZ8Rz3v zY3Gg4ktPe0J1ZibO2z4kOMVdLXfKkNJBj90EW4tLSG0Hx6BGHKIfV0FHl29PMm9P1U5 86CkAL2aus9uL/X9tCoYGqzHarTUDKAj2jxyrswrPrkWaUQL1B5R3HV/H1MFJXAmsDEX yOAy5SvcW0UikMQ2CJGV1PtkOTbFeB10RpQqtH755fli7w5IMVvNVpRKhRD93Ecfmgqo dE0pi9uYJDUFdaJB9ld6SpzS4Qojxp3q/UpqItLl4zpd6V/oK1viHG4GbNw2KUiuPHg0 MNIA== 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=jnKR2PoeAIKjHuDWgCk3o7QuZS8LEHYAoeREGeLzT+w=; b=Z+QIT7WGDv1IUPt2uoORC77Y1kli5zd82lIuq/+d33kJJTK2ubapw3uTVdtVUbX8iV 8adh3vTPxXUc+sDTNgHk3/DzkEuTZ79uQ71AYZaL4TWfs12EM/IdZrtCeTRH3jdk6Kni GL53lHc5A2z5yRGiFoONxxwIMgrFCmIIypHg+f00QuMncdFC4bxI5t59R4PzoOeOkMtP jFmYhzND+cspdX+YoIVap+0UvqiQrrlLHruSJ2PVj52E6imTeTnSceWIIBwFBqF3M3Ct mZbO9JKraUaZbShAmAtbf0UqsurlTGC1GK+OohPAj++erBdAmEZYQAmLqEpBgB/2HUSH 5MVA== X-Gm-Message-State: ABuFfohMCxfJWY5WF75z7peNBiUJ+4UmhtpI1Z85GGESeQxvn8GkRILT z2jaIkEGiwSlvbK0fvYdLtA= X-Google-Smtp-Source: ACcGV62qItnQd2CXtT6xk/RzShI4DDV5hJdw17NOq2BjfOvsibaFEpU1DYVLMYQw8bbac0podcCrfA== X-Received: by 2002:a17:902:261:: with SMTP id 88-v6mr9771113plc.331.1538712872151; Thu, 04 Oct 2018 21:14:32 -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 n63-v6sm277975pfn.9.2018.10.04.21.14.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 Oct 2018 21:14:31 -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 16/16] of: unittest: find overlays[] entry by name instead of index Date: Thu, 4 Oct 2018 21:12:47 -0700 Message-Id: <1538712767-30394-17-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1538712767-30394-1-git-send-email-frowand.list@gmail.com> References: <1538712767-30394-1-git-send-email-frowand.list@gmail.com> Sender: linux-fpga-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fpga@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 b61a33f30a56..4d4ba4ddba9b 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -2152,7 +2152,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), @@ -2175,7 +2175,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; @@ -2205,6 +2206,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]; @@ -2252,11 +2266,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;