netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: mdio: fix -Wvoid-pointer-to-enum-cast warning
@ 2023-08-15 20:35 Justin Stitt
  2023-08-15 20:41 ` Andrew Lunn
  2023-08-18  3:10 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 4+ messages in thread
From: Justin Stitt @ 2023-08-15 20:35 UTC (permalink / raw)
  To: Iyappan Subramanian, Keyur Chudgar, Quan Nguyen, Andrew Lunn,
	Heiner Kallweit, Russell King, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Nathan Chancellor, Nick Desaulniers,
	Tom Rix
  Cc: netdev, linux-kernel, llvm, 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->data` is a void* while `enum
xgene_mdio_id` has the size of an int. This leads to truncation and
possible data loss.

Link: https://github.com/ClangBuiltLinux/linux/issues/1910
Reported-by: Nathan Chancellor <nathan@kernel.org>
Signed-off-by: Justin Stitt <justinstitt@google.com>
---
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(-)

diff --git a/drivers/net/mdio/mdio-xgene.c b/drivers/net/mdio/mdio-xgene.c
index 7aafc221b5cf..7119eb11c00d 100644
--- a/drivers/net/mdio/mdio-xgene.c
+++ b/drivers/net/mdio/mdio-xgene.c
@@ -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 <justinstitt@google.com>


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

* Re: [PATCH] net: mdio: fix -Wvoid-pointer-to-enum-cast warning
  2023-08-15 20:35 [PATCH] net: mdio: fix -Wvoid-pointer-to-enum-cast warning Justin Stitt
@ 2023-08-15 20:41 ` Andrew Lunn
  2023-08-16  9:51   ` Russell King (Oracle)
  2023-08-18  3:10 ` patchwork-bot+netdevbpf
  1 sibling, 1 reply; 4+ messages in thread
From: Andrew Lunn @ 2023-08-15 20:41 UTC (permalink / raw)
  To: Justin Stitt
  Cc: Iyappan Subramanian, Keyur Chudgar, Quan Nguyen, Heiner Kallweit,
	Russell King, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Nathan Chancellor, Nick Desaulniers, Tom Rix, netdev,
	linux-kernel, llvm

On Tue, Aug 15, 2023 at 08:35:59PM +0000, Justin Stitt 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->data` is a void* while `enum
> xgene_mdio_id` has the size of an int. This leads to truncation and
> possible data loss.
> 
> Link: https://github.com/ClangBuiltLinux/linux/issues/1910
> Reported-by: Nathan Chancellor <nathan@kernel.org>
> Signed-off-by: Justin Stitt <justinstitt@google.com>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew

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

* Re: [PATCH] net: mdio: fix -Wvoid-pointer-to-enum-cast warning
  2023-08-15 20:41 ` Andrew Lunn
@ 2023-08-16  9:51   ` Russell King (Oracle)
  0 siblings, 0 replies; 4+ messages in thread
From: Russell King (Oracle) @ 2023-08-16  9:51 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: Justin Stitt, Iyappan Subramanian, Keyur Chudgar, Quan Nguyen,
	Heiner Kallweit, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Nathan Chancellor, Nick Desaulniers, Tom Rix, netdev,
	linux-kernel, llvm

On Tue, Aug 15, 2023 at 10:41:39PM +0200, Andrew Lunn wrote:
> On Tue, Aug 15, 2023 at 08:35:59PM +0000, Justin Stitt 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->data` is a void* while `enum
> > xgene_mdio_id` has the size of an int. This leads to truncation and
> > possible data loss.
> > 
> > Link: https://github.com/ClangBuiltLinux/linux/issues/1910
> > Reported-by: Nathan Chancellor <nathan@kernel.org>
> > Signed-off-by: Justin Stitt <justinstitt@google.com>
> 
> Reviewed-by: Andrew Lunn <andrew@lunn.ch>

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.

Reviewed-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk>

Thanks!

-- 
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

* Re: [PATCH] net: mdio: fix -Wvoid-pointer-to-enum-cast warning
  2023-08-15 20:35 [PATCH] net: mdio: fix -Wvoid-pointer-to-enum-cast warning Justin Stitt
  2023-08-15 20:41 ` Andrew Lunn
@ 2023-08-18  3:10 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-08-18  3:10 UTC (permalink / raw)
  To: Justin Stitt
  Cc: iyappan, keyur, quan, andrew, hkallweit1, linux, davem, edumazet,
	kuba, pabeni, nathan, ndesaulniers, trix, netdev, linux-kernel,
	llvm

Hello:

This patch was applied to netdev/net-next.git (main)
by Jakub Kicinski <kuba@kernel.org>:

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->data` is a void* while `enum
> xgene_mdio_id` has 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!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2023-08-18  3:10 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-15 20:35 [PATCH] net: mdio: fix -Wvoid-pointer-to-enum-cast warning Justin Stitt
2023-08-15 20:41 ` Andrew Lunn
2023-08-16  9:51   ` Russell King (Oracle)
2023-08-18  3:10 ` patchwork-bot+netdevbpf

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).