Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1881697imm; Sat, 13 Oct 2018 05:52:38 -0700 (PDT) X-Google-Smtp-Source: ACcGV605ygpO4ZvsVTCA2QdOqQjQm9z6npytfiZVIQz+QeNuTHJXMnnvQVwbdWnlajnfZWUPhfzn X-Received: by 2002:a65:588e:: with SMTP id d14-v6mr9117810pgu.117.1539435158651; Sat, 13 Oct 2018 05:52:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539435158; cv=none; d=google.com; s=arc-20160816; b=vVXDEVMnLR/Nq8io6t507lmpfiS/75Kgk8VhWURdSDHG0KteZ1vtVdfbKAu1dMjX4S NY13BQ0W+9fb4OZ5i5PPIx3gH162/97wNQjJUbv5qbMd1zKmoylVuSO5qqLMdVOqGr3Y 4dEiT+hQr5eism7VFvdDFX9XCAmom442iTUJDzSCf2BYZ0Lu41h7eFDTZfsKsqk71uk2 ZmfhfyQCsR6Dy9yFRzBpxzfjLhKv1zUZnOvJHgDnuQoIeSMYuwaJBHKL2z8W+L+UZ9is RM9E71UWQuf9IcJ0+5jn/ivqqwjzg1Cd5KkYQDMQ2507vsW5r4prkdR8ggjpoYqholRf ZAvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id; bh=IxGjoOdG7r84i7M4JocgW0cB9WVoJEmZEVPshwXK6R8=; b=Xd5F+kLHCZkDFrlabDccnjPaF8EjASfmb1hKvzfw8fau3oWvFgXgs/WLMcBAYYhyQD ka0lQPdMjU6dYzuWR8eneGj2zVVcUlejD3SD29hZVe5umSAbXHo++KaeNvrlmt3DVTEi xLUnh3L+WmupQnhyScnIAQndqJIKUOJTvJ22leQJ5YnEu8KxFncb8tkqcE1SsZqR205+ LuOsoBUtUxp4a7ojkwExxlVuTBt45T6ULU8mrla8oYNlU9GKYkvW1rT3nT5ded1N+rRz R6eiToCiCyFKr/uIiw1UYRUWc65IoUpQ+BmEIRu5YhB40ZWx/skLrD/oynAG6RDIjLyz Dl7w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k190-v6si4153709pgd.181.2018.10.13.05.52.23; Sat, 13 Oct 2018 05:52:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726670AbeJMU2x (ORCPT + 99 others); Sat, 13 Oct 2018 16:28:53 -0400 Received: from smtprelay0102.hostedemail.com ([216.40.44.102]:54098 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726163AbeJMU2x (ORCPT ); Sat, 13 Oct 2018 16:28:53 -0400 Received: from filter.hostedemail.com (clb03-v110.bra.tucows.net [216.40.38.60]) by smtprelay01.hostedemail.com (Postfix) with ESMTP id E0CA1100E86C8; Sat, 13 Oct 2018 12:51:49 +0000 (UTC) X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::::::::::::::::::::,RULES_HIT:41:355:379:599:800:960:966:973:988:989:1260:1277:1311:1313:1314:1345:1359:1437:1515:1516:1518:1535:1543:1593:1594:1605:1711:1730:1747:1777:1792:2196:2198:2199:2200:2393:2559:2562:2693:2828:2898:2899:3138:3139:3140:3141:3142:3622:3865:3866:3867:3868:3870:3871:4321:4385:4605:5007:7514:7576:7875:9010:10004:10400:10848:11026:11232:11473:11658:11914:12043:12048:12296:12438:12679:12740:12760:12895:13255:13439:14181:14659:14721:21080:21433:21451:21627:21789:30012:30029:30054:30069:30070:30091,0,RBL:47.151.153.53:@perches.com:.lbl8.mailshell.net-62.14.0.100 64.201.201.201,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:28,LUA_SUMMARY:none X-HE-Tag: bait23_fb9a8a32a15d X-Filterd-Recvd-Size: 5128 Received: from XPS-9350.home (unknown [47.151.153.53]) (Authenticated sender: joe@perches.com) by omf14.hostedemail.com (Postfix) with ESMTPA; Sat, 13 Oct 2018 12:51:47 +0000 (UTC) Message-ID: <97b26203e6792795bdc0a66ce4cdb47571ff16c1.camel@perches.com> Subject: Re: [PATCH v2 12/18] of: overlay: check prevents multiple fragments add or delete same node From: Joe Perches To: frowand.list@gmail.com, 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 Date: Sat, 13 Oct 2018 05:51:46 -0700 In-Reply-To: <1539406418-18162-13-git-send-email-frowand.list@gmail.com> References: <1539406418-18162-1-git-send-email-frowand.list@gmail.com> <1539406418-18162-13-git-send-email-frowand.list@gmail.com> Content-Type: text/plain; charset="ISO-8859-1" User-Agent: Evolution 3.30.1-1build1 Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2018-10-12 at 21:53 -0700, frowand.list@gmail.com wrote: > 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 [] > diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c [] > @@ -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)) { A bit of odd indentation here. This line is normally aligned to the second ( on the line above. > + /* 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; > +} Style trivia: Using inverted tests and continue would reduce indentation. 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) continue; 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) continue; /* inexpensive name compare */ if (of_node_cmp(ce_1->np->full_name, ce_2->np->full_name)) continue; /* 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; } } }