diff mbox series

net: phy: initialize ge and fe variables

Message ID 20210530192943.2556076-1-trix@redhat.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series net: phy: initialize ge and fe variables | expand

Checks

Context Check Description
netdev/cover_letter success Link
netdev/fixes_present success Link
netdev/patch_count success Link
netdev/tree_selection success Guessed tree name to be net-next
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cc_maintainers success CCed 7 of 7 maintainers
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, 8 lines checked
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/header_inline success Link

Commit Message

Tom Rix May 30, 2021, 7:29 p.m. UTC
From: Tom Rix <trix@redhat.com>

Static analysis reports this issue
/motorcomm.c:83:2: warning: variable 'ge' is used uninitialized
  whenever switch default is taken [-Wsometimes-uninitialized]
        default: /* leave everything alone in other modes */
        ^~~~~~~
drivers/net/phy/motorcomm.c:87:85: note: uninitialized use
  occurs here
        ret = __phy_modify(phydev, YT8511_PAGE,
	  (YT8511_DELAY_RX | YT8511_DELAY_GE_TX_EN), ge);
                                                     ^~

__phy_modify() calls __mdiobus_modify_changed(.., mask, set)

	new = (ret & ~mask) | set;
	if (new == ret)
		return 0;

	ret = __mdiobus_write(bus, addr, regnum, new);

Since 'ge/set' is or-ed in, it is safe to initialize it to 0

Signed-off-by: Tom Rix <trix@redhat.com>
---
 drivers/net/phy/motorcomm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jakub Kicinski June 1, 2021, 5:22 a.m. UTC | #1
On Sun, 30 May 2021 12:29:43 -0700 trix@redhat.com wrote:
> From: Tom Rix <trix@redhat.com>
> 
> Static analysis reports this issue
> /motorcomm.c:83:2: warning: variable 'ge' is used uninitialized
>   whenever switch default is taken [-Wsometimes-uninitialized]
>         default: /* leave everything alone in other modes */
>         ^~~~~~~
> drivers/net/phy/motorcomm.c:87:85: note: uninitialized use
>   occurs here
>         ret = __phy_modify(phydev, YT8511_PAGE,
> 	  (YT8511_DELAY_RX | YT8511_DELAY_GE_TX_EN), ge);
>                                                      ^~
> 
> __phy_modify() calls __mdiobus_modify_changed(.., mask, set)
> 
> 	new = (ret & ~mask) | set;
> 	if (new == ret)
> 		return 0;
> 
> 	ret = __mdiobus_write(bus, addr, regnum, new);
> 
> Since 'ge/set' is or-ed in, it is safe to initialize it to 0
> 
> Signed-off-by: Tom Rix <trix@redhat.com>
> ---
>  drivers/net/phy/motorcomm.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/phy/motorcomm.c b/drivers/net/phy/motorcomm.c
> index 796b68f4b499..53b2906c54ef 100644
> --- a/drivers/net/phy/motorcomm.c
> +++ b/drivers/net/phy/motorcomm.c
> @@ -50,7 +50,7 @@ static int yt8511_write_page(struct phy_device *phydev, int page)
>  
>  static int yt8511_config_init(struct phy_device *phydev)
>  {
> -	unsigned int ge, fe;
> +	unsigned int ge = 0, fe = 0;
>  	int ret, oldpage;
>  
>  	/* set clock mode to 125mhz */

I believe this was fixed by just-applied commit 0cc8bddb5b06 ("net: phy:
abort loading yt8511 driver in unsupported modes").
diff mbox series

Patch

diff --git a/drivers/net/phy/motorcomm.c b/drivers/net/phy/motorcomm.c
index 796b68f4b499..53b2906c54ef 100644
--- a/drivers/net/phy/motorcomm.c
+++ b/drivers/net/phy/motorcomm.c
@@ -50,7 +50,7 @@  static int yt8511_write_page(struct phy_device *phydev, int page)
 
 static int yt8511_config_init(struct phy_device *phydev)
 {
-	unsigned int ge, fe;
+	unsigned int ge = 0, fe = 0;
 	int ret, oldpage;
 
 	/* set clock mode to 125mhz */