Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp2489443imm; Thu, 18 Oct 2018 15:50:38 -0700 (PDT) X-Google-Smtp-Source: ACcGV60yudFy6CScJITkNGmc5ISYpKgKgdBKUMQ1lITa3ZDVN+AkiyKEase52zBbjleJLmL15I4S X-Received: by 2002:a63:9742:: with SMTP id d2-v6mr30327860pgo.278.1539903037947; Thu, 18 Oct 2018 15:50:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539903037; cv=none; d=google.com; s=arc-20160816; b=RhedDiuOlXipOb/VkKZPe2TWtt01egvQciAYfcpUZYWZUKe8qeLGTAFJm6CnjgOCvk jSfF5GqE6PBwZowfNE098VQEE9sU/fwf9XNj+C1iE/0eskQMHayjf2INFVkpOsP22oCB UfarbZ8ndjXnenmycWAOlZmErO9oHWwnNo/iwie4+3vYyXaINSQMkpooSTBcOv+PKnax 5yMHG/UXA4avGZAEFRm1+8tOyVOCNjvurmq66EX18FepTwgwAY7K6q0nWaloIbl18Woi WORGvGDNjHBQbJEa4by7JHGgGtIL9RVc1CbGuBOJ/bc4UbT5WsNBZ38RviAVdpsps2vL FH0g== 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=3p9z0Ehj9iwgF9Lhv52flr3WKpZAxs8EQb4W3gnL4wU=; b=KGIh0mKZHjUhL3AaldYYeT0ERc+M4TUHoGD9FF5aXwtQVKRoGleLdNBORT+QXybGil MH4n/qbdR2G8057WOVS2c10MZamApCidz7Z6SlJCDaSKYLPTKBLVo9/l7M91xHr/8ePe +dv6e/rnTBiYBqPFJ9jae27Soj6ZEZki9nqw0nHd2b9KwJrtbypBPWj/pgrA0dnMpOhJ 3GzFTp6vDv90MXd6pzMpYGTtkh5Tl1QYlEBTrEfaesWzU89uKBMyFfOqjz+zYLziZOKn SIwTaI3DZRM4UdKJeUdv6bH0ubEIjjRwQszAKP/buq81/2ZULbifgz3/1IyPuFoqarsP ccQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=HZR4PRXS; 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 c14-v6si22323339pgm.556.2018.10.18.15.50.22; Thu, 18 Oct 2018 15:50:37 -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=HZR4PRXS; 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 S1727613AbeJSGv0 (ORCPT + 99 others); Fri, 19 Oct 2018 02:51:26 -0400 Received: from mail-pf1-f196.google.com ([209.85.210.196]:38860 "EHLO mail-pf1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727474AbeJSGvZ (ORCPT ); Fri, 19 Oct 2018 02:51:25 -0400 Received: by mail-pf1-f196.google.com with SMTP id f29-v6so15558995pff.5; Thu, 18 Oct 2018 15:48: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=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=oJXaTuH1hTOHoGg1bIced/mVvMEJXBjbcsYacA5Km9pvx6Ki64qxC9l7Qx/+dXk+4l kD+Huomme1S0KwXkdqLHk6Ux91Lz4aIDk3jhzJHfYhMtlHdxCuirRvH3OLgCkHfIM3ds NTTgkpTHuyZ5Iq2xpOol4mdwtzjWjWo/hevDmfUZ6T4IegbCJ+L7wYhl/wlzvyq1QvhH NGJsZ7IYUxs9vp6GAeZ276z4gblUzmgbsVINyfODdmLmXezNxR4EjTrcovFfmgT/8xgD 8HmkC8KW3MLJrUAs6C9rseBnROs2EaiP0qPhzrIWulR/aiqqwZxota6h6DkFCvn24kTf 7fAw== X-Gm-Message-State: ABuFfoh7W1qSmSJFHqK2RDGqbpnf5Juqo+NJh3ctXmKSsxkFU/yQM1Cy Ki1rz5JL/EwMRXF7BoNQ7no= 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 Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, devicetree@vger.kernel.org, linux-fpga@vger.kernel.org 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 -- Frank Rowand