Re: [PATCH v2] interconnect: imx: fix use-after-free in imx_icc_node_init_qos()

Frank Li
2026-04-09T03:34:48Z

On Wed, Apr 08, 2026 at 03:30:22PM +0000, Wentao Liang wrote:
> The function imx_icc_node_init_qos() manually manages the reference count
> of struct device_node *dn using of_node_put(). However, some error paths
> use dn after the put, leading to use-after-free. Convert to automatic
> cleanup using __free(device_node) to ensure the reference is always
> released when dn goes out of scope.
>
> Fixes: f0d8048525d7 ("interconnect: Add imx core driver")
> Cc: stable@vger.kernel.org
> Signed-off-by: Wentao Liang <vulab@iscas.ac.cn>
> ---
> Changes in v2:
> - Use auto cheanup to fix the problem.
> ---

Reviewed-by: Frank Li <Frank.Li@nxp.com>

> drivers/interconnect/imx/imx.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/interconnect/imx/imx.c b/drivers/interconnect/imx/imx.c
> index 9511f80cf041..e5fcdcb88cfb 100644
> --- a/drivers/interconnect/imx/imx.c
> +++ b/drivers/interconnect/imx/imx.c
> @@ -120,7 +120,8 @@ static int imx_icc_node_init_qos(struct icc_provider *provider,
> struct imx_icc_node *node_data = node->data;
> const struct imx_icc_node_adj_desc *adj = node_data->desc->adj;
> struct device *dev = provider->dev;
> - struct device_node *dn = NULL;
> + struct device_node *__free(device_nod) dn = of_parse_phandle(dev->of_node,
> + adj->phandle_name, 0);
> struct platform_device *pdev;
>
> if (adj->main_noc) {
> @@ -128,7 +129,6 @@ static int imx_icc_node_init_qos(struct icc_provider *provider,
> dev_dbg(dev, "icc node %s[%d] is main noc itself\n",
> node->name, node->id);
> } else {
> - dn = of_parse_phandle(dev->of_node, adj->phandle_name, 0);
> if (!dn) {
> dev_warn(dev, "Failed to parse %s\n",
> adj->phandle_name);
> @@ -138,12 +138,10 @@ static int imx_icc_node_init_qos(struct icc_provider *provider,
> if (!of_device_is_available(dn)) {
> dev_warn(dev, "Missing property %s, skip scaling %s\n",
> adj->phandle_name, node->name);
> - of_node_put(dn);
> return 0;
> }
>
> pdev = of_find_device_by_node(dn);
> - of_node_put(dn);
> if (!pdev) {
> dev_warn(dev, "node %s[%d] missing device for %pOF\n",
> node->name, node->id, dn);
> --
> 2.34.1
>