Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3868438pxb; Tue, 17 Nov 2020 05:48:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJyxgH6gByLfkwxuiZeaqRSexXTt9MgnPZiuafAzqcGvhD326XH2aYF/g1uHLiY8kFVLvOGS X-Received: by 2002:a05:6402:1542:: with SMTP id p2mr20427215edx.298.1605620915141; Tue, 17 Nov 2020 05:48:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605620915; cv=none; d=google.com; s=arc-20160816; b=OwnlOyIZYo65Il77DAktgXY/AWvfkPx1+vhAaPN3robmU7ckweHqQKDALKVOWZBD7i tqz6CBDBTs5waPlD0W0W9SH6bR/0166YhTsdiIyWJIgpGp5HDYKVA6ZlzFJy9w/L7kp+ vJJFmm12eRd2gp11Gzxcf5cFQtY4UKaTytSiom5KQBJdjeKaDZVpbm15rWEhrFy4uqMq M447Z3fN3qvWJP+19ALSgwCgRynihXP/2mSW3s4JXLkSA8CD54BYlSD7ogUIy71CQVE1 2aPrsYWYOjq1SDQOsPm4nBvqp/KdMoG8VkRZHkMlnHKPKECcYrGGuXzxntNOhcVOdnua 3Dew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=WFUuRtwvMoxXZfjiWMGfFSoEpg4VGdJzQPefMbQzdVE=; b=Dy4csTq6k0+nSxQvTYTI9+ZCG6lmjFH5nYt1iTZM8PiDJtkVqqR4kg0Oka8aQo2GJE TS84IdxsQ6PHqVJ8zLv9FlhLrJD+r4WWSLUT8UAL33fOgEv5X5Ktgu79eiPVRyvEdTFg XHxig4V07uMnT6EgYEdrfmW4wMLCH+2n/A3TeshEaSP+sZQctKKE10FRLVndgsbR05dE c/CXEFCBqEfvK9eU9Wr4UgCYpNdA7gkGZrS21sx39qIV+R+8G6kWQCNxQbQYDmX3q9Ov SkqUZOdK3q6sLz9IpxHhS3qdPiXGyjRNlsnQQqktg1pRcSKpl70WKRQlmvKKIrWm/V02 TkWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ej1Hz39s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k5si595445eji.617.2020.11.17.05.48.11; Tue, 17 Nov 2020 05:48:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ej1Hz39s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733003AbgKQNqW (ORCPT + 99 others); Tue, 17 Nov 2020 08:46:22 -0500 Received: from mail.kernel.org ([198.145.29.99]:49134 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732989AbgKQNhw (ORCPT ); Tue, 17 Nov 2020 08:37:52 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CE5A52465E; Tue, 17 Nov 2020 13:37:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605620272; bh=FLKBhWs9ZpMgIeeKx//TqHn6fR7JZ2pl0UdIwnGlBcI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ej1Hz39sGhCEF0i1nCYhdGJhDHS79zxAD9i9AxgYH3H0dPLGrVpM+HcXCCSeLhlwU KLJzqOrsrVSsv+rFR2O2gCseuaUPcn6KCGL6/iMyHMobwDoaHj8QtL7RkC0w1mFfaa 719IvnuodCIAEQw9HWh5Uv/FFCbbJCU6HCoFjV5g= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Evan Nimmo , Rob Herring , Sasha Levin Subject: [PATCH 5.9 164/255] of/address: Fix of_node memory leak in of_dma_is_coherent Date: Tue, 17 Nov 2020 14:05:04 +0100 Message-Id: <20201117122146.919134873@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201117122138.925150709@linuxfoundation.org> References: <20201117122138.925150709@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Evan Nimmo [ Upstream commit a5bea04fcc0b3c0aec71ee1fd58fd4ff7ee36177 ] Commit dabf6b36b83a ("of: Add OF_DMA_DEFAULT_COHERENT & select it on powerpc") added a check to of_dma_is_coherent which returns early if OF_DMA_DEFAULT_COHERENT is enabled. This results in the of_node_put() being skipped causing a memory leak. Moved the of_node_get() below this check so we now we only get the node if OF_DMA_DEFAULT_COHERENT is not enabled. Fixes: dabf6b36b83a ("of: Add OF_DMA_DEFAULT_COHERENT & select it on powerpc") Signed-off-by: Evan Nimmo Link: https://lore.kernel.org/r/20201110022825.30895-1-evan.nimmo@alliedtelesis.co.nz Signed-off-by: Rob Herring Signed-off-by: Sasha Levin --- drivers/of/address.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/of/address.c b/drivers/of/address.c index da4f7341323f2..37ac311843090 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -1043,11 +1043,13 @@ out: */ bool of_dma_is_coherent(struct device_node *np) { - struct device_node *node = of_node_get(np); + struct device_node *node; if (IS_ENABLED(CONFIG_OF_DMA_DEFAULT_COHERENT)) return true; + node = of_node_get(np); + while (node) { if (of_property_read_bool(node, "dma-coherent")) { of_node_put(node); -- 2.27.0