* [PATCH net v2] net: stmmac: add clk_prepare_enable() error handling
@ 2025-11-14 14:23 Pavel Zhigulin
2025-11-18 14:30 ` Paolo Abeni
0 siblings, 1 reply; 4+ messages in thread
From: Pavel Zhigulin @ 2025-11-14 14:23 UTC (permalink / raw)
To: Andrew Lunn
Cc: Pavel Zhigulin, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Maxime Coquelin, Alexandre Torgue, Maxime Chevallier,
Inochi Amaoto, Quentin Schulz, Joe Hattori, Rayagond Kokatanur,
Giuseppe CAVALLARO, netdev, linux-stm32, linux-arm-kernel,
linux-kernel, lvc-project
The driver previously ignored the return value of 'clk_prepare_enable()'
for both the CSR clock and the PCLK in 'stmmac_probe_config_dt()' function.
Add 'clk_prepare_enable()' return value checks.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Fixes: bfab27a146ed ("stmmac: add the experimental PCI support")
Signed-off-by: Pavel Zhigulin <Pavel.Zhigulin@kaspersky.com>
---
v2: Fix 'ret' value initialization after build bot notification.
v1: https://lore.kernel.org/all/20251113134009.79440-1-Pavel.Zhigulin@kaspersky.com/
drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
index 27bcaae07a7f..8f9eb9683d2b 100644
--- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
+++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
@@ -632,7 +632,9 @@ stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac)
dev_warn(&pdev->dev, "Cannot get CSR clock\n");
plat->stmmac_clk = NULL;
}
- clk_prepare_enable(plat->stmmac_clk);
+ rc = clk_prepare_enable(plat->stmmac_clk);
+ if (rc < 0)
+ dev_warn(&pdev->dev, "Cannot enable CSR clock: %d\n", rc);
}
plat->pclk = devm_clk_get_optional(&pdev->dev, "pclk");
@@ -640,7 +642,12 @@ stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac)
ret = plat->pclk;
goto error_pclk_get;
}
- clk_prepare_enable(plat->pclk);
+ rc = clk_prepare_enable(plat->pclk);
+ if (rc < 0) {
+ ret = ERR_PTR(rc);
+ dev_err(&pdev->dev, "Cannot enable pclk: %d\n", rc);
+ goto error_pclk_get;
+ }
/* Fall-back to main clock in case of no PTP ref is passed */
plat->clk_ptp_ref = devm_clk_get(&pdev->dev, "ptp_ref");
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net v2] net: stmmac: add clk_prepare_enable() error handling
2025-11-14 14:23 [PATCH net v2] net: stmmac: add clk_prepare_enable() error handling Pavel Zhigulin
@ 2025-11-18 14:30 ` Paolo Abeni
2025-11-18 14:42 ` Paolo Abeni
2025-11-18 17:14 ` Russell King (Oracle)
0 siblings, 2 replies; 4+ messages in thread
From: Paolo Abeni @ 2025-11-18 14:30 UTC (permalink / raw)
To: Pavel Zhigulin, Andrew Lunn
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Maxime Coquelin,
Alexandre Torgue, Maxime Chevallier, Inochi Amaoto,
Quentin Schulz, Joe Hattori, Rayagond Kokatanur,
Giuseppe CAVALLARO, netdev, linux-stm32, linux-arm-kernel,
linux-kernel, lvc-project
On 11/14/25 3:23 PM, Pavel Zhigulin wrote:
> The driver previously ignored the return value of 'clk_prepare_enable()'
> for both the CSR clock and the PCLK in 'stmmac_probe_config_dt()' function.
>
> Add 'clk_prepare_enable()' return value checks.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Fixes: bfab27a146ed ("stmmac: add the experimental PCI support")
> Signed-off-by: Pavel Zhigulin <Pavel.Zhigulin@kaspersky.com>
> ---
> v2: Fix 'ret' value initialization after build bot notification.
> v1: https://lore.kernel.org/all/20251113134009.79440-1-Pavel.Zhigulin@kaspersky.com/
>
> drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c | 11 +++++++++--
> 1 file changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
> index 27bcaae07a7f..8f9eb9683d2b 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
> @@ -632,7 +632,9 @@ stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac)
> dev_warn(&pdev->dev, "Cannot get CSR clock\n");
> plat->stmmac_clk = NULL;
> }
> - clk_prepare_enable(plat->stmmac_clk);
> + rc = clk_prepare_enable(plat->stmmac_clk);
> + if (rc < 0)
> + dev_warn(&pdev->dev, "Cannot enable CSR clock: %d\n", rc);
> }
>
> plat->pclk = devm_clk_get_optional(&pdev->dev, "pclk");
> @@ -640,7 +642,12 @@ stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac)
> ret = plat->pclk;
> goto error_pclk_get;
> }
> - clk_prepare_enable(plat->pclk);
> + rc = clk_prepare_enable(plat->pclk);
> + if (rc < 0) {
> + ret = ERR_PTR(rc);
> + dev_err(&pdev->dev, "Cannot enable pclk: %d\n", rc);
> + goto error_pclk_get;
> + }
It looks like the driver is supposed to handle the
IS_ERR_OR_NULL(plat->pclk) condition. This check could cause regression
on existing setup currently failing to initialize the (optional) clock
and still being functional.
I *think* we are better off without the added checks.
/P
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net v2] net: stmmac: add clk_prepare_enable() error handling
2025-11-18 14:30 ` Paolo Abeni
@ 2025-11-18 14:42 ` Paolo Abeni
2025-11-18 17:14 ` Russell King (Oracle)
1 sibling, 0 replies; 4+ messages in thread
From: Paolo Abeni @ 2025-11-18 14:42 UTC (permalink / raw)
To: Pavel Zhigulin, Andrew Lunn
Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Maxime Coquelin,
Alexandre Torgue, Maxime Chevallier, Inochi Amaoto,
Quentin Schulz, Joe Hattori, Rayagond Kokatanur,
Giuseppe CAVALLARO, netdev, linux-stm32, linux-arm-kernel,
linux-kernel, lvc-project
On 11/18/25 3:30 PM, Paolo Abeni wrote:
> On 11/14/25 3:23 PM, Pavel Zhigulin wrote:
>> The driver previously ignored the return value of 'clk_prepare_enable()'
>> for both the CSR clock and the PCLK in 'stmmac_probe_config_dt()' function.
>>
>> Add 'clk_prepare_enable()' return value checks.
>>
>> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>>
>> Fixes: bfab27a146ed ("stmmac: add the experimental PCI support")
>> Signed-off-by: Pavel Zhigulin <Pavel.Zhigulin@kaspersky.com>
>> ---
>> v2: Fix 'ret' value initialization after build bot notification.
>> v1: https://lore.kernel.org/all/20251113134009.79440-1-Pavel.Zhigulin@kaspersky.com/
>>
>> drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c | 11 +++++++++--
>> 1 file changed, 9 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
>> index 27bcaae07a7f..8f9eb9683d2b 100644
>> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
>> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
>> @@ -632,7 +632,9 @@ stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac)
>> dev_warn(&pdev->dev, "Cannot get CSR clock\n");
>> plat->stmmac_clk = NULL;
>> }
>> - clk_prepare_enable(plat->stmmac_clk);
>> + rc = clk_prepare_enable(plat->stmmac_clk);
>> + if (rc < 0)
>> + dev_warn(&pdev->dev, "Cannot enable CSR clock: %d\n", rc);
>> }
>>
>> plat->pclk = devm_clk_get_optional(&pdev->dev, "pclk");
>> @@ -640,7 +642,12 @@ stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac)
>> ret = plat->pclk;
>> goto error_pclk_get;
>> }
>> - clk_prepare_enable(plat->pclk);
>> + rc = clk_prepare_enable(plat->pclk);
>> + if (rc < 0) {
>> + ret = ERR_PTR(rc);
>> + dev_err(&pdev->dev, "Cannot enable pclk: %d\n", rc);
>> + goto error_pclk_get;
>> + }
>
> It looks like the driver is supposed to handle the
> IS_ERR_OR_NULL(plat->pclk) condition. This check could cause regression
> on existing setup currently failing to initialize the (optional) clock
> and still being functional.
I'm sorry, ENOCOFFEE above, ->pclk is not NULL nor ERR when
clk_prepare_enable() fails. Still I don't stmmac code depending pclk
being successfully initialized, and the eventual regression looks like a
real possibility.
/P
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net v2] net: stmmac: add clk_prepare_enable() error handling
2025-11-18 14:30 ` Paolo Abeni
2025-11-18 14:42 ` Paolo Abeni
@ 2025-11-18 17:14 ` Russell King (Oracle)
1 sibling, 0 replies; 4+ messages in thread
From: Russell King (Oracle) @ 2025-11-18 17:14 UTC (permalink / raw)
To: Paolo Abeni
Cc: Pavel Zhigulin, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Maxime Coquelin, Alexandre Torgue,
Maxime Chevallier, Inochi Amaoto, Quentin Schulz, Joe Hattori,
Rayagond Kokatanur, Giuseppe CAVALLARO, netdev, linux-stm32,
linux-arm-kernel, linux-kernel, lvc-project
On Tue, Nov 18, 2025 at 03:30:09PM +0100, Paolo Abeni wrote:
> On 11/14/25 3:23 PM, Pavel Zhigulin wrote:
> > The driver previously ignored the return value of 'clk_prepare_enable()'
> > for both the CSR clock and the PCLK in 'stmmac_probe_config_dt()' function.
> >
> > Add 'clk_prepare_enable()' return value checks.
> >
> > Found by Linux Verification Center (linuxtesting.org) with SVACE.
> >
> > Fixes: bfab27a146ed ("stmmac: add the experimental PCI support")
> > Signed-off-by: Pavel Zhigulin <Pavel.Zhigulin@kaspersky.com>
> > ---
> > v2: Fix 'ret' value initialization after build bot notification.
> > v1: https://lore.kernel.org/all/20251113134009.79440-1-Pavel.Zhigulin@kaspersky.com/
> >
> > drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c | 11 +++++++++--
> > 1 file changed, 9 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
> > index 27bcaae07a7f..8f9eb9683d2b 100644
> > --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
> > +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
> > @@ -632,7 +632,9 @@ stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac)
> > dev_warn(&pdev->dev, "Cannot get CSR clock\n");
> > plat->stmmac_clk = NULL;
> > }
> > - clk_prepare_enable(plat->stmmac_clk);
> > + rc = clk_prepare_enable(plat->stmmac_clk);
> > + if (rc < 0)
> > + dev_warn(&pdev->dev, "Cannot enable CSR clock: %d\n", rc);
> > }
> >
> > plat->pclk = devm_clk_get_optional(&pdev->dev, "pclk");
> > @@ -640,7 +642,12 @@ stmmac_probe_config_dt(struct platform_device *pdev, u8 *mac)
> > ret = plat->pclk;
> > goto error_pclk_get;
> > }
> > - clk_prepare_enable(plat->pclk);
> > + rc = clk_prepare_enable(plat->pclk);
> > + if (rc < 0) {
> > + ret = ERR_PTR(rc);
> > + dev_err(&pdev->dev, "Cannot enable pclk: %d\n", rc);
> > + goto error_pclk_get;
> > + }
>
> It looks like the driver is supposed to handle the
> IS_ERR_OR_NULL(plat->pclk) condition. This check could cause regression
> on existing setup currently failing to initialize the (optional) clock
> and still being functional.
>
> I *think* we are better off without the added checks.
Note that the clk API permits NULL as valid. CCF checks for this
in clk_prepare() and avoids returning an error:
if (!clk)
return 0;
Same check in clk_enable(). So if plat->pclk is NULL, then no error
will be returned.
Places that set plat->pclk:
stmmac_probe_config_dt() - checks for error-pointers and fails. This
will cause driver probe failure.
dwc_qos_probe() - uses stmmac_pltfr_find_clk() which returns the
clk from the bulk-get or NULL. These clocks will have been obtained
using devm_clk_bulk_get_all_enabled(), which I think will return an
error if any fail, which fails the driver probe.
So, I don't think plat->pclk can be an error-pointer here.
Therefore, I don't think there's any concern with error pointers
or NULL in plat->pclk.
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-11-18 17:14 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-14 14:23 [PATCH net v2] net: stmmac: add clk_prepare_enable() error handling Pavel Zhigulin
2025-11-18 14:30 ` Paolo Abeni
2025-11-18 14:42 ` Paolo Abeni
2025-11-18 17:14 ` Russell King (Oracle)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).