public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
* [bug report] net: usb: lan78xx: Convert to PHYLINK for improved PHY and MAC management
@ 2025-06-25 15:22 Dan Carpenter
  2025-06-26 10:39 ` Oleksij Rempel
  0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2025-06-25 15:22 UTC (permalink / raw)
  To: o.rempel; +Cc: linux-usb

Hello Oleksij Rempel,

The patch e110bc825897: "net: usb: lan78xx: Convert to PHYLINK for
improved PHY and MAC management" from Jun 18, 2025, leads to the
following static checker warning:

    drivers/net/usb/lan78xx.c:2851 lan78xx_phy_init()
    error: we previously assumed 'phydev' could be null (see line 2839)

drivers/net/usb/lan78xx.c
    2817 static int lan78xx_phy_init(struct lan78xx_net *dev)
    2818 {
    2819 	struct phy_device *phydev;
    2820 	int ret;
    2821 
    2822 	phydev = lan78xx_get_phy(dev);
    2823 	/* phydev can be NULL if no PHY is found and the chip is LAN7801,

Assume phydev is NULL

    2824 	 * which will use a fixed link later.
    2825 	 * If an  error occurs, return the error code immediately.
    2826 	 */
    2827 	if (IS_ERR(phydev))
    2828 		return PTR_ERR(phydev);
    2829 
    2830 	ret = lan78xx_phylink_setup(dev);
    2831 	if (ret < 0)
    2832 		return ret;
    2833 
    2834 	/* If no PHY is found, set up a fixed link. It is very specific to
    2835 	 * the LAN7801 and is used in special cases like EVB-KSZ9897-1 where
    2836 	 * LAN7801 acts as a USB-to-Ethernet interface to a switch without
    2837 	 * a visible PHY.
    2838 	 */
    2839 	if (!phydev) {
    2840 		ret = lan78xx_set_fixed_link(dev);
    2841 		if (ret < 0)
    2842 			goto phylink_uninit;
    2843 	}
    2844 
    2845 	ret = lan78xx_mac_prepare_for_phy(dev);
    2846 	if (ret < 0)
    2847 		goto phylink_uninit;
    2848 
    2849 	/* if phyirq is not set, use polling mode in phylib */
    2850 	if (dev->domain_data.phyirq > 0)
--> 2851 		phydev->irq = dev->domain_data.phyirq;
    2852 	else
    2853 		phydev->irq = PHY_POLL;
    2854 	netdev_dbg(dev->net, "phydev->irq = %d\n", phydev->irq);

Then this block will crash.

    2855 
    2856 	ret = phylink_connect_phy(dev->phylink, phydev);
    2857 	if (ret) {
    2858 		netdev_err(dev->net, "can't attach PHY to %s, error %pe\n",
    2859 			   dev->mdiobus->id, ERR_PTR(ret));
    2860 		goto phylink_uninit;
    2861 	}
    2862 
    2863 	ret = lan78xx_configure_leds_from_dt(dev, phydev);
    2864 	if (ret < 0)
    2865 		goto phylink_uninit;
    2866 
    2867 	return 0;
    2868 
    2869 phylink_uninit:
    2870 	lan78xx_phy_uninit(dev);
    2871 
    2872 	return ret;
    2873 }

regards,
dan carpenter

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [bug report] net: usb: lan78xx: Convert to PHYLINK for improved PHY and MAC management
  2025-06-25 15:22 [bug report] net: usb: lan78xx: Convert to PHYLINK for improved PHY and MAC management Dan Carpenter
@ 2025-06-26 10:39 ` Oleksij Rempel
  0 siblings, 0 replies; 2+ messages in thread
From: Oleksij Rempel @ 2025-06-26 10:39 UTC (permalink / raw)
  To: Dan Carpenter; +Cc: linux-usb

On Wed, Jun 25, 2025 at 10:22:54AM -0500, Dan Carpenter wrote:
> Hello Oleksij Rempel,
> 
> The patch e110bc825897: "net: usb: lan78xx: Convert to PHYLINK for
> improved PHY and MAC management" from Jun 18, 2025, leads to the
> following static checker warning:
> 
>     drivers/net/usb/lan78xx.c:2851 lan78xx_phy_init()
>     error: we previously assumed 'phydev' could be null (see line 2839)
> 
> drivers/net/usb/lan78xx.c
>     2817 static int lan78xx_phy_init(struct lan78xx_net *dev)
>     2818 {
>     2819 	struct phy_device *phydev;
>     2820 	int ret;
>     2821 
>     2822 	phydev = lan78xx_get_phy(dev);
>     2823 	/* phydev can be NULL if no PHY is found and the chip is LAN7801,
> 
> Assume phydev is NULL
> 
>     2824 	 * which will use a fixed link later.
>     2825 	 * If an  error occurs, return the error code immediately.
>     2826 	 */
>     2827 	if (IS_ERR(phydev))
>     2828 		return PTR_ERR(phydev);
>     2829 
>     2830 	ret = lan78xx_phylink_setup(dev);
>     2831 	if (ret < 0)
>     2832 		return ret;
>     2833 
>     2834 	/* If no PHY is found, set up a fixed link. It is very specific to
>     2835 	 * the LAN7801 and is used in special cases like EVB-KSZ9897-1 where
>     2836 	 * LAN7801 acts as a USB-to-Ethernet interface to a switch without
>     2837 	 * a visible PHY.
>     2838 	 */
>     2839 	if (!phydev) {
>     2840 		ret = lan78xx_set_fixed_link(dev);
>     2841 		if (ret < 0)
>     2842 			goto phylink_uninit;
>     2843 	}
>     2844 
>     2845 	ret = lan78xx_mac_prepare_for_phy(dev);
>     2846 	if (ret < 0)
>     2847 		goto phylink_uninit;
>     2848 
>     2849 	/* if phyirq is not set, use polling mode in phylib */
>     2850 	if (dev->domain_data.phyirq > 0)
> --> 2851 		phydev->irq = dev->domain_data.phyirq;
>     2852 	else
>     2853 		phydev->irq = PHY_POLL;
>     2854 	netdev_dbg(dev->net, "phydev->irq = %d\n", phydev->irq);
> 
> Then this block will crash.

Thank you for the bug report!

Here is the fix:
https://lore.kernel.org/all/20250626103731.3986545-1-o.rempel@pengutronix.de

-- 
Pengutronix e.K.                           |                             |
Steuerwalder Str. 21                       | http://www.pengutronix.de/  |
31137 Hildesheim, Germany                  | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-06-26 10:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-25 15:22 [bug report] net: usb: lan78xx: Convert to PHYLINK for improved PHY and MAC management Dan Carpenter
2025-06-26 10:39 ` Oleksij Rempel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox