Skip to content

Commit 794cd13

Browse files
LorenzoBianconiNipaLocal
authored andcommitted
net: airoha: Move net_devs registration in a dedicated routine
Since airoha_probe() is not executed under rtnl lock, there is small race where a given device is configured by user-space while the remaining ones are not completely loaded from the dts yet. This condition will allow a hw device misconfiguration since there are some conditions (e.g. GDM2 check in airoha_dev_init()) that require all device are properly loaded from the device tree. Fix the issue moving net_devices registration at the end of the airoha_probe routine. Fixes: 9cd451d ("net: airoha: Add loopback support for GDM2") Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org> Reviewed-by: Simon Horman <horms@kernel.org> Signed-off-by: NipaLocal <nipa@local>
1 parent a27ef29 commit 794cd13

File tree

1 file changed

+26
-13
lines changed

1 file changed

+26
-13
lines changed

drivers/net/ethernet/airoha/airoha_eth.c

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2924,19 +2924,26 @@ static int airoha_alloc_gdm_port(struct airoha_eth *eth,
29242924
port->id = id;
29252925
eth->ports[p] = port;
29262926

2927-
err = airoha_metadata_dst_alloc(port);
2928-
if (err)
2929-
return err;
2927+
return airoha_metadata_dst_alloc(port);
2928+
}
29302929

2931-
err = register_netdev(dev);
2932-
if (err)
2933-
goto free_metadata_dst;
2930+
static int airoha_register_gdm_devices(struct airoha_eth *eth)
2931+
{
2932+
int i;
29342933

2935-
return 0;
2934+
for (i = 0; i < ARRAY_SIZE(eth->ports); i++) {
2935+
struct airoha_gdm_port *port = eth->ports[i];
2936+
int err;
29362937

2937-
free_metadata_dst:
2938-
airoha_metadata_dst_free(port);
2939-
return err;
2938+
if (!port)
2939+
continue;
2940+
2941+
err = register_netdev(port->dev);
2942+
if (err)
2943+
return err;
2944+
}
2945+
2946+
return 0;
29402947
}
29412948

29422949
static int airoha_probe(struct platform_device *pdev)
@@ -3027,6 +3034,10 @@ static int airoha_probe(struct platform_device *pdev)
30273034
}
30283035
}
30293036

3037+
err = airoha_register_gdm_devices(eth);
3038+
if (err)
3039+
goto error_napi_stop;
3040+
30303041
return 0;
30313042

30323043
error_napi_stop:
@@ -3040,10 +3051,12 @@ static int airoha_probe(struct platform_device *pdev)
30403051
for (i = 0; i < ARRAY_SIZE(eth->ports); i++) {
30413052
struct airoha_gdm_port *port = eth->ports[i];
30423053

3043-
if (port && port->dev->reg_state == NETREG_REGISTERED) {
3054+
if (!port)
3055+
continue;
3056+
3057+
if (port->dev->reg_state == NETREG_REGISTERED)
30443058
unregister_netdev(port->dev);
3045-
airoha_metadata_dst_free(port);
3046-
}
3059+
airoha_metadata_dst_free(port);
30473060
}
30483061
free_netdev(eth->napi_dev);
30493062
platform_set_drvdata(pdev, NULL);

0 commit comments

Comments
 (0)