Linux Input/HID development
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Leon Romanovsky" <leon@kernel.org>
Cc: linux-input@vger.kernel.org, linux-usb@vger.kernel.org,
	linux-pci@vger.kernel.org, linux-sound@vger.kernel.org,
	dmitry.torokhov@gmail.com
Subject: Re: [PATCH v4 19/33] net: phy: Use the compatibility driver attachment API
Date: Wed, 25 Nov 2026 09:46:43 +0000	[thread overview]
Message-ID: <sashiko-outbox-233056@kernel.org> (raw)
In-Reply-To: <20261124-device-trust-core-v4-19-037eb0d17b1f@nvidia.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] net: phy: unsynchronized phydev->irq write on error in
  phy_attach_direct()
--

commit 165c70c3ab9d6261f753f16524c858fcd9ab84df
Author: Leon Romanovsky <leon@kernel.org>

net: phy: Use the compatibility driver attachment API

This commit switches the generic PHY fallback attachment in
phy_attach_direct() to use device_driver_attach_unrestricted() and moves
is_genphy_driven management into phy_probe() and phy_remove().

> diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
> index 5d4508bcfbe99..4f20b451e270d 100644
> --- a/drivers/net/phy/phy_device.c
> +++ b/drivers/net/phy/phy_device.c
[ ... ]
> @@ -1912,6 +1911,8 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
>  	struct device *d = &phydev->mdio.dev;
>  	struct module *ndev_owner = NULL;
>  	struct module *drv_owner;
> +	struct device_driver *drv;
> +	bool bind_genphy;
>  	int irq = phydev->irq;
>  	int err;
>  
> @@ -1939,16 +1940,16 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
>  	/* Assume that if there is no driver, that it doesn't
>  	 * exist, and we should use the genphy driver.
>  	 */
> -	if (!d->driver) {
> +	drv = d->driver;
> +	bind_genphy = !drv;
> +	if (bind_genphy) {
>  		if (phydev->is_c45)
> -			d->driver = &genphy_c45_driver.mdiodrv.driver;
> +			drv = &genphy_c45_driver.mdiodrv.driver;
>  		else
> -			d->driver = &genphy_driver.mdiodrv.driver;
> -
> -		phydev->is_genphy_driven = 1;
> +			drv = &genphy_driver.mdiodrv.driver;
>  	}
>  
> -	drv_owner = d->driver->owner;
> +	drv_owner = drv->owner;
>  	if (!try_module_get(drv_owner)) {
>  		phydev_err(phydev, "failed to get the device driver module\n");
>  		err = -EIO;
> @@ -1956,11 +1957,8 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
>  	}
>  	phydev->drv_owner = drv_owner;
>  
> -	if (phydev->is_genphy_driven) {
> -		err = d->driver->probe(d);
> -		if (err >= 0)
> -			err = device_bind_driver(d);
> -
> +	if (bind_genphy) {
> +		err = device_driver_attach_unrestricted(drv, d);
>  		if (err)
>  			goto error_module_put;
>  	}
> @@ -2071,8 +2069,6 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
>  	module_put(phydev->drv_owner);
>  	phydev->drv_owner = NULL;
>  	phydev->irq = irq;
> -	phydev->is_genphy_driven = 0;
> -	d->driver = NULL;
>  error_put_device:
>  	put_device(d);
>  	if (ndev_owner != bus->owner)

[Severity: Medium]
Can error_module_put overwrite phydev->irq after a concurrent driver probe?

While d->driver and phydev->is_genphy_driven are now cleaned up under
d->p->driver_lock, error_module_put still unconditionally restores the
saved phydev->irq outside d->p->driver_lock when
device_driver_attach_unrestricted() fails:

CPU0                                     CPU1
phy_attach_direct()
  irq = phydev->irq;
  drv = d->driver; (NULL)
                                         driver_probe_device()
                                           mutex_lock(&d->p->driver_lock)
                                           ...
                                           phy_probe()
                                             phydev->irq = PHY_POLL;
  device_driver_attach_unrestricted()
    mutex_trylock(&d->p->driver_lock)
    -> returns -EBUSY
  goto error_module_put;
  phydev->irq = irq;  <-- clobbers PHY_POLL

If the bound PHY driver does not support interrupts and phy_probe() forced
phydev->irq to PHY_POLL, restoring the raw IRQ number leaves the bound
driver with an unsupported interrupt configuration.  The same race exists
if genphy's phy_probe() fails inside device_driver_attach_unrestricted()
and another driver probes after d->p->driver_lock is released.

Restoring phydev->irq inside phy_probe()'s error path (while holding
d->p->driver_lock) instead of at error_module_put would avoid touching
phydev->irq when driver_lock is not held.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261124-device-trust-core-v4-0-037eb0d17b1f@nvidia.com?part=19

  reply	other threads:[~2026-11-25  9:46 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24  9:43 [PATCH v4 00/33] driver core: Authorize device trust before driver binding Leon Romanovsky
2026-11-24  9:43 ` [PATCH v4 01/33] wifi: mac80211_hwsim: lock device for manual " Leon Romanovsky
2026-11-24  9:43 ` [PATCH v4 02/33] Bluetooth: btusb: Fix MediaTek ISO claim locking Leon Romanovsky
2026-11-24 10:39   ` Oliver Neukum
2026-11-25  8:49     ` Leon Romanovsky
2026-11-24  9:43 ` [PATCH v4 03/33] USB: Lock interfaces during manual driver binding Leon Romanovsky
2026-11-24  9:43 ` [PATCH v4 04/33] USB: serial: Register USB drivers with their owning module Leon Romanovsky
2026-11-24  9:43 ` [PATCH v4 05/33] USB: Reject claims of DT-disabled interfaces Leon Romanovsky
2026-11-24  9:43 ` [PATCH v4 06/33] USB: Reject usbfs connect requests for unregistered interfaces Leon Romanovsky
2026-11-25  9:46   ` sashiko-bot
2026-11-24  9:43 ` [PATCH v4 07/33] USB: Release interface claims according to binding state Leon Romanovsky
2026-11-24  9:43 ` [PATCH v4 08/33] USB: Reject claims after interface registration failure Leon Romanovsky
2026-11-24  9:43 ` [PATCH v4 09/33] ALSA: usb-audio: Release interface claims when probe fails Leon Romanovsky
2026-11-24  9:43 ` [PATCH v4 10/33] USB: Pin modules for unregistered interface claims Leon Romanovsky
2026-11-24  9:43 ` [PATCH v4 11/33] USB: Add helpers to release unpublished " Leon Romanovsky
2026-11-24  9:43 ` [PATCH v4 12/33] USB: Unwind interface claims after registration or binding failure Leon Romanovsky
2026-11-24  9:43 ` [PATCH v4 13/33] PNP: Attach card devices through the driver core Leon Romanovsky
2026-11-24  9:43 ` [PATCH v4 14/33] cdx: Propagate DMA configuration errors Leon Romanovsky
2026-11-24  9:43 ` [PATCH v4 15/33] driver core: Report deferred probes through sysfs drivers_probe Leon Romanovsky
2026-11-24  9:43 ` [PATCH v4 16/33] driver core: Add a compatibility API for manual driver attachment Leon Romanovsky
2026-11-25  9:46   ` sashiko-bot
2026-11-24  9:43 ` [PATCH v4 17/33] Input: gameport - use the compatibility driver attachment API Leon Romanovsky
2026-11-24  9:43 ` [PATCH v4 18/33] Input: serio " Leon Romanovsky
2026-11-24  9:43 ` [PATCH v4 19/33] net: phy: Use " Leon Romanovsky
2026-11-25  9:46   ` sashiko-bot [this message]
2026-11-24  9:43 ` [PATCH v4 20/33] USB: Drain usbfs when a device is unregistered Leon Romanovsky
2026-11-24  9:43 ` [PATCH v4 21/33] driver core: Introduce a generic device trust level Leon Romanovsky
2026-11-25  0:13   ` Randy Dunlap
2026-11-25  8:06     ` Leon Romanovsky
2026-11-24  9:43 ` [PATCH v4 22/33] driver core: Expose device trust authorization interfaces Leon Romanovsky
2026-11-24  9:43 ` [PATCH v4 23/33] driver core: Accept device trust policy on the kernel command line Leon Romanovsky
2026-11-24  9:43 ` [PATCH v4 24/33] driver core: Accept device trust policy by driver name Leon Romanovsky
2026-11-24  9:43 ` [PATCH v4 25/33] driver core: Expose committed device trust level Leon Romanovsky
2026-11-24  9:43 ` [PATCH v4 26/33] driver core: Cover trust authorization and binding with KUnit Leon Romanovsky
2026-11-24  9:43 ` [PATCH v4 27/33] driver core: Document trust admission and initrd authorization Leon Romanovsky
2026-11-24  9:43 ` [PATCH v4 28/33] PCI: Use device trust for platform restrictions Leon Romanovsky
2026-11-25  9:46   ` sashiko-bot
2026-11-24  9:44 ` [PATCH v4 29/33] iommu: Use device trust for DMA restrictions Leon Romanovsky
2026-11-24  9:44 ` [PATCH v4 30/33] driver core: Allow driver attachment with the device lock held Leon Romanovsky
2026-11-24  9:44 ` [PATCH v4 31/33] USB: Retain the result of configuration requests Leon Romanovsky
2026-11-24  9:44 ` [PATCH v4 32/33] USB: Authorize interfaces through device trust Leon Romanovsky
2026-11-25  9:46   ` sashiko-bot
2026-11-24  9:44 ` [PATCH v4 33/33] USB: Authorize devices " Leon Romanovsky
2026-11-25  9:46   ` 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=sashiko-outbox-233056@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=leon@kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=linux-usb@vger.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