Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp633686lqo; Fri, 10 May 2024 09:51:10 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX60UDCIEwgyhsAnAy8TMRqHKuTPAEswNU4hZ8OaFJp/ptE97p/n4NQlPBquOAggqBoZIqAWweehx/KPP8L+kL2bDmpuDFSvhWf7JbQgg== X-Google-Smtp-Source: AGHT+IFjsJNR8TcUcPt9GJ5gUpmUXE/0cQr6dL63xfOQrdAAGj+VbijVHvP+CEiq3Q5dlQdSAy55 X-Received: by 2002:a17:90a:b794:b0:2b1:faae:36ce with SMTP id 98e67ed59e1d1-2b6cc758fb6mr3152835a91.14.1715359869773; Fri, 10 May 2024 09:51:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715359869; cv=pass; d=google.com; s=arc-20160816; b=ywVDuQXEvMn6eYGP+7GSqvaknJ1koJWjl44mFabnLxPu8+bsWB3OjQKhOuFXNCbfcZ 0sGRS1gcVgpFdTwlFZ5R6OuhnaU532ycpPud9UmbOovyHgIpBTRRAei111dttZ6ebrXY ADGiKUkN/XQ5uMZvLgpVgGq/KFeDNt13pbGjB8jqIBLVdXerJEqUMOY1hb2ijURyngQA WMZck7gFVnd9GCZtMsbEDiaPhzuqnzPX5lWX+OuOEfKRTL+Ydc8CIU62/dX+3O8zwVH6 McM/y5neoRpeVbS7eArrCNUDF0pwKKxg6MEZG3lZVto4hVyodBXeh65eiGZGDTsOOD5L 6F8g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:organization:references :in-reply-to:message-id:subject:cc:to:from:date; bh=2sPfYKySAbUeYAwrObIDjbKl46+Tq8eeHq7aa7NbpsQ=; fh=55rHtnTnGCux3ZAl876AoPkzVL+WuxIc4PPHgVpf4AM=; b=eXBo5pVi6SeuWMLHGFuZl1keg8j0VXPGAy0/K8Ey+iG4ZebNH+pos0hncyF0uI7fZO M9KyH3U9/xPr8Olrx0sYsDgEueDgRU8WBl5lLfBGcyD7GbCnYJ9+TGIb4Bcy51eIro+u QdvGrgLRxp2eFMgau4v0QDSEk/IFiD2jN5RAuSS17uXOXkZ7y3ra6Ek8ZcG8JXH01X7Q QRRhnJWxU5Zz9BiUcDVQIdv986L1X3KLaa6qnIcK4FV9b7ddxkAq1KrWr9eu6CFJl9HG d5nKEN22CFwYgD/tJ7q8wSgj4nuvhR23Lfkdi4wtPpho8DRz1U6wZpuvZNxjPQgYPA43 r0Hg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-176031-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-176031-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2b670f592a8si3972405a91.67.2024.05.10.09.51.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 May 2024 09:51:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-176031-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=arm.com dmarc=pass fromdomain=arm.com); spf=pass (google.com: domain of linux-kernel+bounces-176031-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-176031-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 8668F282CE9 for ; Fri, 10 May 2024 16:49:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C7B3117995; Fri, 10 May 2024 16:49:46 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BDEF61429A; Fri, 10 May 2024 16:49:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715359786; cv=none; b=Vx0jpzu/yRWfEcoIMokKZo7IyaFxXeJR7NfCWkZ4d8U5/h0keAlQWNQLS86KT5kRq1eiEWBlnQsYCcZUoNcYWfYpYeRAV8ekLHbmPrKGUEuxtaPoQIHSOR+wPWZbhhF2XoYtJQc5TaVsGG3SnlPjPQn7tU1+UD4SNcnfi8metQA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715359786; c=relaxed/simple; bh=GbCNIFOQBJPFUW1zv45XMBiGgvlwB+enNPlomZb/ubM=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VniAdTsPC1j4hkiQ964whJ5oVAHbTU3ZXwomszffxZWWkqWeXTvl0EmuULZL8lsWLzDo+s37Ng7+iQlbSQFS+DkNJWz6FJ/qteyc648sQeqe4d4pFAeX8YFtU1U/nQ05USKirnGJIP3TYSCMF6CTpqPGD1035ZIvxail0bR3joc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 58A4A106F; Fri, 10 May 2024 09:50:07 -0700 (PDT) Received: from donnerap.manchester.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6F42B3F6A8; Fri, 10 May 2024 09:49:40 -0700 (PDT) Date: Fri, 10 May 2024 17:49:37 +0100 From: Andre Przywara To: Javier Carrasco Cc: Yangtao Li , "Rafael J. Wysocki" , Viresh Kumar , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Jonathan Cameron , linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] cpufreq: sun50i: fix memory leak in dt_has_supported_hw() Message-ID: <20240510174937.0a710104@donnerap.manchester.arm.com> In-Reply-To: <20240503-sun50i-cpufreq-nvmem-cleanup-v1-1-0a2352cac46b@gmail.com> References: <20240503-sun50i-cpufreq-nvmem-cleanup-v1-0-0a2352cac46b@gmail.com> <20240503-sun50i-cpufreq-nvmem-cleanup-v1-1-0a2352cac46b@gmail.com> Organization: ARM X-Mailer: Claws Mail 3.18.0 (GTK+ 2.24.32; aarch64-unknown-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Fri, 03 May 2024 19:52:32 +0200 Javier Carrasco wrote: Hi Javier, > The for_each_child_of_node() loop does not decrement the child node > refcount before the break instruction, even though the node is no > longer required. Ah, thanks for spotting this, there is indeed a leak. Sorry for the blunder! > This can be avoided with the new for_each_child_of_node_scoped() macro > that removes the need for any of_node_put(). Wow, that's the typical convoluted Linux macro, but it looks correct to me. It would call the put even if the loop ends naturally, but there is a NULL test in there, so that's fine. > Fixes: fa5aec9561cf ("cpufreq: sun50i: Add support for opp_supported_hw") > Signed-off-by: Javier Carrasco Reviewed-by: Andre Przywara Thanks! Andre > --- > drivers/cpufreq/sun50i-cpufreq-nvmem.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/drivers/cpufreq/sun50i-cpufreq-nvmem.c b/drivers/cpufreq/sun50i-cpufreq-nvmem.c > index 0b882765cd66..ef83e4bf2639 100644 > --- a/drivers/cpufreq/sun50i-cpufreq-nvmem.c > +++ b/drivers/cpufreq/sun50i-cpufreq-nvmem.c > @@ -131,7 +131,7 @@ static const struct of_device_id cpu_opp_match_list[] = { > static bool dt_has_supported_hw(void) > { > bool has_opp_supported_hw = false; > - struct device_node *np, *opp; > + struct device_node *np; > struct device *cpu_dev; > > cpu_dev = get_cpu_device(0); > @@ -142,7 +142,7 @@ static bool dt_has_supported_hw(void) > if (!np) > return false; > > - for_each_child_of_node(np, opp) { > + for_each_child_of_node_scoped(np, opp) { > if (of_find_property(opp, "opp-supported-hw", NULL)) { > has_opp_supported_hw = true; > break; >