Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp3852153pxb; Tue, 17 Nov 2020 05:24:39 -0800 (PST) X-Google-Smtp-Source: ABdhPJzqs5jBwXQMf+SZe4f9MWNuNenkLbYAsBZhF/soa6J+yj9l33yjPKzGSlFJ8hZp1EkBsrZV X-Received: by 2002:a05:6402:396:: with SMTP id o22mr20965535edv.34.1605619478709; Tue, 17 Nov 2020 05:24:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605619478; cv=none; d=google.com; s=arc-20160816; b=TxJyfw+CMzs9ZbQCyxk2ye+yRRQOKrSHTSpLzw375EsSo8BelAgQB/SIXh+0ZMfFUb Ko0SbOTp4IkcJa3qHk/U+3lZQK2BlZytCbGAzf20hWJmA9U8PALII9gVufYoDJuKnOSd hzSRtJHatqta9HYT5svji+lztqmwGJ+6eGx3imZ7Ifa3OUGJOTEqTCJKGua6WOeWpRiD 5ZycwJbaF51EFXs1c/RmZyOI3SY1EIxLfiZnNCGAk+ZhLfoEEChgaviz3mNR29OuPOEi i+Zk/YDuQAZg91I1rTmV8heC/4thZiTXfJvkRxqsHLXMtWA3R/DbTgILLgYJxWtKw1XV Czmw== 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=k+jGe9rfp5nRPgMyt2wwnUYNxDJyFn6MrFIUiAv5NXE=; b=ngUTu4M6oxMqhdll1naOMUmn0yVfiptAD/+LadDO+Kh7mdqla5jq3/pDoF2bL1U6A7 7f308hdpbvGL1Yl6z1p+u0tgIbFoV7ZFqVcmhdEs2CTM0F3BZxI3HQxMziqRbiev9Nuz pyrrWGa65oRGKDiiczamHRLWNUEYNuTWhTofnNB+uPpyfpWOrp1GfUlQowpU2gtI8Y8G pSueVKX4PnsEG3T83HtGjYwzHBTTdvNwuAHAMo6zPxP1jBmk1Tgi4t/499zBszU9HteI S0XDoWjB6Dl7uc9HypsLb/aDrpDMYuh/SaOX3G8TU6qpyefUDuQ4DgnFvGZaEdzOsHu7 zBiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=sURCy3CM; 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 oa23si1278878ejb.707.2020.11.17.05.24.15; Tue, 17 Nov 2020 05:24:38 -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=sURCy3CM; 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 S1730470AbgKQNUF (ORCPT + 99 others); Tue, 17 Nov 2020 08:20:05 -0500 Received: from mail.kernel.org ([198.145.29.99]:53336 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729575AbgKQNT7 (ORCPT ); Tue, 17 Nov 2020 08:19:59 -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 57A8C241A6; Tue, 17 Nov 2020 13:19:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1605619198; bh=QhHr7M29daAeMk7vkOkFo+ezbF6jU7vpB6jpsy5pCOc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=sURCy3CM6knfEbzPkHL9uo0/UOR/HTvBA15gVb/zLhh9DCTAGc3X+xSCuLrZZT3i3 iybJBvQ/zZbYZc59nL+uQMbPGnvsnGoeDwgSudr6bGTGutntwkpw7ZZ0I6uY543GJ9 sIaKwL68ITf1KKjL5sKKuJlWBn8u7zhQbySFeNqk= 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.19 060/101] of/address: Fix of_node memory leak in of_dma_is_coherent Date: Tue, 17 Nov 2020 14:05:27 +0100 Message-Id: <20201117122116.028079051@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201117122113.128215851@linuxfoundation.org> References: <20201117122113.128215851@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 c42aebba35ab8..30806dd357350 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -975,11 +975,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