Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1542738imm; Fri, 12 Oct 2018 21:55:46 -0700 (PDT) X-Google-Smtp-Source: ACcGV63SCH9Lj+YxmR31sxelyok5dG6ByHBeT7crL3p8vgm0BByovsotYSGpA2XKcC1icQLtX2gm X-Received: by 2002:a17:902:ea:: with SMTP id a97-v6mr8552494pla.164.1539406546124; Fri, 12 Oct 2018 21:55:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539406546; cv=none; d=google.com; s=arc-20160816; b=XTlZ+3U5FHp309wFRJV183NIjHlmbIiy3mJ+IYMHDx/wvxud9U/ga/nBRx1wJ8X6f+ +x/Z96dE/2azttVsnPEfDeF9jqZob8a8O4Tw0kMsiJ/gCZTQnddJqajKiwsKtav7P/KS u3h7yxxn03JSZHDJrjA/7r2U6/D5SmD7IFCfoLOIWijOG/Ux+/BBLpYEaH5Ro6o9Y3dZ 94S/NmzWUWZ9tbwyjfd2Ba9NnX8Sxxm1Li+JOEiWor0GYoOlEPr2tnW2xZjjcjXEJkxn sTJY7uF3YzTsMgsC8+DWum9B8+7H4RL1UYbsLLqMVaMIVcVo+b+hbdXoeVZUKCNPi5c7 Qy2A== 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=6jwtNAKUA0bImQ+OzjBieSYaakSLUGtiTllRPSG9WlA=; b=Km+zkLJMNkziKulNNFWGp65rZf7Bj4JH3OxLRpfBPG3AOnz8CNsSKBQCNR41MfcUMh AGDNWzyv5qWpiPynxU50fSa6x0pyPADQaLdWTe7uENORAwCS9HM6XdIoEibKKpIpfCaU +NyAEIPTubZWKbs1QtzLA+IaCe9/x9UyVtzyHqCL4HsUs8x8r7TGmdd9nAggGoRO/04u B5n6fUNOXOq5iLiDc9/vB/xuk0N2sl7+iMuS6HI72MrV3ZrPdTwMpmSDj45ojiTP5d5Y Qcypspz1c5+TVUQJkXuFDdIPuJu0/i6mUQUy5fGku2mOMONmXnWZVquBMFww0gvnbj+G RyPA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=MydkuL+k; 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 s19-v6si3453500pgi.324.2018.10.12.21.55.30; Fri, 12 Oct 2018 21:55:46 -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=MydkuL+k; 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 S1726512AbeJMMas (ORCPT + 99 others); Sat, 13 Oct 2018 08:30:48 -0400 Received: from mail-pl1-f193.google.com ([209.85.214.193]:45151 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726031AbeJMMar (ORCPT ); Sat, 13 Oct 2018 08:30:47 -0400 Received: by mail-pl1-f193.google.com with SMTP id y15-v6so6816481plr.12; Fri, 12 Oct 2018 21:55:07 -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=6jwtNAKUA0bImQ+OzjBieSYaakSLUGtiTllRPSG9WlA=; b=MydkuL+kvbcHS1s2I/c5iiBymR1vJcXEfrx9eRB6MsqaqBlxpv77t1V31NVXbg1+Q2 cBsw95pb83+KDWFQ/sVdbH9dNaBhnQEZJoeKR8j5RJ6CGXLyAkfPAoLfwtH6cv7F4mbV AkV/BMca5jxzMvSUe5pSB9p866bzhxxnstDmizSIB8CFotOaj5uggnURBA1UCzmq2DQM mBTzHABgnBLG/r78RD3iKc3483a1p1kCFRE5Nqtoy+7wPBKukYzwNpJAKvcf7hUQ/ejH eDBCNik1FszHiK7qaqH1V/SHTRmGUqC4N0wO7w6P7l8aWLrc03JqrAFD/Btu3FX540Kr fBkg== 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=6jwtNAKUA0bImQ+OzjBieSYaakSLUGtiTllRPSG9WlA=; b=XbVLNiMqbVLGirXgTBOmxJxfJUo87OC9Bkaucgc/2PkJrLuF5ustmlLGTdDtcMcWLM qlAFsTq730shvWjcha2BTPj6Uv5mWB5MiHxFIjj2MZlY5IrVXWgd6UwEFtHOE79bDm+Z JLfkZYOkr32k4UK3UQJL+uujl53Yko/lKMKTMAYWVrwE1cozA9A1lI29+FaG8+hzfbf7 2ddD0QNrZUrG9reZeLUorIpL80A0LZBaWePEfYkTiD+nXWWVkkVlYUbR8NQ7mIKy5mPQ ARoobj6iznTWE017Jf4p3cUgFw+aVxyXYwuE2RinLWUic/nLFk/nW5Gs6siwdiPTKsyy YVIA== X-Gm-Message-State: ABuFfogpAlnF1Kx9hm0alZ/39DrT6ThZyKpB5bcRaadQJRyC21tdutEL P+Iy1pyqWngr+0BU7S90jYU= X-Received: by 2002:a17:902:5a4d:: with SMTP id f13-v6mr2083052plm.114.1539406507004; Fri, 12 Oct 2018 21:55:07 -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 h87-v6sm6959462pfj.78.2018.10.12.21.55.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Oct 2018 21:55:06 -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 v2 02/18] of: overlay: add missing of_node_put() after add new node to changeset Date: Fri, 12 Oct 2018 21:53:22 -0700 Message-Id: <1539406418-18162-3-git-send-email-frowand.list@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1539406418-18162-1-git-send-email-frowand.list@gmail.com> References: <1539406418-18162-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 The refcount of a newly added overlay node decrements to one (instead of zero) when the overlay changeset is destroyed. This change will cause the final decrement be to zero. After applying this patch, new validation warnings will be reported from the devicetree unittest during boot due to a pre-existing devicetree bug. The warnings will be similar to: OF: ERROR: memory leak of_node_release() overlay node /testcase-data/overlay-node/test-bus/test-unittest4 before free overlay changeset This pre-existing devicetree bug will also trigger a WARN_ONCE() from refcount_sub_and_test_checked() when an overlay changeset is destroyed without having first been applied. This scenario occurs when an error in the overlay is detected during the overlay changeset creation: WARNING: CPU: 0 PID: 1 at lib/refcount.c:187 refcount_sub_and_test_checked+0xa8/0xbc refcount_t: underflow; use-after-free. (unwind_backtrace) from (show_stack+0x10/0x14) (show_stack) from (dump_stack+0x6c/0x8c) (dump_stack) from (__warn+0xdc/0x104) (__warn) from (warn_slowpath_fmt+0x44/0x6c) (warn_slowpath_fmt) from (refcount_sub_and_test_checked+0xa8/0xbc) (refcount_sub_and_test_checked) from (kobject_put+0x24/0x208) (kobject_put) from (of_changeset_destroy+0x2c/0xb4) (of_changeset_destroy) from (free_overlay_changeset+0x1c/0x9c) (free_overlay_changeset) from (of_overlay_remove+0x284/0x2cc) (of_overlay_remove) from (of_unittest_apply_revert_overlay_check.constprop.4+0xf8/0x1e8) (of_unittest_apply_revert_overlay_check.constprop.4) from (of_unittest_overlay+0x960/0xed8) (of_unittest_overlay) from (of_unittest+0x1cc4/0x2138) (of_unittest) from (do_one_initcall+0x4c/0x28c) (do_one_initcall) from (kernel_init_freeable+0x29c/0x378) (kernel_init_freeable) from (kernel_init+0x8/0x110) (kernel_init) from (ret_from_fork+0x14/0x2c) Signed-off-by: Frank Rowand --- drivers/of/overlay.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/of/overlay.c b/drivers/of/overlay.c index 1176cb4b6e4e..32cfee68f2e3 100644 --- a/drivers/of/overlay.c +++ b/drivers/of/overlay.c @@ -379,7 +379,9 @@ static int add_changeset_node(struct overlay_changeset *ovcs, if (ret) return ret; - return build_changeset_next_level(ovcs, tchild, node); + ret = build_changeset_next_level(ovcs, tchild, node); + of_node_put(tchild); + return ret; } if (node->phandle && tchild->phandle) -- Frank Rowand