From nobody Thu Feb 12 21:48:55 2026 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 346E52594A0 for ; Sat, 4 Jan 2025 08:05:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735977903; cv=none; b=lzgjMYN+eu/Z8eGXXEHLddT5KC/zeCLBl0wCaWRARA+VxB5Zuq6xHk9HwTDg92WtrmarD8Kw+WH9MgCS3kkjq8rvLLpw0m1IlvU3Myc+DTajjOTCGJMZoc1rAz8ymopA7vOfZeLehNRW5fQOLZKvs9bkkNwmwxPfJbw1d/jAOE8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1735977903; c=relaxed/simple; bh=OiITaJ/ocoATSvmAv5xTdtcVoXCNMDQa/wQpxILwLAE=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=gHkBFgo5ePehBuBqWI28iWGv4piK5Q7Fde4EgH155V26aedbFrVw6DW+5FrHouox2D91noxBoDTRcvKiL+psmPBayc9+B9cBwSRp4h1eIwlFX0aJXjwttiew5duwog7We8Dt1QFU/Z8BBJq2S/YLiWdiGbH/BriLjNMEolHSDAg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=pf.is.s.u-tokyo.ac.jp; spf=none smtp.mailfrom=pf.is.s.u-tokyo.ac.jp; dkim=pass (2048-bit key) header.d=pf-is-s-u-tokyo-ac-jp.20230601.gappssmtp.com header.i=@pf-is-s-u-tokyo-ac-jp.20230601.gappssmtp.com header.b=uINOHa+8; arc=none smtp.client-ip=209.85.214.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=pf.is.s.u-tokyo.ac.jp Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=pf.is.s.u-tokyo.ac.jp Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pf-is-s-u-tokyo-ac-jp.20230601.gappssmtp.com header.i=@pf-is-s-u-tokyo-ac-jp.20230601.gappssmtp.com header.b="uINOHa+8" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-2161eb94cceso127604775ad.2 for ; Sat, 04 Jan 2025 00:05:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pf-is-s-u-tokyo-ac-jp.20230601.gappssmtp.com; s=20230601; t=1735977900; x=1736582700; 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=7Vx4zMteia+J1/B/69EN8T9J2slrz+udWAUcy1QXu6s=; b=uINOHa+8KxTxzfOvbtpGWM/l++dRcUlmRT4vQSr3WcnuE4z3Dt5J3r6FwbERoax9Pw BE7Qk1r/2cc9T0iOcsytsH9hVpMpMRbUzTK04/HkFN6wfYcQIKXN5e4i3mpyKws4xxK0 9+D5258uVN/+Gk4WvT0WijEYF6M0exSyHYXbJPZO0/PvUCAru8qCtTljRDh/aipsZdXo p8uxZHqm0smYAcnUAXO31VQIs6yFCDghb+eKUqKXUQ8qBr8E4GEBB+XWGslvwREVZsll 8IVV4K0klHqYz/JTiQy8p9pYz91vq977OODxMsWMax8hkFKl/8RiwEfXx3maBzWqnsQj Y7WQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1735977900; x=1736582700; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=7Vx4zMteia+J1/B/69EN8T9J2slrz+udWAUcy1QXu6s=; b=cqAU+DXOCLqhauz9VJ+ekJdhVGAsgQZFx99YxtM0Hm2cgfHAyeYvAZdy0xUNwCUetG fphmdZysneMX2WwBteCWZOA2/JU5gPwG5yBwktqUzRFClWSMFbe7Al9EV5PlqZ+07ewJ XYGrEoE7bIwPt6gP5ID6u80XGIgrskDce6Rf8MS3V4uFlEvrOW6Dhxq6jWnmHV4JbpOO C2lDCUSUowM6FlWYQYUn0UKAS8uubNIhBb/Uh3/4rtHiQX6qRI2hkDNmCqLTw7LpqQw3 ZFPHJarLmxpkiOi0DhBSsX+AjbdEoN78dXP+qlOEmb0zpKMdxN5YMrvivgPMAKqilH2a OQww== X-Gm-Message-State: AOJu0YzNI8JOEVJBHl6cjugeebxf4iEsAfAx1xLpbTky17TqXKfYavXN xnqIpceeRYptFQjJgJKKJCWFzqQ1S3H7YrsDx1HsGXJ24BvF4bqNL6LlSWi9G40= X-Gm-Gg: ASbGncvkCPG6kduhybdElei2uZjVVwrX5dV5ekeeOnw5KEsCeLhFgT4ge5+PhvePkO/ FBkAIvZiiOk55tpAWQ6hM5b4gLdTsoi3foeCFY0aja7DOn38EeswK01lfNDjaPBKwyTnDQoSRuZ wU+eJZuaMVyURRY9LW0EfbGyQqF9tqDzicHhTTFJd+jQ5pNFRRNZ49q0MjtApUQL8EiUshfIblu AGH3RseQfvqm9B9hcyVwChgXoqtMzkAvxyV0H7J+jge2w5HKKkJkx9wlc7MxPVVVivCoa7ExUN7 eAqibYdsFoINbCCiEDA1+q/XbP4XyfrnMyEql+VYkjI= X-Google-Smtp-Source: AGHT+IHL8N9DNgmfil5pukrNP7u4eEf/ogEBaiqCcc5lC+wWwgkqTTBDGoHpJAc5vccHWqXfKTNfGg== X-Received: by 2002:a17:902:f685:b0:219:e4b0:4286 with SMTP id d9443c01a7336-219e6ebcabdmr632471425ad.29.1735977900362; Sat, 04 Jan 2025 00:05:00 -0800 (PST) Received: from localhost.localdomain (133-32-227-190.east.xps.vectant.ne.jp. [133.32.227.190]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-219dc962ca2sm258043205ad.5.2025.01.04.00.04.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 04 Jan 2025 00:04:59 -0800 (PST) From: Joe Hattori To: lgirdwood@gmail.com, broonie@kernel.org Cc: linux-kernel@vger.kernel.org, Joe Hattori Subject: [PATCH] regulator: of: Implement the unwind path of of_regulator_match() Date: Sat, 4 Jan 2025 17:04:53 +0900 Message-Id: <20250104080453.2153592-1-joe@pf.is.s.u-tokyo.ac.jp> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" of_regulator_match() does not release the OF node reference in the error path, resulting in an OF node leak. Therefore, call of_node_put() on the obtained nodes before returning the EINVAL error. Since it is possible that some drivers call this function and do not exit on failure, such as s2mps11_pmic_driver, clear the init_data and of_node in the error path. This was reported by an experimental verification tool that I am developing. As I do not have access to actual devices nor the QEMU board configuration to test drivers that call this function, no runtime test was able to be performed. Fixes: 1c8fa58f4750 ("regulator: Add generic DT parsing for regulators") Signed-off-by: Joe Hattori --- drivers/regulator/of_regulator.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/regulator/of_regulator.c b/drivers/regulator/of_regula= tor.c index 3f490d81abc2..deab0b95b663 100644 --- a/drivers/regulator/of_regulator.c +++ b/drivers/regulator/of_regulator.c @@ -446,7 +446,7 @@ int of_regulator_match(struct device *dev, struct devic= e_node *node, "failed to parse DT for regulator %pOFn\n", child); of_node_put(child); - return -EINVAL; + goto err_put; } match->of_node =3D of_node_get(child); count++; @@ -455,6 +455,18 @@ int of_regulator_match(struct device *dev, struct devi= ce_node *node, } =20 return count; + +err_put: + for (i =3D 0; i < num_matches; i++) { + struct of_regulator_match *match =3D &matches[i]; + + match->init_data =3D NULL; + if (match->of_node) { + of_node_put(match->of_node); + match->of_node =3D NULL; + } + } + return -EINVAL; } EXPORT_SYMBOL_GPL(of_regulator_match); =20 --=20 2.34.1