All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Chen-Yu Tsai" <wenst@chromium.org>
Cc: robh@kernel.org, conor+dt@kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v4 02/14] device property: Add fwnode_graph_get_next_port_endpoint()
Date: Thu, 09 Jul 2026 10:26:29 +0000	[thread overview]
Message-ID: <20260709102630.268DF1F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260709095726.704448-3-wenst@chromium.org>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the core `fwnode_get_next_child_node()` API has a severe pre-existing bug when iterating over a node with both primary and secondary fwnodes, leading to a double-free/Use-After-Free and an infinite loop.
--

--- Patch [2]: [PATCH v4 02/14] device property: Add fwnode_graph_get_next_port_endpoint() ---
commit 1373ba83196f2e29826248ffdc2c43881f3a22fa
Author: Chen-Yu Tsai <wenst@chromium.org>

device property: Add fwnode_graph_get_next_port_endpoint()

This commit introduces a new helper function to iterate over endpoint
firmware nodes under a specific port node. It will be used by the
upcoming USB power sequencing integration to verify graph connections
and supported connector types.

> diff --git a/drivers/base/property.c b/drivers/base/property.c
> index c5e7e00f1b0cd..7f1fff3b55c74 100644
> --- a/drivers/base/property.c
> +++ b/drivers/base/property.c

[ ... ]

> @@ -1099,6 +1099,31 @@ int fwnode_irq_get_byname(const struct fwnode_handle *fwnode, const char *name)
>  }
>  EXPORT_SYMBOL(fwnode_irq_get_byname);
>  
> +/**
> + * fwnode_graph_get_next_port_endpoint - Get next endpoint firmware node in port
> + * @port: Pointer to the target port firmware node
> + * @prev: Previous endpoint node or %NULL to get the first
> + *
> + * The caller is responsible for calling fwnode_handle_put() on the returned
> + * fwnode pointer. Note that this function also puts a reference to @prev
> + * unconditionally.
> + *
> + * Return: an endpoint firmware node pointer or %NULL if no more endpoints
> + * are available.
> + */
> +struct fwnode_handle *fwnode_graph_get_next_port_endpoint(const struct fwnode_handle *port,
> +							  struct fwnode_handle *prev)
> +{
> +	do {
> +		prev = fwnode_get_next_child_node(port, prev);

[Severity: High]
This isn't a bug introduced by this patch, but the core fwnode iteration 
API has a pre-existing double-free and infinite loop issue when used on 
nodes with both primary and secondary fwnodes.

When the primary fwnode's get_next_child_node operation reaches the end,
it drops the reference to the last child and returns NULL. The core API 
fwnode_get_next_child_node() then passes this already-put child pointer 
to the secondary ops:

drivers/base/property.c:fwnode_get_next_child_node() {
    ...
    next = fwnode_call_ptr_op(fwnode, get_next_child_node, child);
    if (next)
        return next;

    /* When no more children in primary, continue with secondary */
    return fwnode_call_ptr_op(fwnode->secondary, get_next_child_node, child);
}

This causes secondary ops like software_node_get_next_child() to call 
fwnode_handle_put(child) a second time on the already dropped node, 
resulting in a use-after-free or double free.

Furthermore, the secondary op returns its first child. On the next iteration
of this do/while loop, this secondary child is passed back to the primary OF 
op. Since to_of_node() on a secondary node evaluates to NULL, the OF iterator 
resets to its first child, creating an infinite loop alternating between 
primary and secondary children.

Is it safe for fwnode_graph_get_next_port_endpoint() to rely on this 
iterator before the underlying issue in fwnode_get_next_child_node() 
is resolved?

> +		if (fwnode_name_eq(prev, "endpoint"))
> +			break;
> +	} while (prev);
> +
> +	return prev;
> +}
> +EXPORT_SYMBOL_GPL(fwnode_graph_get_next_port_endpoint);

[ ... ]

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260709095726.704448-1-wenst@chromium.org?part=2

  reply	other threads:[~2026-07-09 10:26 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-09  9:57 [PATCH v4 00/14] arm64: mediatek: Add M.2 E-key slot on Chromebooks Chen-Yu Tsai
2026-07-09  9:57 ` [PATCH v4 01/14] device property: Add fwnode_graph_get_port_by_id() Chen-Yu Tsai
2026-07-09 10:13   ` sashiko-bot
2026-07-09  9:57 ` [PATCH v4 02/14] device property: Add fwnode_graph_get_next_port_endpoint() Chen-Yu Tsai
2026-07-09 10:26   ` sashiko-bot [this message]
2026-07-09  9:57 ` [PATCH v4 03/14] power: sequencing: Add pwrseq_power_is_on() Chen-Yu Tsai
2026-07-09 10:33   ` Andy Shevchenko
2026-07-09 10:35   ` sashiko-bot
2026-07-09  9:57 ` [PATCH v4 04/14] usb: hub: Return actual error from hub_configure() in hub_probe() Chen-Yu Tsai
2026-07-09  9:57 ` [PATCH v4 05/14] usb: hub: Associate port@ fwnode with USB port device Chen-Yu Tsai
2026-07-09 11:04   ` sashiko-bot
2026-07-10 12:08   ` Greg Kroah-Hartman
2026-07-13  6:40     ` Chen-Yu Tsai
2026-07-09  9:57 ` [PATCH v4 06/14] usb: core: Move struct usb_port and related APIs to port.h Chen-Yu Tsai
2026-07-09 10:36   ` Andy Shevchenko
2026-07-09 14:30   ` Bartosz Golaszewski
2026-07-09  9:57 ` [PATCH v4 07/14] usb: hub: Pass |struct usb_port*| to usb_port_is_power_on() Chen-Yu Tsai
2026-07-09 10:38   ` Andy Shevchenko
2026-07-09  9:57 ` [PATCH v4 08/14] usb: hub: Use usb_hub_set_port_power() to control port power everywhere Chen-Yu Tsai
2026-07-09 10:39   ` Andy Shevchenko
2026-07-09  9:57 ` [PATCH v4 09/14] usb: hub: Power on connected M.2 E-key connectors with power sequencing API Chen-Yu Tsai
2026-07-09 10:53   ` Andy Shevchenko
2026-07-09 11:45   ` sashiko-bot
2026-07-09  9:57 ` [PATCH v4 10/14] dt-bindings: usb: mediatek,mtk-xhci: Switch to ports for USB connections Chen-Yu Tsai
2026-07-09 11:58   ` sashiko-bot
2026-07-09 14:31   ` Bartosz Golaszewski
2026-07-09  9:57 ` [PATCH v4 11/14] power: sequencing: pcie-m2: support matching on remote "port" node Chen-Yu Tsai
2026-07-09 10:55   ` Andy Shevchenko
2026-07-09  9:57 ` [PATCH v4 12/14] power: sequencing: pcie-m2: Add usb and sdio targets for E-key connector Chen-Yu Tsai
2026-07-13  9:43   ` Wei Deng
2026-07-13  9:57     ` Chen-Yu Tsai
2026-07-13 10:42       ` Chen-Yu Tsai
2026-07-09  9:57 ` [PATCH v4 13/14] arm64: dts: mediatek: mt8195-cherry: Add M.2 E-key slot Chen-Yu Tsai
2026-07-09 12:35   ` sashiko-bot
2026-07-09  9:57 ` [PATCH v4 14/14] arm64: dts: mediatek: mt8188-geralt: Add WiFi/BT as " Chen-Yu Tsai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260709102630.268DF1F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=wenst@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.