From patchwork Fri May 3 17:52:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 794793 Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E704A158202; Fri, 3 May 2024 17:52:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714758761; cv=none; b=jyStyiTZKkz3woQ/T8uwvS3nEry16Pl90hlQe7QfIdg/+pwx1O+AcUYln8vp76B5JlaIVXd9oHXAU1sFyUiwyu2/1O5OT4WWXC00eYhnAa4FRlxeNHp+ce3t9hDOCqjT8DuB4A+JMdUTj+k388z7vAyDOz3zVATD1+3tYmHtpak= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714758761; c=relaxed/simple; bh=Mri5fTd2blYcQR3oWWDwHWSCOTzmuxEMWx67fmd/ZzI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=MGjKVyQTBPGIW5znjnKfJkIGaIsrM78y7vRTPDHUV2jLpwzNSWaw5ybdOZSsfpeEJnCBGBhWUez6VxjtOVWUn3KK76IthXTpedj6rjvZ1z5HMfDXEi6KAPsfSKhAxY36RZdnkReJeFWl+SNMj6ot8iZL0ISXh+6ev0BGe3Y9FKc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=j+1GCw2H; arc=none smtp.client-ip=209.85.218.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="j+1GCw2H" Received: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-a5872b74c44so1257015766b.3; Fri, 03 May 2024 10:52:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714758758; x=1715363558; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=hv8U88MGPjGVlknzKUx2MPXN0ijTnWvKrGGtFBeWuHY=; b=j+1GCw2Hb5yVK5bM43zhvseYTuP1bFc7kTCaZoySIAS6EvN3fZr+aXNPTapUnOqgUM PPT+hVuF6Y0CW8lwC2OgRrh534WF8xm2BxHAPXYzbRzoY77LJHKqwZLLs2afnAfws2bH F2GNQJaU/uqiCkY+mloD0Ebg7aMQWEYX/Int/eCaKzjTWiDX9yBs6Jr4KU9B2mA47960 3J2Y/6LmSFzTkI9EQJ/+pZXM5oOoIzD9Tk3LHxNmVpYflfkW+LJxI9zECCQnE7IA2V8x nOgbunW3uBsVY4cOypUYC1O+fDPHHwUgf3QH/9R0TtAVNfANq7B3t6izn1IUQwjpLLTF OQaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714758758; x=1715363558; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=hv8U88MGPjGVlknzKUx2MPXN0ijTnWvKrGGtFBeWuHY=; b=DDwvoEYMjv/vhesaXwDfDSym2MeUESt1yHjOAFSsHmU0+jnSiBRkwLxjIb7TdgMBid jKrTv5vaTVZYst3FeYx0inSvtTpRzi936pX7IHDrLDkAaWYpN24nfsa7r8r3Ff4hvUjl yHgbEmsVebPGJUiHrRPKZ+ICCronB7FGq90CT1zy48FjZaEraNdqL2qAQiQcPKgnZvqW vOZJ0SxZlVGwff2s+JcyROrZe8CChSp7JLglNGzuiqxX7+7OIGp9/BGzhwvjUDZyHBX2 6YGnIyqPxyZVGrA+vmXFpeaFtqSbIbnB6nFV0QBJTgbTLcrqRiNABB42Ojuk6aiRpo4O yIXg== X-Forwarded-Encrypted: i=1; AJvYcCW1ze0pVjZhrWJa1ZsEztA4dJJe3UAqiJhTx3Al64d5hKJUIifGu0mktbN1jGhHq+R4KvP49C3wSUXNegbBDTEf+zBeX8m75LkgeZmo X-Gm-Message-State: AOJu0YxefErl8kOeeXYF9QOtaoaqzKnWL8IwqBHGzHFRLwAmuZZQicXQ C0CdYU/k+w9uibs2Gbgsk4QtozrmpfA7S27VhTjevTkVZ9VA+mgb X-Google-Smtp-Source: AGHT+IFda4IBg1SIoYzq/bSKmyVZMSDW+3JXaIB3rFnqcRC9ICD1D1DRaJaPNDAiCVlEqa/qxNFdkg== X-Received: by 2002:a50:9fa8:0:b0:56e:2b31:b111 with SMTP id c37-20020a509fa8000000b0056e2b31b111mr2253828edf.7.1714758758304; Fri, 03 May 2024 10:52:38 -0700 (PDT) Received: from [127.0.1.1] (84-115-213-47.cable.dynamic.surfer.at. [84.115.213.47]) by smtp.gmail.com with ESMTPSA id q28-20020a50aa9c000000b00572469a7948sm1968368edc.45.2024.05.03.10.52.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 May 2024 10:52:37 -0700 (PDT) From: Javier Carrasco Date: Fri, 03 May 2024 19:52:32 +0200 Subject: [PATCH 1/2] cpufreq: sun50i: fix memory leak in dt_has_supported_hw() Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240503-sun50i-cpufreq-nvmem-cleanup-v1-1-0a2352cac46b@gmail.com> References: <20240503-sun50i-cpufreq-nvmem-cleanup-v1-0-0a2352cac46b@gmail.com> In-Reply-To: <20240503-sun50i-cpufreq-nvmem-cleanup-v1-0-0a2352cac46b@gmail.com> To: Yangtao Li , "Rafael J. Wysocki" , Viresh Kumar , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Andre Przywara , Jonathan Cameron Cc: linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Javier Carrasco X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1714758755; l=1326; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=Mri5fTd2blYcQR3oWWDwHWSCOTzmuxEMWx67fmd/ZzI=; b=udeaJHPt5rHhF46vbOWjAj99SPixn91bwWQoY9RNNRD/rc/kOQ3iLjl9RVmcNade0FxgOeYLv Xx9Nip+KoJxDW65l/77GOlzgmH9ZN45UEINZI5sCgACTRCbPC02afj6 X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= 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. This can be avoided with the new for_each_child_of_node_scoped() macro that removes the need for any of_node_put(). Fixes: fa5aec9561cf ("cpufreq: sun50i: Add support for opp_supported_hw") Signed-off-by: Javier Carrasco Reviewed-by: Andre Przywara --- 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; From patchwork Fri May 3 17:52:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Carrasco X-Patchwork-Id: 794558 Received: from mail-ej1-f44.google.com (mail-ej1-f44.google.com [209.85.218.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 76C02158219; Fri, 3 May 2024 17:52:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714758763; cv=none; b=ErlMyvl619DK31vKE543BjtUqNNIBrfHXke6DIChK3Va1gRlR/28pcsqhZruYNGdpJexeY7nyfHPoAzQxSOOefcaRjxvU4FxH9gI8k+DZ6gHfFa98h9JDMZPLNxRt6uLtPxwXDFvcbfuJ4rRZ6C8XyuRUyrJdFaU3CKVffzsjTo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714758763; c=relaxed/simple; bh=lzVnrSjci3YdZbJDcigjVDnutqYD0vEbfrujcq5AHHs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Kx6rgwmJDiz1z7RcsAdiTZLNOOY2vlw52ChjQ1R64gapawoNZS9Cctckp0WGy6RGtbDzpp119WXmcqEl7LNFjK8y+R0ld03VVkcBYjSp5LzZrZVN14jIzkZ8ml5c37wUL2S91/uI4te3xzENHr4o+Y6CMNyiW9JX5C/o9bRRwG0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fHBnhkNf; arc=none smtp.client-ip=209.85.218.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fHBnhkNf" Received: by mail-ej1-f44.google.com with SMTP id a640c23a62f3a-a5894c1d954so462406166b.1; Fri, 03 May 2024 10:52:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714758760; x=1715363560; darn=vger.kernel.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=nDa0e4iujX0ACKE4cFSjYtiiXZ+21EvsOzvNajBTvcI=; b=fHBnhkNfFgY0EOvMbeVCSgUkK7B04ewgHLaKvupBI1FHbml3mOuJNEtp4z3KnDfxnP q/kpD0T4HiVuwFL0hzy/8ZE73zCE3GgCyoFHSwTqzKksgDaMMNnLm7kFmEHveYVR5Src YXEmQyX5QUeLdOF5PQ8IsAyZ6QXAPeue/CP1RzyBIg2hZYlVNhpb0Pm2ab+X6946Y+an x9LMs8Tnwo02wbyE+f8xZQQLQdkv1XJVdJ6N3fdMRQxPd6fU8rl5s1h4axpsQAkYCDCT h/8VKiGbPhwq56kNy+kXIdjb6pvFeQwx72K2b75ExFzx+K7llCFwQH68VOTtfKfSFU9o gkqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714758760; x=1715363560; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nDa0e4iujX0ACKE4cFSjYtiiXZ+21EvsOzvNajBTvcI=; b=LEAj6ZkKB/Gzuip3jB6vw7KmUtWNXJb/CnZrFKXCl53KJttPngkg6zRoUdkNqEyEsI FncKm1W2eqF38E3HUDbQffM0tPOtwZ8c3/MqfHwQYspzZcneeQTMiuKmtQZZL50ocqdN 9L4NL5nrZfivnMGMUGzUU9r1T+dOqUSRVihH3Rt48iOeR+XHcJ0mTcatMXKiU5gPQmzV l5YrsJPl4tAgBiftbHy7h/CUlVjvKGZrUhGP3ke/Cuisj9suOMzSOIEEwiN7qCSfFmHn 4qSPIaPz5b8VwplAQf25mEjQtJdo251Fu8LWaaU/9/kHVZ12d5HlUVfnC5Vl6CHA9z1N y13w== X-Forwarded-Encrypted: i=1; AJvYcCUKfcPbNup11HdOgEIuDb30/ppXFEml47MxXTiR9wpbmDethXSNwaMdepGZV5l/R/xE6zD5l4m3pgN3nIwt3XdhtxBaItTAoJzLKyN9 X-Gm-Message-State: AOJu0Yy4sgNylC9OgJUrFGg9xvoB/S6GdsZGsVICfGsnowSkJ3O1HfVZ QjIc/MN9VQZ4+qdoPJEyjDQB1+xPX8yLIkpXn4h3kIw84KdNkaovYFLSc2wcOjE= X-Google-Smtp-Source: AGHT+IFONK2j7f1Ty9XVR60wDESk+CJEsa1zFEF6TM1ALYU3+/t6lQ5A3HkIW/azPODD5tAnbepFfw== X-Received: by 2002:a50:9549:0:b0:572:3483:8a27 with SMTP id v9-20020a509549000000b0057234838a27mr2688603eda.33.1714758759958; Fri, 03 May 2024 10:52:39 -0700 (PDT) Received: from [127.0.1.1] (84-115-213-47.cable.dynamic.surfer.at. [84.115.213.47]) by smtp.gmail.com with ESMTPSA id q28-20020a50aa9c000000b00572469a7948sm1968368edc.45.2024.05.03.10.52.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 May 2024 10:52:39 -0700 (PDT) From: Javier Carrasco Date: Fri, 03 May 2024 19:52:33 +0200 Subject: [PATCH 2/2] cpufreq: sun50i: replace of_node_put() with automatic cleanup handler Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20240503-sun50i-cpufreq-nvmem-cleanup-v1-2-0a2352cac46b@gmail.com> References: <20240503-sun50i-cpufreq-nvmem-cleanup-v1-0-0a2352cac46b@gmail.com> In-Reply-To: <20240503-sun50i-cpufreq-nvmem-cleanup-v1-0-0a2352cac46b@gmail.com> To: Yangtao Li , "Rafael J. Wysocki" , Viresh Kumar , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Andre Przywara , Jonathan Cameron Cc: linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev, linux-kernel@vger.kernel.org, Javier Carrasco X-Mailer: b4 0.14-dev X-Developer-Signature: v=1; a=ed25519-sha256; t=1714758755; l=2545; i=javier.carrasco.cruz@gmail.com; s=20240312; h=from:subject:message-id; bh=lzVnrSjci3YdZbJDcigjVDnutqYD0vEbfrujcq5AHHs=; b=EOd+5S8zrky1F+pf72NRCJOPHcqlppmlIu7H4SxMTuZa8DO0mns86VbChhQoq1UQhqm1esOuH iDf9qDV2t7qDx8DC46feRuLOrY1zGZIHAzv0ufxTYPAlC0XNm2P0FzB X-Developer-Key: i=javier.carrasco.cruz@gmail.com; a=ed25519; pk=lzSIvIzMz0JhJrzLXI0HAdPwsNPSSmEn6RbS+PTS9aQ= Make use of the __free() cleanup handler to automatically free nodes when they get out of scope. Signed-off-by: Javier Carrasco Reviewed-by: Andre Przywara --- drivers/cpufreq/sun50i-cpufreq-nvmem.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/drivers/cpufreq/sun50i-cpufreq-nvmem.c b/drivers/cpufreq/sun50i-cpufreq-nvmem.c index ef83e4bf2639..eb47c193269c 100644 --- a/drivers/cpufreq/sun50i-cpufreq-nvmem.c +++ b/drivers/cpufreq/sun50i-cpufreq-nvmem.c @@ -131,14 +131,14 @@ 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; struct device *cpu_dev; cpu_dev = get_cpu_device(0); if (!cpu_dev) return false; - np = dev_pm_opp_of_get_opp_desc_node(cpu_dev); + struct device_node *np __free(device_node) = + dev_pm_opp_of_get_opp_desc_node(cpu_dev); if (!np) return false; @@ -149,8 +149,6 @@ static bool dt_has_supported_hw(void) } } - of_node_put(np); - return has_opp_supported_hw; } @@ -165,7 +163,6 @@ static int sun50i_cpufreq_get_efuse(void) const struct sunxi_cpufreq_data *opp_data; struct nvmem_cell *speedbin_nvmem; const struct of_device_id *match; - struct device_node *np; struct device *cpu_dev; u32 *speedbin; int ret; @@ -174,19 +171,18 @@ static int sun50i_cpufreq_get_efuse(void) if (!cpu_dev) return -ENODEV; - np = dev_pm_opp_of_get_opp_desc_node(cpu_dev); + struct device_node *np __free(device_node) = + dev_pm_opp_of_get_opp_desc_node(cpu_dev); if (!np) return -ENOENT; match = of_match_node(cpu_opp_match_list, np); - if (!match) { - of_node_put(np); + if (!match) return -ENOENT; - } + opp_data = match->data; speedbin_nvmem = of_nvmem_cell_get(np, NULL); - of_node_put(np); if (IS_ERR(speedbin_nvmem)) return dev_err_probe(cpu_dev, PTR_ERR(speedbin_nvmem), "Could not get nvmem cell\n"); @@ -301,14 +297,9 @@ MODULE_DEVICE_TABLE(of, sun50i_cpufreq_match_list); static const struct of_device_id *sun50i_cpufreq_match_node(void) { - const struct of_device_id *match; - struct device_node *np; - - np = of_find_node_by_path("/"); - match = of_match_node(sun50i_cpufreq_match_list, np); - of_node_put(np); + struct device_node *np __free(device_node) = of_find_node_by_path("/"); - return match; + return of_match_node(sun50i_cpufreq_match_list, np); } /*