Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3848400pxb; Tue, 17 Nov 2020 05:19:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJwhoJBdfNSfSyPwt5PEYwVmUpqbFyOZWcigJSBZ6P3KvyX4P42g8KBPGth2uIY69QFTycO5 X-Received: by 2002:a50:e087:: with SMTP id f7mr8526606edl.29.1605619157975; Tue, 17 Nov 2020 05:19:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605619157; cv=none; d=google.com; s=arc-20160816; b=rciDPkc/gd7+/cnBSWquDeaHuISD6XI6OD84++tQ4MgJOxbKzAO/DaJtXZqgyH+2oe 4KcJJrbDF9QrOjB/GVDaWJaSdKAMMqtyEOWZ0A9PdqfLg+pqMVyNiGy18kkp76/exS3G NsMec+LNS8M/MoOGEvhbj8naA+TMTC+Zfps13InEVEF9TE9TO3mec04sGbvaXO4NAwZt f3ZPBCQ+qWwFZaBES4BnE6sgfsWQ10QuhmpodWwtPjNKSwGHPBpL+113zXWITsM2kijz yRXbsyTjDH8yOEcpro3u4hkYBN34uuPd8/gdVZMa9t5YBhEDmFQBbp7s/ZYdA99k37EJ wcwA== 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=GHTEHlZ+Hx5U6fdoLZbkreyfeK6L1h6pFYZNNVjhla8=; b=F6Bd9QmU9ay8AL9zovCjOlIg4lg6tA2DrLcnw6Eeu01fp3SfwoM6XKYDkzXO6Io5oo MPrniUJK73qQ5UzggGbceO1XpxWqLZTd6YR++uTSyf0mNO1aPGUqhfPW29ciqHO55R8j 1Eoh1DLNUwLOODdAneMDqrRPH/0H0ZDDXi2ogiPuq941sXXKBVwTuBeW8lCqfyXlzpVk Tu21CqzYWgSxR+8XeoQjEBYOWEBmnvjS9mXhmyTXkVtYHVUXIEK7UuibMa7EJ5QU1qSQ jH1JXwXWonB0NqXfMm9T1GmHBYXlIn/YFK2IrUVYpwWq/lAZSpCkC9GlG35bRyME02mD 3Qtg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ym0a9jDG; 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 b6si14196326edv.126.2020.11.17.05.18.54; Tue, 17 Nov 2020 05:19:17 -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=ym0a9jDG; 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 S1730308AbgKQNQ0 (ORCPT + 99 others); Tue, 17 Nov 2020 08:16:26 -0500 Received: from mail.kernel.org ([198.145.29.99]:48000 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729505AbgKQNQP (ORCPT ); Tue, 17 Nov 2020 08:16:15 -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 B457C2151B; Tue, 17 Nov 2020 13:16:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605618975; bh=i1ldFHBKYHtg3JHHz1Tz+b5dbxYVY1DiiT30kpGx7PI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ym0a9jDGHgvV59gT7NcdYRHn8G8FHgPRfMH9NsxKn7pF0gtNXzT+o8IwhBHNxCDlk GFIy1lpLLEV0gyF0aTNFl9WFP63HBPFrwscfEr42PokxEtgfOcGt2Hwy5ZKy3/QwAU 7feup8qJqNoNpngpk5+rnXzEou7pGCfVuWTuHslQ= 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 4.14 41/85] of/address: Fix of_node memory leak in of_dma_is_coherent Date: Tue, 17 Nov 2020 14:05:10 +0100 Message-Id: <20201117122113.030990829@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201117122111.018425544@linuxfoundation.org> References: <20201117122111.018425544@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 456339c19aed7..94f4ff22044f6 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -899,11 +899,13 @@ EXPORT_SYMBOL_GPL(of_dma_get_range); */ 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