diff mbox series

net: nixge: fix -Wvoid-pointer-to-enum-cast warning

Message ID 20230815-void-drivers-net-ethernet-ni-nixge-v1-1-f096a6e43038@google.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series net: nixge: fix -Wvoid-pointer-to-enum-cast warning | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1330 this patch: 1330
netdev/cc_maintainers warning 2 maintainers not CCed: simon.horman@corigine.com andrew@lunn.ch
netdev/build_clang success Errors and warnings before: 1355 this patch: 1353
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1353 this patch: 1353
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Justin Stitt Aug. 15, 2023, 8:50 p.m. UTC
When building with clang 18 I see the following warning:
|       drivers/net/ethernet/ni/nixge.c:1273:12: warning: cast to smaller integer
|               type 'enum nixge_version' from 'const void *' [-Wvoid-pointer-to-enum-cast]
|        1273 |         version = (enum nixge_version)of_id->data;

This is due to the fact that `of_id->data` is a void* while `enum nixge_version`
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: There is likely no data loss occurring here since `enum nixge_version`
has only a few fields which aren't nearly large enough to cause data
loss. However, this patch still works towards the goal of enabling this
warning for more builds by reducing noise.
---
 drivers/net/ethernet/ni/nixge.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)


---
base-commit: 2ccdd1b13c591d306f0401d98dedc4bdcd02b421
change-id: 20230815-void-drivers-net-ethernet-ni-nixge-37b465831af0

Best regards,
--
Justin Stitt <justinstitt@google.com>

Comments

Simon Horman Aug. 16, 2023, 8:27 a.m. UTC | #1
On Tue, Aug 15, 2023 at 08:50:13PM +0000, Justin Stitt wrote:
> When building with clang 18 I see the following warning:
> |       drivers/net/ethernet/ni/nixge.c:1273:12: warning: cast to smaller integer
> |               type 'enum nixge_version' from 'const void *' [-Wvoid-pointer-to-enum-cast]
> |        1273 |         version = (enum nixge_version)of_id->data;
> 
> This is due to the fact that `of_id->data` is a void* while `enum nixge_version`
> 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: There is likely no data loss occurring here since `enum nixge_version`
> has only a few fields which aren't nearly large enough to cause data
> loss. However, this patch still works towards the goal of enabling this
> warning for more builds by reducing noise.

This information might be better placed in the patch description,
above the scissors (---) and tags ("Link:", ...)

And, although I did make an error in this area myself as recently as
yesterday, this patch should probably be tagged as being for net-next.
It's probably not necessary to repost for this.

	Subject: [PATCH net-next] ...

The above notwithstanding,

Reviewed-by: Simon Horman <horms@kernel.org>
Tested-by: Simon Horman <horms@kernel.org> # build-tested
diff mbox series

Patch

diff --git a/drivers/net/ethernet/ni/nixge.c b/drivers/net/ethernet/ni/nixge.c
index 0fd156286d4d..105977804e6a 100644
--- a/drivers/net/ethernet/ni/nixge.c
+++ b/drivers/net/ethernet/ni/nixge.c
@@ -1270,7 +1270,7 @@  static int nixge_of_get_resources(struct platform_device *pdev)
 	if (!of_id)
 		return -ENODEV;
 
-	version = (enum nixge_version)of_id->data;
+	version = (uintptr_t)of_id->data;
 	if (version <= NIXGE_V2)
 		priv->dma_regs = devm_platform_get_and_ioremap_resource(pdev, 0, NULL);
 	else