net: dsa: b53: srab: propagate errors from init helpers
PATCH v2 1/1 net: dsa: b53: srab: propagate errors from init helpers
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().
---
v2: address memory leak in b53_srab_prepare_irq().
drivers/net/dsa/b53/b53_srab.c | 36 ++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-)
drivers/net/dsa/b53/b53_srab.c +28 -8
@@ -531,7 +531,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,18 +551,22 @@ 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;
@@ -572,11 +576,11 @@ static void b53_srab_mux_init(struct platform_device *pdev)int ret;if (dev->pdata && dev->pdata->chip_id !=BCM58XX_DEVICE_ID ) -return ; +return -ENODEV ; priv->mux_config =devm_platform_ioremap_resource (pdev,1 );if (IS_ERR (priv->mux_config)) -return ; +return PTR_ERR (priv->mux_config);/* Obtain the port mux configuration so we know which lanes * actually map to SerDes lanes
@@ -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)
Signature · 1 line
2.55.0
Jonas Gorski
maintainerHi,
Quoted 62 lines · Rosen Penev
Convert
b53_srab_prepare_irq()andb53_srab_mux_init()from void to int-returning functions so probe failures are properly propagated.
b53_srab_prepare_irq()now returns-ENOMEMon allocation failure and -EPROBE_DEFER if any port IRQ is not yet available.
b53_srab_mux_init()now returnsPTR_ERRon 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 reachingb53_switch_register().Add error handling in probe as a result of
b53_srab_prepare_irq().Assisted-by Opencode:Big-PickleSigned-off-by Rosen Penev <[email protected]>---
v2: address memory leak inb53_srab_prepare_irq().drivers/net/dsa/b53/b53_srab.c | 36 ++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-)drivers/net/dsa/b53/b53_srab.c +7
-3@@ -531,7 +531,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,18 +551,22 @@ 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;
drivers/net/dsa/b53/b53_srab.c static void b53_srab_mux_init(struct platform_device *pdev) · line 579
Quoted 5 lines
drivers/net/dsa/b53/b53_srab.c +1
-1@@ -572,11 +576,11 @@ static void b53_srab_mux_init(struct platform_device *pdev)int ret;if (dev->pdata && dev->pdata->chip_id !=BCM58XX_DEVICE_ID ) -return ; +return -ENODEV ;
I don't think this is correct. If you look at the b53_srab_of_match[] table, only some srab devices have BCM58XX_DEVICE_ID, so returning an error code here would break probing all other srab devices.
Just returning 0 here is not enough though ...
drivers/net/dsa/b53/b53_srab.c static void b53_srab_mux_init(struct platform_device *pdev) · line 583
Quoted 5 lines
drivers/net/dsa/b53/b53_srab.c +1
-1priv->mux_config =devm_platform_ioremap_resource (pdev,1 );if (IS_ERR (priv->mux_config)) -return ; +return PTR_ERR (priv->mux_config);
... since some devices don't have match data, so their pdata is unpoulated and the above check would still allow them, so they would then be rejected here.
So the above check should be if (!dev->pdata || dev->pdata->chip_id != BCM58XX_DEVICE_ID) return 0;
Best regards,
Jonas
Quoted 84 lines · Jonas Gorski
Hi,
Quoted 62 lines · Rosen Penev
Convert
b53_srab_prepare_irq()andb53_srab_mux_init()from void to int-returning functions so probe failures are properly propagated.
b53_srab_prepare_irq()now returns-ENOMEMon allocation failure and -EPROBE_DEFER if any port IRQ is not yet available.
b53_srab_mux_init()now returnsPTR_ERRon 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 reachingb53_switch_register().Add error handling in probe as a result of
b53_srab_prepare_irq().Assisted-by Opencode:Big-PickleSigned-off-by Rosen Penev <[email protected]>---
v2: address memory leak inb53_srab_prepare_irq().drivers/net/dsa/b53/b53_srab.c | 36 ++++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-)drivers/net/dsa/b53/b53_srab.c +7
-3@@ -531,7 +531,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,18 +551,22 @@ 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;drivers/net/dsa/b53/b53_srab.c static void b53_srab_mux_init(struct platform_device *pdev) · line 579
Quoted 5 lines
drivers/net/dsa/b53/b53_srab.c +1
-1@@ -572,11 +576,11 @@ static void b53_srab_mux_init(struct platform_device *pdev)int ret;if (dev->pdata && dev->pdata->chip_id !=BCM58XX_DEVICE_ID ) -return ; +return -ENODEV ;I don't think this is correct. If you look at the b53_srab_of_match[] table, only some srab devices have
BCM58XX_DEVICE_ID, so returning an error code here would break probing all other srab devices.Just returning 0 here is not enough though ...
drivers/net/dsa/b53/b53_srab.c static void b53_srab_mux_init(struct platform_device *pdev) · line 583
Quoted 5 lines
drivers/net/dsa/b53/b53_srab.c +1
-1priv->mux_config =devm_platform_ioremap_resource (pdev,1 );if (IS_ERR (priv->mux_config)) -return ; +return PTR_ERR (priv->mux_config);
Quoted 6 lines
... since some devices don't have match data, so their pdata is unpoulated and the above check would still allow them, so they would then be rejected here.
So the above check should be if (!dev->pdata ||
dev->pdata->chip_id!=BCM58XX_DEVICE_ID) return 0;
I thought this as well. That was v1. Guess I'll send a v3 the same as v1...
Quoted 3 lines
Best regards,
Jonas