Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3322229imm; Sun, 14 Oct 2018 17:27:42 -0700 (PDT) X-Google-Smtp-Source: ACcGV63IJHZ/l3FAAJffvj9KCwAk4Wq4azzxwlJ0dPmtSS9by8PjljFKWQ5DtnNvSxtmEm1IcoiE X-Received: by 2002:a17:902:205:: with SMTP id 5-v6mr14935770plc.307.1539563262675; Sun, 14 Oct 2018 17:27:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539563262; cv=none; d=google.com; s=arc-20160816; b=i5sfThqEJsrqvPCUZed3S0c6maFMLu4MDPjw/CaT0uKHVm0X6PmQdLLsH5dBR5F0UR vAMOMBgtBdIkcVuYwnwsHxp8dujSTv5AmlnVDiuuOK4hPANagNRS/sd4NjLAjcw1hoO9 AMl/0TuKZ3/79+ASZaqbc4j71HB5Kdy38/thuL1knohJ/fPYUJn2fUnhfB5Db37yzeEM /6Y0abcXJzMtkcdyA98QEci7Htx3T7JpbQD2NrtLhsrkvPDE5FdAJDlf+7gfuoHA03T+ MQxZyxit+NhWOKkHxUcChkbAPf0P3akVZ/Irm2KxaQobDUeWn/10OaltiX1x2X+MwMqJ lgSQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=GLwPvaFYCJWZOyI89dqGxvTQx+54pbaTdFZFvSr2/M0=; b=gsEv/3QJLCvu89/Cj8rHAK6H/DTBtC0zmZih8mDZrvMyU+bA1wgXqWeEk9uyyqyO1W tRo6Gd82eACItT7NwgBCsEhpfChOt7lKortlMdcUxCHkt2JR+ZXEYIgXaoGLR1+OkUU5 eNvWP/Lx3uK7TnqGGW3AxujA+l73ji1AAm+oaDwOd0vMPhtU2kwNOEnm0JRvUP8V6+1g p2erAWLh3GeZwdBg51PYo+6KyZLuuc1vrOOJ0VE7NnMdBxrfoFwkFT/oGHQXX0E5e16j TwCwZKT5PRL//jCGWJ05FJhqjd4fkayHP4Jm860lHFbvWMoHTgYpwR1/fRp4xhc1QkNL icUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TAVh63kY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h7-v6si9289234pfe.72.2018.10.14.17.27.28; Sun, 14 Oct 2018 17:27:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TAVh63kY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726932AbeJOIJH (ORCPT + 99 others); Mon, 15 Oct 2018 04:09:07 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:45180 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726843AbeJOIJE (ORCPT ); Mon, 15 Oct 2018 04:09:04 -0400 Received: by mail-pl1-f195.google.com with SMTP id y15-v6so8392084plr.12; Sun, 14 Oct 2018 17:26:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GLwPvaFYCJWZOyI89dqGxvTQx+54pbaTdFZFvSr2/M0=; b=TAVh63kY9xXRmT+EiDuTEiTz8d+ieMTayJqJiXk53CojmotSIDGIgzumO+/+CU8gyu l2e2aGXeMJMTmJQwmRwQh3Z6lMyJhQiATjvGr8xGly4guj3aylP4WPw782SNJjqmvP6I 7VukfvzGe6CEMuBFOtJ4Cj3Rfp8gtXnj+xgsJ90PccTpDRafRAb3FpjN4DdgLFQcBXfL R/A0P2PmVRR+ZBsd5S8BJhPH0UVV2wFnI5XCrg8v6zRaXiPtctqnYAeSd0hddxWbBC/I /E8HsYAILQvwAKEDurN0NXhBeD78S+XDuT095XyWzxZMRPp1faiycZMUBv6y/D45RBw9 /nHQ== 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=GLwPvaFYCJWZOyI89dqGxvTQx+54pbaTdFZFvSr2/M0=; b=nqV2s6li2DwKBerxKd4oUwPwcOASWj3TAZwzRr3OOmlu1mO7YW32Dz/pJEShbfvnxB wVFTz4bKz1tkFk+S4ZehMvuoi04OkcRUrnSPt+RUdNYpUtEim4UTmE0PNg1EtedlsNes M6WPs0F71B3WhZ5HVyfpDELvB8S7tEC2/V+R8bfCc/LVcSDj5hQRJJdL3AKtDwdtm/XK 0n6fTOk0W0hBOvgqDVY5f09CPlsetC+fPu94W6tM3khV0fPUQqbzX/eXLr0PqhNvFn+L zJ7Gadzst4VGvjxYeC3NGKX/mcvkPzmsgQauViEPUUPNVP/YvLP+UnqB2B4k3sq0K3oe YZlA== X-Gm-Message-State: ABuFfojyo94p7MMwiOJMlqFHcbG7WCUgQ7zQgW1Val5Ftaf9o7UylD5Q DzOuP/p8JUqh3Jde12U+yoo= X-Received: by 2002:a17:902:d908:: with SMTP id c8-v6mr14633141plz.227.1539563175157; Sun, 14 Oct 2018 17:26: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 j14-v6sm11387110pgh.52.2018.10.14.17.26.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 14 Oct 2018 17:26: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 v3 12/18] of: overlay: check prevents multiple fragments add or delete same node Date: Sun, 14 Oct 2018 17:24:24 -0700 Message-Id: <1539563070-12969-13-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1539563070-12969-1-git-send-email-frowand.list@gmail.com> References: <1539563070-12969-1-git-send-email-frowand.list@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Frank Rowand Multiple overlay fragments adding or deleting the same node is not supported. Replace code comment of such, with check to detect the attempt and fail the overlay apply. Devicetree unittest where multiple fragments added the same node was added in the previous patch in the series. After applying this patch the unittest messages will no longer include: Duplicate name in motor-1, renamed to "controller#1" OF: overlay: of_overlay_apply() err=0 ### dt-test ### of_overlay_fdt_apply() expected -22, ret=0, overlay_bad_add_dup_node ### dt-test ### FAIL of_unittest_overlay_high_level():2419 Adding overlay 'overlay_bad_add_dup_node' failed ... ### dt-test ### end of unittest - 210 passed, 1 failed but will instead include: OF: overlay: ERROR: multiple overlay fragments add and/or delete node /testcase-data-2/substation@100/motor-1/controller ... ### dt-test ### end of unittest - 211 passed, 0 failed Signed-off-by: Frank Rowand --- checkpatch errors "line over 80 characters" and "Too many leading tabs" are ok, they will be fixed later in this series drivers/of/overlay.c | 58 ++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 9 deletions(-) diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c index a3990c20e210..b0a0dafb6a13 100644 --- a/drivers/of/overlay.c +++ b/drivers/of/overlay.c @@ -398,14 +398,6 @@ static int add_changeset_property(struct overlay_changeset *ovcs, * a live devicetree created from Open Firmware. * * NOTE_2: Multiple mods of created nodes not supported. - * If more than one fragment contains a node that does not already exist - * in the live tree, then for each fragment of_changeset_attach_node() - * will add a changeset entry to add the node. When the changeset is - * applied, __of_attach_node() will attach the node twice (once for - * each fragment). At this point the device tree will be corrupted. - * - * TODO: add integrity check to ensure that multiple fragments do not - * create the same node. * * Returns 0 on success, -ENOMEM if memory allocation failure, or -EINVAL if * invalid @overlay. @@ -523,6 +515,54 @@ static int build_changeset_symbols_node(struct overlay_changeset *ovcs, } /** + * check_changeset_dup_add_node() - changeset validation: duplicate add node + * @ovcs: Overlay changeset + * + * Check changeset @ovcs->cset for multiple add node entries for the same + * node. + * + * Returns 0 on success, -ENOMEM if memory allocation failure, or -EINVAL if + * invalid overlay in @ovcs->fragments[]. + */ +static int check_changeset_dup_add_node(struct overlay_changeset *ovcs) +{ + struct of_changeset_entry *ce_1, *ce_2; + char *fn_1, *fn_2; + int name_match; + + list_for_each_entry(ce_1, &ovcs->cset.entries, node) { + + if (ce_1->action == OF_RECONFIG_ATTACH_NODE || + ce_1->action == OF_RECONFIG_DETACH_NODE) { + + ce_2 = ce_1; + list_for_each_entry_continue(ce_2, &ovcs->cset.entries, node) { + if (ce_2->action == OF_RECONFIG_ATTACH_NODE || + ce_2->action == OF_RECONFIG_DETACH_NODE) { + /* inexpensive name compare */ + if (!of_node_cmp(ce_1->np->full_name, + ce_2->np->full_name)) { + /* expensive full path name compare */ + fn_1 = kasprintf(GFP_KERNEL, "%pOF", ce_1->np); + fn_2 = kasprintf(GFP_KERNEL, "%pOF", ce_2->np); + name_match = !strcmp(fn_1, fn_2); + kfree(fn_1); + kfree(fn_2); + if (name_match) { + pr_err("ERROR: multiple overlay fragments add and/or delete node %pOF\n", + ce_1->np); + return -EINVAL; + } + } + } + } + } + } + + return 0; +} + +/** * build_changeset() - populate overlay changeset in @ovcs from @ovcs->fragments * @ovcs: Overlay changeset * @@ -577,7 +617,7 @@ static int build_changeset(struct overlay_changeset *ovcs) } } - return 0; + return check_changeset_dup_add_node(ovcs); } /* -- Frank Rowand