From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5318014A4E9; Wed, 5 Feb 2025 13:54:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738763650; cv=none; b=S1ambSp2MarfCfWUoJznsG1Yc6YL+rSwJ4rfZeJECMUecghZMM50oszv9zSpQYM/xH73FDgeyX88p+oKNHW0Y7NCe+q2F3E6cMF0BXDODE2Qf5cU8KFFR2wNUl43WwP1X6IuCPjllOBhqDyXYm8vLaH8FuXD6B6PWEURO+n8vUA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1738763650; c=relaxed/simple; bh=GIm9ZT/NeA0R2iakg/aJ+pBiuzbXcdbrlCmo8hkNE8Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pmBRwWGI94Hi/7rOVKbhN/JWVmJTX+RjFQw0/LBrV4ny14UN0sJMUQNbfk/gzuVj/7oVqI4XqVxj+k4NH03TccnXdR2+dLE1PkoGQG1QtLSs6OpYvIxGciOmB1L7z5jWFwl0UZP5i3Vteymt80+uXpV3DPorQcmbGOc3XvlQNZQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=1XzRFmUg; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="1XzRFmUg" Received: by smtp.kernel.org (Postfix) with ESMTPSA id B505DC4CED1; Wed, 5 Feb 2025 13:54:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1738763650; bh=GIm9ZT/NeA0R2iakg/aJ+pBiuzbXcdbrlCmo8hkNE8Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=1XzRFmUg7cETQDKAw38Gw1ZgE6S3vueZ/5CUK/9XbxwJVsH+zhnJa2nZ/vmOkQgre 8L2OQdBkTVP5cqim2V2nZhBzkBv2q48S7Ee1OAE7U22kLq7ux4dabQMQC7m+6cmVip v0L6J2CqbuYFhG7BDb6wRB6XzBeGZWCDIOPA4MbY= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Joe Hattori , Mark Brown , Sasha Levin Subject: [PATCH 6.6 093/393] regulator: of: Implement the unwind path of of_regulator_match() Date: Wed, 5 Feb 2025 14:40:12 +0100 Message-ID: <20250205134423.854425670@linuxfoundation.org> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250205134420.279368572@linuxfoundation.org> References: <20250205134420.279368572@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Joe Hattori [ Upstream commit dddca3b2fc676113c58b04aaefe84bfb958ac83e ] 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 Link: https://patch.msgid.link/20250104080453.2153592-1-joe@pf.is.s.u-tokyo.ac.jp Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- 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_regulator.c index 59e71fd0db439..f23c12f4ffbfa 100644 --- a/drivers/regulator/of_regulator.c +++ b/drivers/regulator/of_regulator.c @@ -435,7 +435,7 @@ int of_regulator_match(struct device *dev, struct device_node *node, "failed to parse DT for regulator %pOFn\n", child); of_node_put(child); - return -EINVAL; + goto err_put; } match->of_node = of_node_get(child); count++; @@ -444,6 +444,18 @@ int of_regulator_match(struct device *dev, struct device_node *node, } return count; + +err_put: + for (i = 0; i < num_matches; i++) { + struct of_regulator_match *match = &matches[i]; + + match->init_data = NULL; + if (match->of_node) { + of_node_put(match->of_node); + match->of_node = NULL; + } + } + return -EINVAL; } EXPORT_SYMBOL_GPL(of_regulator_match); -- 2.39.5