From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f47.google.com (mail-pj1-f47.google.com [209.85.216.47]) (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 61D7116CD33 for ; Wed, 10 Jun 2026 04:15:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781064948; cv=none; b=EHItNpuO4Iqv1HU/y6hMHrgM1r4jK6HDb65XmIOHmkBO5SXWi7aPlYybDD8BYnnnIUXXLCgj8qCVHxIBLkBr1cppNuKRYom07iviycADGCrRR7uEIFDfQNnxiahYiXPe/WwN3EHCeNMBX4RzRnShFSXrYU0oAM44Fuwk1GHr9mo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781064948; c=relaxed/simple; bh=Om8Zca55xZg6VMdzz3rc5y5q15kLkne5yOPVho7KXks=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=srdh1wi4WrLatPSLE3ni4sC+CKY6n5yMhczPCVhU5p6yTlc4ISsuqIM+A3TwDxHP1BTJLCyhEYz0Qb3qgxt0NX500HT5JLU/S2e5HoqCoZEOZgcT7v0bZX7LozwDSApKDitemuS3zlxosQ1XwJSeqdPs+NHZdFbNaRrU8Fsu3Rw= 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=TDqn0U3p; arc=none smtp.client-ip=209.85.216.47 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="TDqn0U3p" Received: by mail-pj1-f47.google.com with SMTP id 98e67ed59e1d1-36baeec21dcso4062284a91.3 for ; Tue, 09 Jun 2026 21:15:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781064946; x=1781669746; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=6+Gj9i6XXhBeEkETP8dtrWAdE9uX+Fdm6RoGUY88HMo=; b=TDqn0U3ppyq1M97+1HXY7yB8mAsCiytpbbwZBttxvnkCSPD+G+o/mIyZDfVEMztUCp XK34WDnrLYB+r+7gFxjqVF7qG+1jLfojGAecyli4OeBBVgoIvHo7/vjC0cgQNsSpYuhk vGpGdwzwB9SDCRuzG7/InWLAhbNzwa7dMwzJY1BOHw+zAdsJFiHbrv2LYdVm9ihORcL1 dBsfbL1hN/Xf6+mMsOS7OaiAhft06+Bnhwl7QFLUeFhgIfc/7zFhwsnXLxQFZfQNmxk2 xWI9SnCv8cy9GQcv8OEGR6l1j+6zdRGQSo3jJf//lG74JN59o2AlsnfMwoAGDLDt/eda E37w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781064946; x=1781669746; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=6+Gj9i6XXhBeEkETP8dtrWAdE9uX+Fdm6RoGUY88HMo=; b=imsVHrabWxXySBeVW8EZ9aC+NN6pXz23yzPsvrBYOdpuDfw3l+0s1GDypFEYik9gN5 qlszmA60fSqQL8nZ+L2qWseP8wZmQUneC2oCEqv8+p1vv6hETNtlSzC0a3CWkytbr9Lt OdkxZty6nrQidEv37BQMkb3M2lgYB7C8PLI2YHOAJCa/T9sl1ic4aTzFjzl7TYEx9kTF 4i4TS1WWDd57WJPKs/RQxzUditX9LfjhXlodC+wX8bKm0QQnicvwWDmJVjmTNcGwYylC HzaQHajat+r9CK5RaWaLEdpiE5hyTlNI4y60uYJGPDoItywUwqwSvUea2pdtDjP6N7W8 w7Hg== X-Forwarded-Encrypted: i=1; AFNElJ/mAolPZChe0lECV3OJPkvpIFIVCutTxEA8CBvQGdRDpdGPHjtW1NpfXzsS7Z07MVJDDxFWihwoe6EhCXM=@vger.kernel.org X-Gm-Message-State: AOJu0Ywm+mvNqNV491dQQ+pr1npkWKQZDkEMRMwMqlLfU1hT89QVIWsB TyxYm5ZoHdiplGhhPOKsemfJZU3p7lwZWJs961FQcxQSOvcwCatT1lRB X-Gm-Gg: Acq92OH8bN52rX/KEYUgdymDm7cnvnFGjaiMQ2LHGFlQTb/iLYMvVQBQqE8FNii0KTm 9UBVXzYr9iJsjrdbiIcbNAVMb0KCDnEmzuyXvQe3+3FxagawavzGIgO65DSEXLikCSrsWlAcSoL mOnc7gmPsJW/OOgJqEoCaGDhKF5P9MWNXEGy/ZkVs931Cv4Q3QO9E600T5Ql9Tt3AkpjBSls9wj DSovpjeEvtCPu//hYBWfbbAaUzr51A4JMZYSwHJJZq8Yoood4zqVwe2bUDFERrHjisUFjUGnI84 ymv+SqJFoQHgODGGf5xq7rvfY3J6rB90/UlOlOFID1whsc3QJA6si/8tW4lf9/7Oo9II0cVrzhy dCaGUwGxFvSEWgoaAemE61Gr5rnr0lCIbydRfVRBGQ4hKYM4GglTNGr2iu06PmQ9tyM6DmnVF0L gTHQ36kC52rBJj7ZEyPywv+8t8bi2o4G5rXsPRwJICbKr+RuXiskBHJpbs4BHETXSG38v/T6Py+ 3yS5am0mNereN4Q75rKqZDRkeAYUKjPJdN1lD5Kj9CDDTCm7gcutQ== X-Received: by 2002:a17:90b:4b0f:b0:368:78da:803 with SMTP id 98e67ed59e1d1-370ef0f15c3mr26348541a91.12.1781064946336; Tue, 09 Jun 2026 21:15:46 -0700 (PDT) Received: from localhost.localdomain (n49-176-80-106.mas22.nsw.optusnet.com.au. [49.176.80.106]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-376465ca306sm591038a91.2.2026.06.09.21.15.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jun 2026 21:15:45 -0700 (PDT) From: Weigang He To: Andrew Lunn Cc: Sebastian Hesselbarth , Gregory Clement , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Weigang He Subject: [PATCH] soc: dove: pmu: fix device_node refcount leaks in dove_init_pmu() Date: Wed, 10 Jun 2026 14:15:36 +1000 Message-ID: <20260610041536.2164285-1-geoffreyhe2@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit dove_init_pmu() acquires two device_node references that are leaked on several exit paths: - np_pmu, from of_find_compatible_node(): leaked on the !domains_node early return and on the !pmu allocation-failure return, both of which occur before the reference is handed to pmu->of_node. On the iomap failure path it has already been stored in pmu->of_node, so it must be released via that field before pmu is freed. - domains_node, from of_get_child_by_name(): used only as the iterator base of for_each_available_child_of_node(), which never drops the parent reference. It is leaked on the allocation-failure return, the iomap-failure return and, most commonly, on the normal success path. The success path keeps np_pmu alive deliberately: it is stored in pmu->of_node and the pmu structure persists for the lifetime of the system, so np_pmu is not put there. Release np_pmu on the two early error returns and via pmu->of_node on the iomap-failure return, and release domains_node on every path once it is no longer needed. Found by static analysis tool CodeQL. Fixes: 44e259ac909f ("ARM: dove: create a proper PMU driver for power domains, PMU IRQs and resets") Signed-off-by: Weigang He --- drivers/soc/dove/pmu.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/soc/dove/pmu.c b/drivers/soc/dove/pmu.c index 7bbd3f940e4d9..d8819ad50db5f 100644 --- a/drivers/soc/dove/pmu.c +++ b/drivers/soc/dove/pmu.c @@ -383,12 +383,16 @@ int __init dove_init_pmu(void) domains_node = of_get_child_by_name(np_pmu, "domains"); if (!domains_node) { pr_err("%pOFn: failed to find domains sub-node\n", np_pmu); + of_node_put(np_pmu); return 0; } pmu = kzalloc(sizeof(*pmu), GFP_KERNEL); - if (!pmu) + if (!pmu) { + of_node_put(np_pmu); + of_node_put(domains_node); return -ENOMEM; + } spin_lock_init(&pmu->lock); pmu->of_node = np_pmu; @@ -398,7 +402,9 @@ int __init dove_init_pmu(void) pr_err("%pOFn: failed to map PMU\n", np_pmu); iounmap(pmu->pmu_base); iounmap(pmu->pmc_base); + of_node_put(pmu->of_node); kfree(pmu); + of_node_put(domains_node); return -ENOMEM; } @@ -443,6 +449,8 @@ int __init dove_init_pmu(void) __pmu_domain_register(domain, np); } + of_node_put(domains_node); + /* Loss of the interrupt controller is not a fatal error. */ parent_irq = irq_of_parse_and_map(pmu->of_node, 0); if (!parent_irq) { base-commit: 0f61b1860cc3f52aef9036d7235ed1f017632193 -- 2.43.0