Devicetree
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Ciprian Regus" <ciprian.regus@analog.com>
Cc: conor+dt@kernel.org, devicetree@vger.kernel.org, robh@kernel.org
Subject: Re: [PATCH net-next v5 03/13] net: ethernet: oa_tc6: add OA_TC6_BROKEN_PHY quirk flag
Date: Wed, 08 Jul 2026 22:34:56 +0000	[thread overview]
Message-ID: <20260708223456.8C3241F00A3A@smtp.kernel.org> (raw)
In-Reply-To: <20260708-adin1140-driver-v5-3-4aca7b51a58b@analog.com>

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

Pre-existing issues:
- [High] Workqueue canceled before netdev unregistration, leading to potential Use-After-Free of private data.
- [Medium] Lockless modification of waiting_tx_skb in oa_tc6_free_pending_skbs causes an skb memory leak.
--

--- Patch [3]: [PATCH net-next v5 03/13] net: ethernet: oa_tc6: add OA_TC6_BROKEN_PHY quirk flag ---
commit bf2392954a9b18d08ae43c154ebae75b683c36c6
Author: Ciprian Regus <ciprian.regus@analog.com>

net: ethernet: oa_tc6: add OA_TC6_BROKEN_PHY quirk flag
    
Some MAC-PHY devices need custom MDIO bus access functions to work
around hardware issues. Add the OA_TC6_BROKEN_PHY quirk flag so drivers
can opt in to skip oa_tc6's internal PHY init and manage the PHY
themselves. When the flag is set, oa_tc6 skips MDIO bus registration,
PHY discovery and PHY connection, leaving these to the driver.
    
Drivers that do not set the flag retain the existing behavior. Update
lan865x and the framework documentation accordingly.

> diff --git a/drivers/net/ethernet/microchip/lan865x/lan865x.c b/drivers/net/ethernet/microchip/lan865x/lan865x.c
> index 0277d9737369a..26a2761332a5a 100644
> --- a/drivers/net/ethernet/microchip/lan865x/lan865x.c
> +++ b/drivers/net/ethernet/microchip/lan865x/lan865x.c
> @@ -346,7 +346,7 @@ static int lan865x_probe(struct spi_device *spi)
>  	spi_set_drvdata(spi, priv);
>  	INIT_WORK(&priv->multicast_work, lan865x_multicast_work_handler);
>  
> -	priv->tc6 = oa_tc6_init(spi, netdev);
> +	priv->tc6 = oa_tc6_init(spi, netdev, NULL);
>  	if (!priv->tc6) {
>  		ret = -ENODEV;
>  		goto free_netdev;

[Severity: High]
This isn't a bug introduced by this patch, but looking at the driver's
teardown order in lan865x_remove(), is there a risk of a use-after-free of
the priv structure?

drivers/net/ethernet/microchip/lan865x/lan865x.c:lan865x_remove() {
	...
	cancel_work_sync(&priv->multicast_work);
	unregister_netdev(priv->netdev);
	...
}

If user-space changes the interface flags (e.g., promiscuous mode) while the
driver is being unbound, .ndo_set_rx_mode (lan865x_set_multicast_list) could
be invoked, unconditionally rescheduling priv->multicast_work.

If this happens after cancel_work_sync() but before unregister_netdev()
completes, the rescheduled work could execute after free_netdev() has freed
the priv structure. 

Could unregister_netdev() be called before cancel_work_sync() to guarantee
no further callbacks will be invoked?

[ ... ]

> diff --git a/drivers/net/ethernet/oa_tc6.c b/drivers/net/ethernet/oa_tc6.c
> index 8b96558834960..fa1359224535c 100644
> --- a/drivers/net/ethernet/oa_tc6.c
> +++ b/drivers/net/ethernet/oa_tc6.c

[ ... ]

> @@ -1327,11 +1334,13 @@ static int oa_tc6_check_ctrl_protection(struct oa_tc6 *tc6)
>   * oa_tc6_init - allocates and initializes oa_tc6 structure.
>   * @spi: device with which data will be exchanged.
>   * @netdev: network device interface structure.
> + * @quirks: device specific modifiers for the OA TC6 protocol.
>   *
>   * Return: pointer reference to the oa_tc6 structure if the MAC-PHY
>   * initialization is successful otherwise NULL.
>   */
> -struct oa_tc6 *oa_tc6_init(struct spi_device *spi, struct net_device *netdev)
> +struct oa_tc6 *oa_tc6_init(struct spi_device *spi, struct net_device *netdev,
> +			   struct oa_tc6_quirks *quirks)
>  {

[Severity: Medium]
This is a pre-existing issue, but could this sequence result in a memory leak
of a single SKB in the error handling path?

Looking at oa_tc6_disable_traffic(), tc6->disable_traffic is set to true
locklessly. Immediately after, oa_tc6_free_pending_skbs() calls
oa_tc6_cleanup_waiting_tx_skb(), which checks and clears tc6->waiting_tx_skb
without holding tc6->tx_skb_lock:

drivers/net/ethernet/oa_tc6.c:oa_tc6_cleanup_waiting_tx_skb() {
	if (tc6->waiting_tx_skb) {
		tc6->netdev->stats.tx_dropped++;
		kfree_skb(tc6->waiting_tx_skb);
		tc6->waiting_tx_skb = NULL;
	}
}

Concurrently, oa_tc6_start_xmit() evaluates tc6->disable_traffic and
tc6->waiting_tx_skb locklessly. If oa_tc6_start_xmit() reads false/NULL just
before oa_tc6_disable_traffic() modifies them, it will acquire the
tx_skb_lock and overwrite tc6->waiting_tx_skb with a new skb:

drivers/net/ethernet/oa_tc6.c:oa_tc6_start_xmit() {
	...
	spin_lock_bh(&tc6->tx_skb_lock);
	tc6->waiting_tx_skb = skb;
	spin_unlock_bh(&tc6->tx_skb_lock);
	...
}

Since traffic is disabled and oa_tc6_cleanup_waiting_tx_skb() has already
executed, will this new skb be left in the queue and leaked until the device
is explicitly unbound?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260708-adin1140-driver-v5-0-4aca7b51a58b@analog.com?part=3

  reply	other threads:[~2026-07-08 22:34 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-07 22:33 [PATCH net-next v5 00/13] net: Add ADIN1140 support Ciprian Regus via B4 Relay
2026-07-07 22:33 ` [PATCH net-next v5 01/13] dt-bindings: net: Add ADIN1140 Ciprian Regus via B4 Relay
2026-07-07 22:33 ` [PATCH net-next v5 02/13] net: ethernet: oa_tc6: Handle the OA TC6 SPI protected mode Ciprian Regus via B4 Relay
2026-07-08 22:34   ` sashiko-bot
2026-07-07 22:33 ` [PATCH net-next v5 03/13] net: ethernet: oa_tc6: add OA_TC6_BROKEN_PHY quirk flag Ciprian Regus via B4 Relay
2026-07-08 22:34   ` sashiko-bot [this message]
2026-07-07 22:33 ` [PATCH net-next v5 04/13] net: ethernet: oa_tc6: Export the C45 access functions Ciprian Regus via B4 Relay
2026-07-08 22:34   ` sashiko-bot
2026-07-07 22:33 ` [PATCH net-next v5 05/13] net: ethernet: oa_tc6: Export standard defined registers Ciprian Regus via B4 Relay
2026-07-08 22:34   ` sashiko-bot
2026-07-07 22:33 ` [PATCH net-next v5 06/13] net: ethernet: oa_tc6: Add the OA_TC6_ prefix to standard registers Ciprian Regus via B4 Relay
2026-07-07 22:33 ` [PATCH net-next v5 07/13] net: ethernet: oa_tc6: Add read_mms/write_mms register access functions Ciprian Regus via B4 Relay
2026-07-08 17:23   ` Selvamani Rajagopal
2026-07-08 22:34   ` sashiko-bot
2026-07-07 22:33 ` [PATCH net-next v5 08/13] net: ethernet: oa_tc6: Use the read_mms/write_mms functions for C45 Ciprian Regus via B4 Relay
2026-07-08 22:34   ` sashiko-bot
2026-07-07 22:33 ` [PATCH net-next v5 09/13] net: ethernet: oa_tc6: Add new register address defines Ciprian Regus via B4 Relay
2026-07-07 22:33 ` [PATCH net-next v5 10/13] net: phy: add generic helpers for direct C45 MMD access Ciprian Regus via B4 Relay
2026-07-09  2:29   ` Selvamani Rajagopal
2026-07-07 22:33 ` [PATCH net-next v5 11/13] net: phy: microchip-t1s: use generic C45 MMD access helpers Ciprian Regus via B4 Relay
2026-07-07 22:33 ` [PATCH net-next v5 12/13] net: phy: Add support for the ADIN1140 PHY Ciprian Regus via B4 Relay
2026-07-08 22:34   ` sashiko-bot
2026-07-07 22:33 ` [PATCH net-next v5 13/13] net: ethernet: adi: Add a driver for the ADIN1140 MACPHY Ciprian Regus via B4 Relay
2026-07-08 22:34   ` sashiko-bot

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=20260708223456.8C3241F00A3A@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=ciprian.regus@analog.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox