Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp188907imm; Thu, 4 Oct 2018 21:15:58 -0700 (PDT) X-Google-Smtp-Source: ACcGV63ltTbZmK5ZjH58w9vzHaEA/5XTW3IpNia2KBkf12n/a30YizhP3DbNAghbsN8bnVzYCEHF X-Received: by 2002:a63:cb51:: with SMTP id m17-v6mr8254838pgi.105.1538712958552; Thu, 04 Oct 2018 21:15:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538712958; cv=none; d=google.com; s=arc-20160816; b=pqDsukuy/0AccyB9pU0fcQrdu5gD4yrTKCqZv104BKhnHiFM4A3srnPwof1maFqRqp dfjxfmkN47mew2To2K/huxP9jZLNtnlmVO8y8inC/z9/2vd68frRSQCv0BrQL8dUjo4A 5zDzgrS6ZNBASXVpBWr9bjdEh4OwfZr6PK/8fcz1m+185NDyQ7ZzfRJ9Ta+wwHkOJw// lU7FxckSnT+TMl6UArOludv19bSNFePxGIJUWd3kbJQN5yyQzYpm1n+kMpd6H9nPJAOq 4pAzLf9LhDSz91blfhbSAl+z33soFzb/nVRFC8DOB5nO157E+GCWUJgWJlF2tt2yA0VG ZjJw== 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=x6RsE6B32jH9hlMthMfkJbAudeY/LWQ22o5761C0YKc=; b=X6R8DVX+6zDQan4e/PPzf4S/w1W+yn4JXPVLRn4KPBiRCWw11fXMKi+J/dMWGVfl8o pooDrw94lOihcXyNhJ2zwwxJbVzEhugPs/QrNat8f6+h/XEXUelZqVxN5CWsUv6BSgQl ydLYmoi4BJJ79514ZwdS0nwE3xDW1Lt97eLzknEmlUYFNLrIncYhY6lgVSn+myiYHVsN B18pdhaYPiwwVliSIp6eRFF2KAneYm7/1hTPj91jry+bhwNrlccsXGJBl3O8oUVchmjD 9sb2/lT77ij3VnyZgTuv/F3DHw95mtZFdfv967HU8Lb+KDLt5Y/g66FCWtB0YD9hNVf9 rePw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="Z/1SuIMs"; 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 16-v6si6425922pgw.208.2018.10.04.21.15.43; Thu, 04 Oct 2018 21:15:58 -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="Z/1SuIMs"; 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 S1727833AbeJELLR (ORCPT + 99 others); Fri, 5 Oct 2018 07:11:17 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:38758 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727599AbeJELLO (ORCPT ); Fri, 5 Oct 2018 07:11:14 -0400 Received: by mail-pf1-f194.google.com with SMTP id f29-v6so1571072pff.5; Thu, 04 Oct 2018 21:14:23 -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=x6RsE6B32jH9hlMthMfkJbAudeY/LWQ22o5761C0YKc=; b=Z/1SuIMsHvY4P/Wvq52yu6Tpz5748wuGfzI52GSTUidtdi6hgpVk+DFRGKvL0E5YO8 ojh4CpNk7A78xTPfQlqN3JIcQmzyvLBFn1KXpTuDrkF01NObrutwWejYXWfQgrO89JEo JPlxXLo0/Lp1IOgMtQ8KIeGa0lOZaPJUZyLTeFANuWL53JIqHrXGEXSW+Mnn3Vgx54/t wCt3Q4MGac8CHLt+dnMex21rhXpz/ZzK51w270PEKVGLYCsQ9TEvRRim/2UknR4dsm+v X//COZ1jj/xrHzV+HJUnoP9Bv3SH6zP1odpipg37FW4yK3fMx8bBWPS7zDJ+bRAJuAAK xXjA== 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=x6RsE6B32jH9hlMthMfkJbAudeY/LWQ22o5761C0YKc=; b=fc8jA/qauI1YNLe4bnLhJKbYDH58IYUzCzzzUta+8U+OsTCwM7jDHrzN9r6j1B88/M lXNtFcijk8KPhdpC7UAYK8ZXm/Pzi59752VC3aOOOQjRaSfu4d0nW/uB+jncZ6ltefuZ FWgtQ0BlIQxTqlv7xAvdRQI+nQ0t6+Hd2KDjqZbNByrZo0JTRrsLnGdJ7qwmNf37t1Sz cCt1HjK875pveiJPN0OlNzHPE+YyY31TiusHpKsgtVhEUpJpTSHLNFrp7D4lgrQpvF2s SYGgFX4qGOvUSajZePQ1Hyr4vJAGnBZHXAjKkcGWnNiCr0oaB5mbVUN6Z/tb7ltc1Hv9 qECg== X-Gm-Message-State: ABuFfohWobjXl22ppjEyyRJOxNzGjxuu2KR+vmw4C44/j9NCRzlgA2AD 3xGFXU55Q4PEO0zQHzaXmi8= X-Received: by 2002:a62:4ec9:: with SMTP id c192-v6mr9873713pfb.221.1538712863474; Thu, 04 Oct 2018 21:14:23 -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 n63-v6sm277975pfn.9.2018.10.04.21.14.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 04 Oct 2018 21:14:22 -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 09/16] of: overlay: validate overlay properties #address-cells and #size-cells Date: Thu, 4 Oct 2018 21:12:40 -0700 Message-Id: <1538712767-30394-10-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1538712767-30394-1-git-send-email-frowand.list@gmail.com> References: <1538712767-30394-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. 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 --- drivers/of/overlay.c | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c index 29c33a5c533f..e6fb3ffe9d93 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,39 @@ 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: overlay and/or live tree #address-cells invalid in node %pOF\n", + target->np); + + } 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: overlay and/or live tree #size-cells invalid in node %pOF\n", + target->np); + + } 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); -- Frank Rowand