Netdev List
 help / color / mirror / Atom feed
* [PATCHv3 net-next] net: dsa: b53: srab: propagate errors from init helpers
@ 2026-07-29 20:29 Rosen Penev
  2026-08-04 11:00 ` Paolo Abeni
  2026-08-05 17:59 ` Jonas Gorski
  0 siblings, 2 replies; 5+ messages in thread
From: Rosen Penev @ 2026-07-29 20:29 UTC (permalink / raw)
  To: netdev
  Cc: Florian Fainelli, Jonas Gorski, Andrew Lunn, Vladimir Oltean,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	open list

Convert b53_srab_prepare_irq() and b53_srab_mux_init() from void to
int-returning functions so probe failures are properly propagated.

b53_srab_prepare_irq() now returns -ENOMEM on allocation failure and
-EPROBE_DEFER if any port IRQ is not yet available.

b53_srab_mux_init() now returns PTR_ERR on ioremap failure instead of
silently ignoring it.

Check and propagate both return values in b53_srab_probe() so the
driver core sees the real error instead of always reaching
b53_switch_register().

Add error handling in probe as a result of b53_srab_prepare_irq().

Move mux_config out of private struct. This was needed when devm was not used.

Assisted-by: Opencode:Big-Pickle
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 v3: move mux_config to function.
 v2: address memory leak in b53_srab_prepare_irq().
 drivers/net/dsa/b53/b53_srab.c | 46 ++++++++++++++++++++++++----------
 1 file changed, 33 insertions(+), 13 deletions(-)

diff --git a/drivers/net/dsa/b53/b53_srab.c b/drivers/net/dsa/b53/b53_srab.c
index b9939bbd2cd5..81bfd5cd1022 100644
--- a/drivers/net/dsa/b53/b53_srab.c
+++ b/drivers/net/dsa/b53/b53_srab.c
@@ -84,7 +84,6 @@ struct b53_srab_port_priv {
 
 struct b53_srab_priv {
 	void __iomem *regs;
-	void __iomem *mux_config;
 	struct b53_srab_port_priv port_intrs[B53_N_PORTS];
 };
 
@@ -531,7 +530,7 @@ static void b53_srab_intr_set(struct b53_srab_priv *priv, bool set)
 	writel(reg, priv->regs + B53_SRAB_CTRLS);
 }
 
-static void b53_srab_prepare_irq(struct platform_device *pdev)
+static int b53_srab_prepare_irq(struct platform_device *pdev)
 {
 	struct b53_device *dev = platform_get_drvdata(pdev);
 	struct b53_srab_priv *priv = dev->priv;
@@ -551,32 +550,37 @@ static void b53_srab_prepare_irq(struct platform_device *pdev)
 
 		name = kasprintf(GFP_KERNEL, "link_state_p%d", i);
 		if (!name)
-			return;
+			return -ENOMEM;
 
 		port->num = i;
 		port->dev = dev;
 		port->irq = platform_get_irq_byname_optional(pdev, name);
 		kfree(name);
+		if (port->irq == -EPROBE_DEFER)
+			return port->irq;
 	}
 
 	b53_srab_intr_set(priv, true);
+
+	return 0;
 }
 
-static void b53_srab_mux_init(struct platform_device *pdev)
+static int b53_srab_mux_init(struct platform_device *pdev)
 {
 	struct b53_device *dev = platform_get_drvdata(pdev);
 	struct b53_srab_priv *priv = dev->priv;
 	struct b53_srab_port_priv *p;
+	void __iomem *mux_config;
 	unsigned int port;
 	u32 reg, off = 0;
 	int ret;
 
-	if (dev->pdata && dev->pdata->chip_id != BCM58XX_DEVICE_ID)
-		return;
+	if (!dev->pdata || dev->pdata->chip_id != BCM58XX_DEVICE_ID)
+		return 0;
 
-	priv->mux_config = devm_platform_ioremap_resource(pdev, 1);
-	if (IS_ERR(priv->mux_config))
-		return;
+	mux_config = devm_platform_ioremap_resource(pdev, 1);
+	if (IS_ERR(mux_config))
+		return PTR_ERR(mux_config);
 
 	/* Obtain the port mux configuration so we know which lanes
 	 * actually map to SerDes lanes
@@ -584,7 +588,7 @@ static void b53_srab_mux_init(struct platform_device *pdev)
 	for (port = 5; port > 3; port--, off += 4) {
 		p = &priv->port_intrs[port];
 
-		reg = readl(priv->mux_config + B53_MUX_CONFIG_P5 + off);
+		reg = readl(mux_config + B53_MUX_CONFIG_P5 + off);
 		switch (reg & MUX_CONFIG_MASK) {
 		case MUX_CONFIG_SGMII:
 			p->mode = PHY_INTERFACE_MODE_SGMII;
@@ -613,6 +617,8 @@ static void b53_srab_mux_init(struct platform_device *pdev)
 			dev_info(&pdev->dev, "Port %d mode: %s\n",
 				 port, phy_modes(p->mode));
 	}
+
+	return 0;
 }
 
 static int b53_srab_probe(struct platform_device *pdev)
@@ -622,6 +628,7 @@ static int b53_srab_probe(struct platform_device *pdev)
 	const struct of_device_id *of_id = NULL;
 	struct b53_srab_priv *priv;
 	struct b53_device *dev;
+	int err;
 
 	if (dn)
 		of_id = of_match_node(b53_srab_of_match, dn);
@@ -651,10 +658,23 @@ static int b53_srab_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, dev);
 
-	b53_srab_prepare_irq(pdev);
-	b53_srab_mux_init(pdev);
+	err = b53_srab_prepare_irq(pdev);
+	if (err)
+		return err;
+
+	err = b53_srab_mux_init(pdev);
+	if (err)
+		goto err_irq;
+
+	err = b53_switch_register(dev);
+	if (err)
+		goto err_irq;
+
+	return 0;
 
-	return b53_switch_register(dev);
+err_irq:
+	b53_srab_intr_set(priv, false);
+	return err;
 }
 
 static void b53_srab_remove(struct platform_device *pdev)
-- 
2.55.0


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

* Re: [PATCHv3 net-next] net: dsa: b53: srab: propagate errors from init helpers
  2026-07-29 20:29 [PATCHv3 net-next] net: dsa: b53: srab: propagate errors from init helpers Rosen Penev
@ 2026-08-04 11:00 ` Paolo Abeni
  2026-08-04 20:55   ` Rosen Penev
  2026-08-05 17:59 ` Jonas Gorski
  1 sibling, 1 reply; 5+ messages in thread
From: Paolo Abeni @ 2026-08-04 11:00 UTC (permalink / raw)
  To: Rosen Penev, netdev
  Cc: Florian Fainelli, Jonas Gorski, Andrew Lunn, Vladimir Oltean,
	David S. Miller, Eric Dumazet, Jakub Kicinski, open list

On 7/29/26 10:29 PM, Rosen Penev wrote:
> -static void b53_srab_mux_init(struct platform_device *pdev)
> +static int b53_srab_mux_init(struct platform_device *pdev)
>  {
>  	struct b53_device *dev = platform_get_drvdata(pdev);
>  	struct b53_srab_priv *priv = dev->priv;
>  	struct b53_srab_port_priv *p;
> +	void __iomem *mux_config;
>  	unsigned int port;
>  	u32 reg, off = 0;
>  	int ret;
>  
> -	if (dev->pdata && dev->pdata->chip_id != BCM58XX_DEVICE_ID)
> -		return;
> +	if (!dev->pdata || dev->pdata->chip_id != BCM58XX_DEVICE_ID)
> +		return 0;
>  
> -	priv->mux_config = devm_platform_ioremap_resource(pdev, 1);
> -	if (IS_ERR(priv->mux_config))
> -		return;
> +	mux_config = devm_platform_ioremap_resource(pdev, 1);
> +	if (IS_ERR(mux_config))
> +		return PTR_ERR(mux_config);

Sashiko noted this strict checking may cause regression on previously
working setup:

https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260729202953.704662-1-rosenp%40gmail.com

/P


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

* Re: [PATCHv3 net-next] net: dsa: b53: srab: propagate errors from init helpers
  2026-08-04 11:00 ` Paolo Abeni
@ 2026-08-04 20:55   ` Rosen Penev
  2026-08-05  7:16     ` Paolo Abeni
  0 siblings, 1 reply; 5+ messages in thread
From: Rosen Penev @ 2026-08-04 20:55 UTC (permalink / raw)
  To: Paolo Abeni
  Cc: netdev, Florian Fainelli, Jonas Gorski, Andrew Lunn,
	Vladimir Oltean, David S. Miller, Eric Dumazet, Jakub Kicinski,
	open list

On Tue, Aug 4, 2026 at 4:00 AM Paolo Abeni <pabeni@redhat.com> wrote:
>
> On 7/29/26 10:29 PM, Rosen Penev wrote:
> > -static void b53_srab_mux_init(struct platform_device *pdev)
> > +static int b53_srab_mux_init(struct platform_device *pdev)
> >  {
> >       struct b53_device *dev = platform_get_drvdata(pdev);
> >       struct b53_srab_priv *priv = dev->priv;
> >       struct b53_srab_port_priv *p;
> > +     void __iomem *mux_config;
> >       unsigned int port;
> >       u32 reg, off = 0;
> >       int ret;
> >
> > -     if (dev->pdata && dev->pdata->chip_id != BCM58XX_DEVICE_ID)
> > -             return;
> > +     if (!dev->pdata || dev->pdata->chip_id != BCM58XX_DEVICE_ID)
> > +             return 0;
> >
> > -     priv->mux_config = devm_platform_ioremap_resource(pdev, 1);
> > -     if (IS_ERR(priv->mux_config))
> > -             return;
> > +     mux_config = devm_platform_ioremap_resource(pdev, 1);
> > +     if (IS_ERR(mux_config))
> > +             return PTR_ERR(mux_config);
>
> Sashiko noted this strict checking may cause regression on previously
> working setup:
>
> https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260729202953.704662-1-rosenp%40gmail.com
It mentions this only applying to out of tree dtbs.
>
> /P
>

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

* Re: [PATCHv3 net-next] net: dsa: b53: srab: propagate errors from init helpers
  2026-08-04 20:55   ` Rosen Penev
@ 2026-08-05  7:16     ` Paolo Abeni
  0 siblings, 0 replies; 5+ messages in thread
From: Paolo Abeni @ 2026-08-05  7:16 UTC (permalink / raw)
  To: Rosen Penev
  Cc: netdev, Florian Fainelli, Jonas Gorski, Andrew Lunn,
	Vladimir Oltean, David S. Miller, Eric Dumazet, Jakub Kicinski,
	open list

On 8/4/26 10:55 PM, Rosen Penev wrote:
> On Tue, Aug 4, 2026 at 4:00 AM Paolo Abeni <pabeni@redhat.com> wrote:
>>
>> On 7/29/26 10:29 PM, Rosen Penev wrote:
>>> -static void b53_srab_mux_init(struct platform_device *pdev)
>>> +static int b53_srab_mux_init(struct platform_device *pdev)
>>>  {
>>>       struct b53_device *dev = platform_get_drvdata(pdev);
>>>       struct b53_srab_priv *priv = dev->priv;
>>>       struct b53_srab_port_priv *p;
>>> +     void __iomem *mux_config;
>>>       unsigned int port;
>>>       u32 reg, off = 0;
>>>       int ret;
>>>
>>> -     if (dev->pdata && dev->pdata->chip_id != BCM58XX_DEVICE_ID)
>>> -             return;
>>> +     if (!dev->pdata || dev->pdata->chip_id != BCM58XX_DEVICE_ID)
>>> +             return 0;
>>>
>>> -     priv->mux_config = devm_platform_ioremap_resource(pdev, 1);
>>> -     if (IS_ERR(priv->mux_config))
>>> -             return;
>>> +     mux_config = devm_platform_ioremap_resource(pdev, 1);
>>> +     if (IS_ERR(mux_config))
>>> +             return PTR_ERR(mux_config);
>>
>> Sashiko noted this strict checking may cause regression on previously
>> working setup:
>>
>> https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20260729202953.704662-1-rosenp%40gmail.com
> It mentions this only applying to out of tree dtbs.
Ah, it was not obvious to me. Restoring the patch in PW. For the future
please see net-next commit bd5c24e4001d.

/P


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

* Re: [PATCHv3 net-next] net: dsa: b53: srab: propagate errors from init helpers
  2026-07-29 20:29 [PATCHv3 net-next] net: dsa: b53: srab: propagate errors from init helpers Rosen Penev
  2026-08-04 11:00 ` Paolo Abeni
@ 2026-08-05 17:59 ` Jonas Gorski
  1 sibling, 0 replies; 5+ messages in thread
From: Jonas Gorski @ 2026-08-05 17:59 UTC (permalink / raw)
  To: Rosen Penev
  Cc: netdev, Florian Fainelli, Andrew Lunn, Vladimir Oltean,
	David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	open list

Hi,

On Wed, Jul 29, 2026 at 10:29 PM Rosen Penev <rosenp@gmail.com> wrote:
>
> Convert b53_srab_prepare_irq() and b53_srab_mux_init() from void to
> int-returning functions so probe failures are properly propagated.
>
> b53_srab_prepare_irq() now returns -ENOMEM on allocation failure and
> -EPROBE_DEFER if any port IRQ is not yet available.
>
> b53_srab_mux_init() now returns PTR_ERR on ioremap failure instead of
> silently ignoring it.
>
> Check and propagate both return values in b53_srab_probe() so the
> driver core sees the real error instead of always reaching
> b53_switch_register().
>
> Add error handling in probe as a result of b53_srab_prepare_irq().
>
> Move mux_config out of private struct. This was needed when devm was not used.
>
> Assisted-by: Opencode:Big-Pickle
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
>  v3: move mux_config to function.
>  v2: address memory leak in b53_srab_prepare_irq().

Please also mention any review comments you addressed in the
changelog. I don't see any mention of changing the condition in
b53_srab_mux_init().

>  drivers/net/dsa/b53/b53_srab.c | 46 ++++++++++++++++++++++++----------
>  1 file changed, 33 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/net/dsa/b53/b53_srab.c b/drivers/net/dsa/b53/b53_srab.c
> index b9939bbd2cd5..81bfd5cd1022 100644
> --- a/drivers/net/dsa/b53/b53_srab.c
> +++ b/drivers/net/dsa/b53/b53_srab.c

(snip)

> @@ -622,6 +628,7 @@ static int b53_srab_probe(struct platform_device *pdev)
>         const struct of_device_id *of_id = NULL;
>         struct b53_srab_priv *priv;
>         struct b53_device *dev;
> +       int err;
>
>         if (dn)
>                 of_id = of_match_node(b53_srab_of_match, dn);
> @@ -651,10 +658,23 @@ static int b53_srab_probe(struct platform_device *pdev)
>
>         platform_set_drvdata(pdev, dev);
>
> -       b53_srab_prepare_irq(pdev);
> -       b53_srab_mux_init(pdev);
> +       err = b53_srab_prepare_irq(pdev);
> +       if (err)
> +               return err;
> +
> +       err = b53_srab_mux_init(pdev);
> +       if (err)
> +               goto err_irq;

Tbh, I'm not sure if it is a good idea to abort probing on error here.
The mux only applies to 2 of the 6? potential ports, so at worst those
two ports won't work, but other ports should continue to work fine.
And I think reduced functionality is preferable to no functionality;
with a non-probing switch it will likely be harder to recover the
device.

(The values read out from mux could even just be passed on via
phy-mode properties on the ports in the device tree, but that would
require changing the driver ...).

Best regards,
Jonas

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

end of thread, other threads:[~2026-08-05 17:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-29 20:29 [PATCHv3 net-next] net: dsa: b53: srab: propagate errors from init helpers Rosen Penev
2026-08-04 11:00 ` Paolo Abeni
2026-08-04 20:55   ` Rosen Penev
2026-08-05  7:16     ` Paolo Abeni
2026-08-05 17:59 ` Jonas Gorski

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