From: Andrew Lunn <andrew@lunn.ch>
To: Wei Fang <wei.fang@nxp.com>
Cc: "hkallweit1@gmail.com" <hkallweit1@gmail.com>,
"linux@armlinux.org.uk" <linux@armlinux.org.uk>,
"davem@davemloft.net" <davem@davemloft.net>,
"edumazet@google.com" <edumazet@google.com>,
"kuba@kernel.org" <kuba@kernel.org>,
"pabeni@redhat.com" <pabeni@redhat.com>,
"f.fainelli@gmail.com" <f.fainelli@gmail.com>,
"xiaolei.wang@windriver.com" <xiaolei.wang@windriver.com>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"imx@lists.linux.dev" <imx@lists.linux.dev>
Subject: Re: [PATCH net] net: phy: clear phydev->devlink when the link is deleted
Date: Thu, 22 May 2025 18:19:13 +0200 [thread overview]
Message-ID: <d8cb2a8f-af3d-4042-96a3-a762df1876a9@lunn.ch> (raw)
In-Reply-To: <PAXPR04MB851054C5E1049B5361A46C108899A@PAXPR04MB8510.eurprd04.prod.outlook.com>
On Thu, May 22, 2025 at 01:57:20PM +0000, Wei Fang wrote:
> > On Thu, May 22, 2025 at 02:42:53PM +0800, Wei Fang wrote:
> > > The phydev->devlink is not cleared when the link is deleted, so calling
> > > phy_detach() again will cause a crash.
> >
> > I would say crashing is correct. You have done something you should
> > not do, and the crash helped you find it. phy_attach() and
> > phy_detach() should always be in pairs.
> >
>
> phy_attach() and phy_detach() are called in pairs in my case. When
> re-enabling the network port, if an error occurs in the phy_attach_direct(),
> For example, if phy_init_hw() returns an error, it will jump to the error
> path and call phy_detach(). Because phy_detach() did not clear the
> phydev->devlink pointer when the network port was disabled,
> device_link_del() will access a NULL pointer and cause a crash. And this
> crash may cause the CPU to hang. I don't think it is reasonable to cause
> the CPU to hang.
Ah, now i get it...
phy_attach_direct() runs, but fails early, before the call to:
phydev->devlink = device_link_add(dev->dev.parent, &phydev->mdio.dev,
DL_FLAG_PM_RUNTIME | DL_FLAG_STATELESS);
So it has its old value, from a previous attach/detach cycle. At the
error: label, it calls phy_detach(phydev), which does a
device_link_del(), using the old value...
Please improve your changelog message, add more details.
Andrew
---
pw-bot: cr
prev parent reply other threads:[~2025-05-22 16:19 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-22 6:42 Wei Fang
2025-05-22 12:33 ` Andrew Lunn
2025-05-22 13:57 ` Wei Fang
2025-05-22 16:19 ` Andrew Lunn [this message]
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=d8cb2a8f-af3d-4042-96a3-a762df1876a9@lunn.ch \
--to=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=f.fainelli@gmail.com \
--cc=hkallweit1@gmail.com \
--cc=imx@lists.linux.dev \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=wei.fang@nxp.com \
--cc=xiaolei.wang@windriver.com \
/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
all inboxes | Powered by JetHome®