Received: by 2002:ab2:6816:0:b0:1f9:5764:f03e with SMTP id t22csp2309091lqo; Mon, 20 May 2024 01:26:53 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUIgIA1mUU20lFljnsnAIQWTzb8+aGQktg1kPjWNSe4PUMLXLchm1+jegtJp2/2k798UzoqFQccvYJas4zXA1Vih3VeyDmze+lI0qgHNw== X-Google-Smtp-Source: AGHT+IEZotf35BVSkX0ErJeCnJH3V47qsahPJd10eB9ST70K1YSFlXMjtAqMg8GEev/Zir3AegDs X-Received: by 2002:a05:651c:149:b0:2e2:9842:a9d3 with SMTP id 38308e7fff4ca-2e52039dc3emr231026361fa.46.1716193613024; Mon, 20 May 2024 01:26:53 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716193612; cv=pass; d=google.com; s=arc-20160816; b=W34NygaNv5z0gfWdwnJJXmJHqMjTJ5aO8Jo3jYY9/l5miC/BHfs/t4E1gvEv9Gh9V5 2vjHpQlvKLbEwDUqjvGJ86vFkEgC9wRFii5BD46bVDZBH1F88A9iz8ajSkcIqQYyIt/+ d3q2PvwUavCBp+Pv41IYWf3+Stl6tO7T+9Egl+qtd2kjjH21IKgnGYBbrB7I8bfpisyT wTCe76UEOJV9vOylL1P8F/6DouQnzxjTuIWsJZ1Q/x9JK8NUkdl5Y3ePWGUi1FAXwlHE eHEZ567ytXfnb0c73ZbyDafCnDF+iUR/3PBO+r5TprTSype5aPixM7gne5uoDD2xPub7 KCIg== 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=PgHTq65DrJGic7bon6l57761rXs2Dti2hFWQrL6igNs=; fh=H+MOBZ/LSCWxSVnnfCUcMOHGBBdMNA39026g/Aw0AUs=; b=oYJpz9the92QO6dUup8B9VfFhjLe6tX34IzReXu3I5CXkR0hMBaE4SC8Q+l+TTQYtd ZD/MntVTIPE4vqX8dgjD0npI6If5Gcauyhckk6yI01Xp5qHENc1XizptLCv7VcJTzsmP ghvumMZtnyd/TPq26R+RG2IlSGQmQNM2nf9xMIwbVXNl2UCj9PwzHqAlZATcrXJS1i/E iAR+UFctc63i2xL8KytM67sTSJ4Xpi/1D6b7hVhvyAZArhmRWRvm5QGK9JDdzmqJk6Kt oUpfY855o5jYGi1tgecZg2Abjv5d8zoDrMi8GTSQFn/F7iSSSa9uDJsD9fAl6EzB0JTv Ucyw==; 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-183493-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-183493-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a5d443adbe9si273823166b.849.2024.05.20.01.26.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 May 2024 01:26:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-183493-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; 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-183493-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-183493-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 am.mirrors.kernel.org (Postfix) with ESMTPS id B98EC1F21584 for ; Mon, 20 May 2024 08:26:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EAC981C6A0; Mon, 20 May 2024 08:26:45 +0000 (UTC) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 545E0182DB; Mon, 20 May 2024 08:26: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=1716193605; cv=none; b=RvZwSEYbGbs8gHiBfPGwoRO31B/pPaybWHT46Ynpq4hCx8Y0G5GkszZZ7nUJx0dM+S5lzS2VwKMiQtJYJfMogfncJTF258wds181J4DEBvu4hH6LFOd20Z/z+kNJN4W5mHvspTNipAL20xFfNccQ6ISN9lpgbtBGNysw+tOTlfk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716193605; c=relaxed/simple; bh=0dPuaAUfJq5Ff9j1D+i4NZ2UxHkBIoSc3A5G/S0n7y0=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Y1DtENN3Yy8tu1yD5NLV2ARbWWAj1GOp824sUTZfaIIYpRhwFsV3cDjSJy7oni+OYObltOnoxA9iwv6z/ZRLi/gTlZmgLtmWgpx5zs7qAcYDoV2J+xVL2fq37pdIqgzaFyRpOZWHc4rV3pAF415YA8LaLUYYrG0a4qlQkXgOinI= 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 6AAF9FEC; Mon, 20 May 2024 01:27:05 -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 D09223F766; Mon, 20 May 2024 01:26:39 -0700 (PDT) Date: Mon, 20 May 2024 09:26:23 +0100 From: Andre Przywara To: Viresh Kumar Cc: Javier Carrasco , Yangtao Li , "Rafael J. Wysocki" , 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: <20240520092623.6ce850e1@donnerap.manchester.arm.com> In-Reply-To: <20240520073339.rf6laivnglmww3bf@vireshk-i7> References: <20240503-sun50i-cpufreq-nvmem-cleanup-v1-0-0a2352cac46b@gmail.com> <20240503-sun50i-cpufreq-nvmem-cleanup-v1-1-0a2352cac46b@gmail.com> <20240510174937.0a710104@donnerap.manchester.arm.com> <20240520073339.rf6laivnglmww3bf@vireshk-i7> 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 Mon, 20 May 2024 13:03:39 +0530 Viresh Kumar wrote: Hi, > On 10-05-24, 17:49, Andre Przywara wrote: > > On Fri, 03 May 2024 19:52:32 +0200 > > Javier Carrasco wrote: > > > 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; > > Why is the opp pointer removed ? Because it's now declared *inside* the for_each_child_of_node_scoped loop below, courtesy of this new macro. The idea is that by doing so, any "break;" will exit the scope, triggering the cleanup routine. The loop running till "the end" will also make "opp" exit its scope, triggering the same routine. Cheers, Andre > > > > 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; > > > >