From patchwork Thu Oct 18 22:46:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Rowand X-Patchwork-Id: 986383 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 42blBj1mdQz9sB7 for ; Fri, 19 Oct 2018 10:10:21 +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="HZR4PRXS"; 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 42blBh6YQszDq5k for ; Fri, 19 Oct 2018 10:10:20 +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="HZR4PRXS"; 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::442; helo=mail-pf1-x442.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="HZR4PRXS"; dkim-atps=neutral Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) (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 42bkjF27CGzF3FL for ; Fri, 19 Oct 2018 09:48:17 +1100 (AEDT) Received: by mail-pf1-x442.google.com with SMTP id 78-v6so13174588pfq.0 for ; Thu, 18 Oct 2018 15:48: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=3p9z0Ehj9iwgF9Lhv52flr3WKpZAxs8EQb4W3gnL4wU=; b=HZR4PRXSXC3f+OMGauO6hcsGtA18EWWZyAT13lTC6JiP5/njGLW9QpgSTrjkm7AeTO Pzmpj4MLhYvoEk+cie1GsGqJaiagsjDi7S0n8R2EhGyO484/VyfjWaH13PygS5PYvk40 WwPi66GZ5/4OCIz7qmmL/QWx9pFrFTdN5CbtAmZIHGRHd5cOn+c1KHWYAukRamdds023 nvmun3DYUlpi+ItHi37r2vXpUD3wQju2cOI6OkHwSlra/QeFcBYY5ASZHKho8CW+xakb Wfb3ySCml32Gdsk8DkDsHlzGzyi5GcS7qIcLChl0fNRPs08grrWiuESLsBbqh5wHJylE JObw== 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=3p9z0Ehj9iwgF9Lhv52flr3WKpZAxs8EQb4W3gnL4wU=; b=uNQsMB+CC06LL/l81KHt3uMWyR3vH3Po0Ey/EmacipDbAKAtRHWYDU7dfMWwg8fFf7 bdkyLjKLdfOelmg8Xxcb8g99mn0gBm7yVCDFd2tZZoLhA9R5OP/n7K8bMgEkj6fIwGD6 EOfreTnJPLD49zBIIU9b7PP7n1N2wyJ08TjzrubwsY2hBOHVpLPJC0rqF6/kON9Y3m1b 0IUFTPZoEeiT/6PgGy7LWqhrrNRSdxD0PSmoQZVLzlGm/7MG3iuLrqzlxsrjffB2iDps UasxBCHXiZT7QVvDH62XRDcY6zNBUJ+sMMxXFl+6FBfWRD7ZaCB+G/CgSVHISqLRh81c pygw== X-Gm-Message-State: ABuFfogtPpl8biovB9efmw4cA6iGdpU7GINBdai/d5OqTnKT97FvCPY0 u6LgeDc+exwAUt2TCjE3yok= X-Google-Smtp-Source: ACcGV62j6brXEhvm6NxaHvXh8fuyuIlHYH77b5IHomUnKE2awpa6wXOXu3BxaUyrg4+cW2Injfp+/g== X-Received: by 2002:a62:8f:: with SMTP id 137-v6mr31996648pfa.24.1539902895523; Thu, 18 Oct 2018 15:48: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 v81-v6sm38129268pfj.25.2018.10.18.15.48.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 18 Oct 2018 15:48:15 -0700 (PDT) From: frowand.list@gmail.com To: Rob Herring , Pantelis Antoniou , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , Alan Tull , Moritz Fischer Subject: [PATCH v5 09/18] of: overlay: validate overlay properties #address-cells and #size-cells Date: Thu, 18 Oct 2018 15:46:27 -0700 Message-Id: <1539902796-8382-10-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> 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. Signed-off-by: Frank Rowand --- Changes since v4: - create of_prop_val_eq() and change open code to use it - remove extra blank lines drivers/of/overlay.c | 32 +++++++++++++++++++++++++++++--- include/linux/of.h | 6 ++++++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c index 272a0d1a5e18..e20d8923f475 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,12 +328,32 @@ 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 (!of_prop_val_eq(prop, new_prop)) { + pr_err("ERROR: changing value of #address-cells is not allowed in %pOF\n", + target->np); + ret = -EINVAL; + } + } else if (!of_prop_cmp(prop->name, "#size-cells")) { + if (!of_prop_val_eq(prop, new_prop)) { + pr_err("ERROR: changing value of #size-cells is not allowed in %pOF\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: memory leak will occur if overlay removed, property: %pOF/%s\n", + target->np, new_prop->name); if (ret) { kfree(new_prop->name); diff --git a/include/linux/of.h b/include/linux/of.h index 72c593455019..1bb14a1f7227 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -947,6 +947,12 @@ static inline int of_cpu_node_to_id(struct device_node *np) #define of_node_cmp(s1, s2) strcasecmp((s1), (s2)) #endif +static inline int of_prop_val_eq(struct property *p1, struct property *p2) +{ + return p1->length == p2->length && + !memcmp(p1->value, p2->value, (size_t)p1->length); +} + #if defined(CONFIG_OF) && defined(CONFIG_NUMA) extern int of_node_to_nid(struct device_node *np); #else