From patchwork Thu Oct 18 22:46:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Rowand X-Patchwork-Id: 10648381 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 6D4B013B0 for ; Thu, 18 Oct 2018 22:49:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5B91628C6C for ; Thu, 18 Oct 2018 22:49:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4FEEE28C78; Thu, 18 Oct 2018 22:49: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 D93E728C6C for ; Thu, 18 Oct 2018 22:48:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727651AbeJSGva (ORCPT ); Fri, 19 Oct 2018 02:51:30 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:35514 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727622AbeJSGv3 (ORCPT ); Fri, 19 Oct 2018 02:51:29 -0400 Received: by mail-pl1-f193.google.com with SMTP id f8-v6so14982513plb.2; Thu, 18 Oct 2018 15:48: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=Qu97L87RGKi+8AyH9EKaRg09X+fdaCoy/llppuDOcJE=; b=UDtnt9JsZOsgIUxfbT3FOkloaNseK0BoQaqLhK2Q5jDJHzyIkCDrylzICRqpoqZpL5 WHQDhw7D8FwNugi3DzON7wPSlXZuN3GcqEgte4P5UJ1kXBrOWvDZeT6aAojsoaJID6vU lWkRmpdXgnaDl7RjIWEHBT1cwkoZZgOGAWFbWuWnJpnOAYBkprjW860xwmUh0Kn7nqid HBiJ4uizS/yzz9REdNaLW0Fv79n3f0gAXhvuYr7hoIygDvQCOyrS+fZtXQLkzvVjuPog uRRmc9BHO4hEgL5h3q3kqOOg4HlPOuu/8AOOU2OHNu6g18lUVS/CvLk6sUChRKQqGcki Galw== 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=Qu97L87RGKi+8AyH9EKaRg09X+fdaCoy/llppuDOcJE=; b=rHpXpynGc2Bu2VN2CuMOesISGxjZS37RcQ3h+r5dX78D1PGflVrE5Ux79P50YXkg1m YV73ilRQ6kg8/LFMu5VcOWwPwabARLGJLEnJsrqeL3S5rNK6YVd3MD2c2zXfmZUU7eb6 akOOI/essqqbT0JKbKz87x1/N7TBYKzJ1Vrneul69rBhV9E91uaaOZs0XgvZ4sFztLnR O9oAq3St1X+d1VxmDLymPCRMBFhWmQJf1x4b1KDX9HELjohGk2dceBX1syMwzLvlai4K rthvdzKxL2Ez4FhP3u5OooTXJDfyoLIKcU5eYEBOjXT2b7b3ARH2LAsTTc2Yj8zNYC+n 6hPQ== X-Gm-Message-State: ABuFfohJV9IjvNBIFFgo93iJ+ilf+vAXiNQzOAyBI84ruXj+yptAFsoe RiK7Aszr8r5NjP1UHfFCOFY= X-Google-Smtp-Source: ACcGV635nMTW9jOKra4iL+74o8Mn5al0B/pZpNUr+vRp5RQEFPig1YNoGM9XZwnEH3kWyV4xyEFyzg== X-Received: by 2002:a17:902:a50e:: with SMTP id s14-v6mr31667667plq.78.1539902898895; Thu, 18 Oct 2018 15:48: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 v81-v6sm38129268pfj.25.2018.10.18.15.48.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 18 Oct 2018 15:48:18 -0700 (PDT) From: frowand.list@gmail.com To: Rob Herring , Pantelis Antoniou , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Alan Tull , Moritz Fischer Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, devicetree@vger.kernel.org, linux-fpga@vger.kernel.org Subject: [PATCH v5 12/18] of: overlay: check prevents multiple fragments add or delete same node Date: Thu, 18 Oct 2018 15:46:30 -0700 Message-Id: <1539902796-8382-13-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1539902796-8382-1-git-send-email-frowand.list@gmail.com> References: <1539902796-8382-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" 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 88e346234ae7..e12f2c28a36a 100644 --- a/drivers/of/overlay.c +++ b/drivers/of/overlay.c @@ -392,14 +392,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. @@ -517,6 +509,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 * @@ -571,7 +611,7 @@ static int build_changeset(struct overlay_changeset *ovcs) } } - return 0; + return check_changeset_dup_add_node(ovcs); } /*