net: mdio: fix -Wvoid-pointer-to-enum-cast warning
Subsystems (4)
PATCH 1/1 net: mdio: fix -Wvoid-pointer-to-enum-cast warning
When building with clang 18 I see the following warning:
| drivers/net/mdio/mdio-xgene.c:338:13: warning: cast to smaller integer | type 'enum xgene_mdio_id' from 'const void *' [-Wvoid-pointer-to-enum-cast] | 338 | mdio_id = (enum xgene_mdio_id)of_id->data;
This is due to the fact that of_id->data is a void* while enum xgene_mdio_id has the size of an int. This leads to truncation and possible data loss.
---
Note: xgene_mdio_id has only two fields enumerated from 1 which means this is no data loss happening here. Either way, this patch helps the goal of eventually enabling this warning for more builds by reducing noise.
--- drivers/net/mdio/mdio-xgene.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/mdio/mdio-xgene.c +1 -1
@@ -335,7 +335,7 @@ static int xgene_mdio_probe(struct platform_device *pdev) of_id =of_match_device (xgene_mdio_of_match, &pdev->dev);if (of_id) { - mdio_id = (enum xgene_mdio_id )of_id->data; + mdio_id = (uintptr_t )of_id->data; }else {#ifdef CONFIG_ACPI const struct acpi_device_id *acpi_id;
---
base-commit: 2ccdd1b13c591d306f0401d98dedc4bdcd02b421
change-id: 20230815-void-drivers-net-mdio-mdio-xgene-e5b3b4a3343b
Best regards,
--
Justin Stitt <[email protected]>
Quoted 5 lines · Justin Stitt
When building with clang 18 I see the following warning:
| drivers/net/mdio/mdio-xgene.c:338:13: warning: cast to smaller integer | type 'enum xgene_mdio_id' from 'const void *' [-Wvoid-pointer-to-enum-cast] | 338 | mdio_id = (enum xgene_mdio_id)of_id->data;
Quoted 7 lines
This is due to the fact that
of_id->datais a void* whileenum xgene_mdio_idhas the size of an int. This leads to truncation and possible data loss.Reported-by Nathan Chancellor <[email protected]>Signed-off-by Justin Stitt <[email protected]>
Andrew
Quoted 10 lines · Andrew Lunn
Quoted 9 lines · Justin Stitt
When building with clang 18 I see the following warning:
| drivers/net/mdio/mdio-xgene.c:338:13: warning: cast to smaller integer | type 'enum xgene_mdio_id' from 'const void *' [-Wvoid-pointer-to-enum-cast] | 338 | mdio_id = (enum xgene_mdio_id)of_id->data;This is due to the fact that
of_id->datais a void* whileenum xgene_mdio_idhas the size of an int. This leads to truncation and possible data loss.
Quoted 5 lines
Quoted 3 lines
Reported-by Nathan Chancellor <[email protected]>Signed-off-by Justin Stitt <[email protected]>Reviewed-by Andrew Lunn <[email protected]>
I wonder whether it would be better to use device_get_match_data() here? The whole of_match_device()...acpi_match_device() dance could become:
+ mdio_id = (uintptr_t)device_get_match_data(&pdev->dev); if (!mdio_id) return -ENODEV;
It's probably something for a follow-up patch though.
Thanks!
Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 10 lines · On Tue, 15 Aug 2023 20:35:59 +0000 you wrote:
When building with clang 18 I see the following warning:
| drivers/net/mdio/mdio-xgene.c:338:13: warning: cast to smaller integer | type 'enum xgene_mdio_id' from 'const void *' [-Wvoid-pointer-to-enum-cast] | 338 | mdio_id = (enum xgene_mdio_id)of_id->data;This is due to the fact that
of_id->datais a void* whileenum xgene_mdio_idhas the size of an int. This leads to truncation and possible data loss.[...]
Here is the summary with links:
- net: mdio: fix -Wvoid-pointer-to-enum-cast warning
https://git.kernel.org/netdev/net-next/c/f3add6dec36d
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html