net: phy: micrel: Fix warn: passing zero to PTR_ERR
Subsystems (3)
PATCH v2 1/1 net: phy: micrel: Fix warn: passing zero to PTR_ERR
Handle the NULL pointer case
Fixes New smatch warnings:drivers/net/phy/micrel.c:2613 lan8814_ptp_probe_once() warn: passing zero to 'PTR_ERR'
vim +/PTR_ERR +2613 drivers/net/phy/micrel.c
---
v1 -> v2:
- Handled NULL pointer case
- Changed subject line with net-next to net
--- drivers/net/phy/micrel.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/net/phy/micrel.c +5 -1
@@ -2812,12 +2812,16 @@ static int lan8814_ptp_probe_once(struct phy_device *phydev) shared->ptp_clock =ptp_clock_register (&shared->ptp_clock_info, &phydev->mdio.dev); -if (IS_ERR_OR_NULL (shared->ptp_clock)) { +if (IS_ERR (shared->ptp_clock)) {phydev_err (phydev,"ptp_clock_register failed %lu\n" ,PTR_ERR (shared->ptp_clock));return -EINVAL ; } +/* Check if PHC support is missing at the configuration level */ +if (!shared->ptp_clock) +return 0 ; +phydev_dbg (phydev,"successfully registered ptp clock\n" ); shared->phydev = phydev;
Signature · 1 line
2.17.1
Quoted 7 lines · Divya Koppera
Handle the NULL pointer case
Fixes New smatch warnings:
drivers/net/phy/micrel.c:2613lan8814_ptp_probe_once()warn: passing zero to 'PTR_ERR'vim +/PTR_ERR +2613
drivers/net/phy/micrel.c
Quoted 8 lines
Reported-by kernel test robot <[email protected]>Reported-by Dan Carpenter <[email protected]>Fixes ece19502834d ("net: phy: micrel: 1588 support for LAN8814 phy")Signed-off-by Divya Koppera <[email protected]>---
v1 -> v2:
- Handled NULL pointer case
- Changed subject line with net-next to net
This is not a genuine bug fix, and so it should target next-next.
Quoted 12 lines
--- drivers/net/phy/micrel.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/net/phy/micrel.c +0
-0@@ -2812,12 +2812,16 @@ static int lan8814_ptp_probe_once(struct phy_device *phydev) shared->ptp_clock =ptp_clock_register (&shared->ptp_clock_info, &phydev->mdio.dev);
drivers/net/phy/micrel.c static int lan8814_ptp_probe_once(struct phy_device *phydev) · line 2823
Quoted 10 lines
drivers/net/phy/micrel.c +4
-1-if (IS_ERR_OR_NULL (shared->ptp_clock)) { +if (IS_ERR (shared->ptp_clock)) {phydev_err (phydev,"ptp_clock_register failed %lu\n" ,PTR_ERR (shared->ptp_clock));return -EINVAL ; } +/* Check if PHC support is missing at the configuration level */ +if (!shared->ptp_clock) +return 0 ;
This is cause a NULL pointer de-reference in lan8814_ts_info() when it calls
info->phc_index = ptp_clock_index(shared->ptp_clock);
Quoted 7 lines
drivers/net/phy/micrel.c +1
-0+phydev_dbg (phydev,"successfully registered ptp clock\n" ); shared->phydev = phydev;Signature · 1 line
2.17.1
Thanks,
Richard
Hi Richard,
Quoted 56 lines
-----Original Message-----
From: Richard Cochran <[email protected]>
Sent: Tuesday, July 19, 2022 7:26 PM
To: Divya Koppera - I30481 <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; UNGLinuxDriver <[email protected]>; Madhuri Sripada - I34878 <[email protected]>
Subject: Re: [PATCH v2 net] net: phy: micrel: Fix warn: passing zero toPTR_ERREXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
Quoted 4 lines · Divya Koppera
Handle the NULL pointer case
Fixes New smatch warnings:
drivers/net/phy/micrel.c:2613lan8814_ptp_probe_once()warn: passingzero to '
PTR_ERR'Quoted 11 lines
vim +/PTR_ERR +2613
drivers/net/phy/micrel.cReported-by kernel test robot <[email protected]>Reported-by Dan Carpenter <[email protected]>Fixes ece19502834d ("net: phy: micrel: 1588 support for LAN8814 phy")Signed-off-by Divya Koppera <[email protected]>---
v1 -> v2:
- Handled NULL pointer case
- Changed subject line with net-next to netThis is not a genuine bug fix, and so it should target next-next.
Quoted 20 lines
--- drivers/net/phy/micrel.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/net/phy/micrel.c index renamed from drivers/net/phy/micrel.c +0
-0
e78d0bf69bc3..6be6ee156f40100644drivers/net/phy/micrel.c +1
-1@@ -2812,12 +2812,16 @@ static int lan8814_ptp_probe_once(struct phy_device *phydev) shared->ptp_clock = ptp_clock_register(&shared->ptp_clock_info, &phydev->mdio.dev); -if (IS_ERR_OR_NULL (shared->ptp_clock)) { +if (IS_ERR (shared->ptp_clock)) {phydev_err (phydev,"ptp_clock_register failed %lu\n" ,PTR_ERR (shared->ptp_clock));return -EINVAL ; }
Quoted 8 lines
drivers/net/phy/micrel.c static int lan8814_ptp_probe_once(struct phy_device *phydev) · line 2823
Quoted 3 lines
drivers/net/phy/micrel.c +3
-0+/* Check if PHC support is missing at the configuration level */ +if (!shared->ptp_clock) +return 0 ;This is cause a NULL pointer de-reference in
lan8814_ts_info()when it callsinfo->phc_index = ptp_clock_index(shared->ptp_clock);
NULL case handling seems to be redundant here because at starting of the function itself there is check for config support of ptp as below
static int lan8814_ptp_probe_once(struct phy_device *phydev)
{
struct lan8814_shared_priv *shared = phydev->shared->priv;
if (!IS_ENABLED(CONFIG_PTP_1588_CLOCK) ||
!IS_ENABLED(CONFIG_NETWORK_PHY_TIMESTAMPING))
return 0;So chances of getting shared-> ptp_clock to be NULL is 0.
Let me know your thoughts. I'll remove this check in next revision if it is redundant.
Quoted 10 lines
Quoted 7 lines
drivers/net/phy/micrel.c +1
-0+phydev_dbg (phydev,"successfully registered ptp clock\n" );shared->phydev = phydev;--
2.17.1Thanks,
Richard
Quoted 7 lines · On Wed, Jul 20, 2022 at 04:32:55AM +0000, [email protected] wrote:
static int
lan8814_ptp_probe_once(struct phy_device *phydev){ struct lan8814_shared_priv *shared = phydev->shared->priv; if (!IS_ENABLED(CONFIG_PTP_1588_CLOCK) || !IS_ENABLED(CONFIG_NETWORK_PHY_TIMESTAMPING)) return 0;
It is weird to use macros here, but not before calling ptp_clock_register. Make it consistent by checking shared->ptp_clock instead.
That is also better form.
Thanks,
Richard