From patchwork Tue Oct 16 02:37:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Rowand X-Patchwork-Id: 984510 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42Z0Y40b37z9sB5 for ; Tue, 16 Oct 2018 14:05:12 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="DobFn6uA"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 42Z0Y362PkzF3XR for ; Tue, 16 Oct 2018 14:05:11 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="DobFn6uA"; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::643; helo=mail-pl1-x643.google.com; envelope-from=frowand.list@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="DobFn6uA"; dkim-atps=neutral Received: from mail-pl1-x643.google.com (mail-pl1-x643.google.com [IPv6:2607:f8b0:4864:20::643]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 42YzzJ2M7WzF3WT for ; Tue, 16 Oct 2018 13:39:24 +1100 (AEDT) Received: by mail-pl1-x643.google.com with SMTP id f18-v6so10224551plr.1 for ; Mon, 15 Oct 2018 19:39: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=IcDpIWwdaGfZQXbuTYh5YTbBTtu4RL7zj10+qvSXPVk=; b=DobFn6uA3MYdT1LTnVFyqdbbHDrDprP8bh3jO9x7S6yvxjJ/21xcuNcgB1zLMMMOF3 NytAVqIUmEe2GJHNjr06qCPnBlymupi3wvSwg10otHltSOfYWUIIJWX/INWMg6gWuX/V nAci1GlC+LIAnFxQGS4FNodg+zAnWkNYnNxElMh6txYmbRJqQ9fVHewKOAlRVtMhGpiZ 5SnZtgXXeOPr4w860xpoHqfgqFWedJ5lUOJsdCaNpXCuf0kwrOB1YAjp1xb368wS2sb4 a7edgBCYiLJ9O6LDQ98ronte9Pf6dh1rESyYxyj2wNehjQgMc0MMmwStpWCWqOkDFN/T nXiQ== 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=IcDpIWwdaGfZQXbuTYh5YTbBTtu4RL7zj10+qvSXPVk=; b=I6rFc0aWxIQcLww++32Raks25lTK1p1X6o77Bc2286BW9JcsW7/Cg1K7CYqajJ/+ks APwQRnHl4EJxGifCItswJl2g4QUc1KURhhUre7qKDpv7IoWKb3PZwNhxdrLYlAM1eg6M 55YwFbDR15Cpks6QR/fjbj3I2jG+UBZ3XF7clHCPyAitbSneMRERBDTELuV7i1B53p8E AtrezeVh06rd/kfXr9sApa21L8BXX0jHOG7LXgH6LdiWJgAMhjiK92hLteeVYWANm6Vp 8MxQTh+yZc8UByV6FswMvbwfs9Mn7cBV9OWqk7SnSMgK5g5xWbxrAR8ZSXf5p1vboPwa rWyw== X-Gm-Message-State: ABuFfohm4yEYK1bQWkgFHdYJ1dsyGmz48etN0YIejfrK4WQQFfLvggET Ec9pDOq57tazZWvLEb+Hmif5/iH1 X-Google-Smtp-Source: ACcGV619noATVp+bGXb0SJieo8qnLtAhlORwixdb70nDuESLPsBO5DAhSAeuI00tlYnuTLdaa9mGuA== X-Received: by 2002:a17:902:a982:: with SMTP id bh2-v6mr19734129plb.193.1539657562632; Mon, 15 Oct 2018 19:39: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 u79-v6sm18620287pfd.117.2018.10.15.19.39.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 15 Oct 2018 19:39:22 -0700 (PDT) From: frowand.list@gmail.com To: Rob Herring , Pantelis Antoniou , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Alan Tull , Moritz Fischer Subject: [PATCH v4 09/18] of: overlay: validate overlay properties #address-cells and #size-cells Date: Mon, 15 Oct 2018 19:37:29 -0700 Message-Id: <1539657458-24401-10-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1539657458-24401-1-git-send-email-frowand.list@gmail.com> References: <1539657458-24401-1-git-send-email-frowand.list@gmail.com> X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, linux-fpga@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" 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 --- Changes since v3: - for errors of an overlay changing the value of #size-cells or #address-cells, return -EINVAL so that overlay apply will fail - for errors of an overlay changing the value of #size-cells or #address-cells, make the message more direct. Old message: OF: overlay: ERROR: overlay and/or live tree #size-cells invalid in node /soc/base_fpga_region New message: OF: overlay: ERROR: changing value of /soc/base_fpga_region/#size-cells not allowed drivers/of/overlay.c | 42 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c index 272a0d1a5e18..3e1e519c12f0 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,43 @@ 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: changing value of %pOF/#address-cells is not allowed\n", + target->np); + ret = -EINVAL; + } + + } 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: changing value of %pOF/#size-cells is not allowed\n", + target->np); + ret = -EINVAL; + } + + } 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);