diff mbox series

[net-next] net: sparx5: Do not use mac_addr uninitialized in mchp_sparx5_probe()

Message ID 20210627184543.4122478-1-nathan@kernel.org (mailing list archive)
State Accepted
Commit b74ef9f9cb91fc86c642af965b7598c4df1c9922
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net: sparx5: Do not use mac_addr uninitialized in mchp_sparx5_probe() | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Clearly marked for net-next
netdev/subject_prefix success Link
netdev/cc_maintainers fail 2 blamed authors not CCed: p.zabel@pengutronix.de bjarni.jonasson@microchip.com; 3 maintainers not CCed: linux-arm-kernel@lists.infradead.org p.zabel@pengutronix.de bjarni.jonasson@microchip.com
netdev/source_inline success Was 0 now: 0
netdev/verify_signedoff success Link
netdev/module_param success Was 0 now: 0
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/verify_fixes success Link
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 20 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success Link

Commit Message

Nathan Chancellor June 27, 2021, 6:45 p.m. UTC
Clang warns:

drivers/net/ethernet/microchip/sparx5/sparx5_main.c:760:29: warning:
variable 'mac_addr' is uninitialized when used here [-Wuninitialized]
        if (of_get_mac_address(np, mac_addr)) {
                                   ^~~~~~~~
drivers/net/ethernet/microchip/sparx5/sparx5_main.c:669:14: note:
initialize the variable 'mac_addr' to silence this warning
        u8 *mac_addr;
                    ^
                     = NULL
1 warning generated.

mac_addr is only used to store the value retrieved from
of_get_mac_address(), which is then copied into the base_mac member of
the sparx5 struct using ether_addr_copy(). It is easier to just use the
base_mac address directly, which avoids the warning and the extra copy.

Fixes: 3cfa11bac9bb ("net: sparx5: add the basic sparx5 driver")
Link: https://github.com/ClangBuiltLinux/linux/issues/1413
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
 drivers/net/ethernet/microchip/sparx5/sparx5_main.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)


base-commit: ff8744b5eb116fdf9b80a6ff774393afac7325bd

Comments

patchwork-bot+netdevbpf@kernel.org June 28, 2021, 11:10 p.m. UTC | #1
Hello:

This patch was applied to netdev/net-next.git (refs/heads/master):

On Sun, 27 Jun 2021 11:45:43 -0700 you wrote:
> Clang warns:
> 
> drivers/net/ethernet/microchip/sparx5/sparx5_main.c:760:29: warning:
> variable 'mac_addr' is uninitialized when used here [-Wuninitialized]
>         if (of_get_mac_address(np, mac_addr)) {
>                                    ^~~~~~~~
> drivers/net/ethernet/microchip/sparx5/sparx5_main.c:669:14: note:
> initialize the variable 'mac_addr' to silence this warning
>         u8 *mac_addr;
>                     ^
>                      = NULL
> 1 warning generated.
> 
> [...]

Here is the summary with links:
  - [net-next] net: sparx5: Do not use mac_addr uninitialized in mchp_sparx5_probe()
    https://git.kernel.org/netdev/net-next/c/b74ef9f9cb91

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
diff mbox series

Patch

diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_main.c b/drivers/net/ethernet/microchip/sparx5/sparx5_main.c
index a325f7c05a07..c73359de3fdd 100644
--- a/drivers/net/ethernet/microchip/sparx5/sparx5_main.c
+++ b/drivers/net/ethernet/microchip/sparx5/sparx5_main.c
@@ -666,7 +666,6 @@  static int mchp_sparx5_probe(struct platform_device *pdev)
 	struct reset_control *reset;
 	struct sparx5 *sparx5;
 	int idx = 0, err = 0;
-	u8 *mac_addr;
 
 	if (!np && !pdev->dev.platform_data)
 		return -ENODEV;
@@ -757,12 +756,10 @@  static int mchp_sparx5_probe(struct platform_device *pdev)
 	if (err)
 		goto cleanup_config;
 
-	if (of_get_mac_address(np, mac_addr)) {
+	if (!of_get_mac_address(np, sparx5->base_mac)) {
 		dev_info(sparx5->dev, "MAC addr was not set, use random MAC\n");
 		eth_random_addr(sparx5->base_mac);
 		sparx5->base_mac[5] = 0;
-	} else {
-		ether_addr_copy(sparx5->base_mac, mac_addr);
 	}
 
 	sparx5->xtr_irq = platform_get_irq_byname(sparx5->pdev, "xtr");