Skip to contentSkip to conversation

scsi: ufs-mediatek: Avoid using ret uninitialized in ufs_mtk_setup_clocks

PATCH Applied Nathan Chancellor 4 participants 4 messages Mar 20, 2019 – Mar 21, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scsi: ufs-mediatek: Avoid using ret uninitialized in ufs_mtk_setup_clocks

When building with -Wsometimes-uninitialized, Clang warns:

drivers/scsi/ufs/ufs-mediatek.c:112:7: warning: variable 'ret' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]

                if (on)
                    ^~
drivers/scsi/ufs/ufs-mediatek.c:120:9: note: uninitialized use occurs
here
        return ret;
               ^~~
drivers/scsi/ufs/ufs-mediatek.c:112:3: note: remove the 'if' if its
condition is always true
                if (on)
                ^~~~~~~
drivers/scsi/ufs/ufs-mediatek.c:108:7: warning: variable 'ret' is used
uninitialized whenever 'if' condition is false
[-Wsometimes-uninitialized]
                if (!on)
                    ^~~
drivers/scsi/ufs/ufs-mediatek.c:120:9: note: uninitialized use occurs
here
        return ret;
               ^~~
drivers/scsi/ufs/ufs-mediatek.c:108:3: note: remove the 'if' if its
condition is always true
                if (!on)
                ^~~~~~~~
drivers/scsi/ufs/ufs-mediatek.c:96:9: note: initialize the variable
'ret' to silence this warning
        int ret;
               ^
                = 0

2 warnings generated.

Remove the default case and initialize ret to -EINVAL to properly fix this warning.

Fixes ddd90623ce26 ("scsi: ufs-mediatek: Add UFS support for Mediatek SoC chips")
---
 drivers/scsi/ufs/ufs-mediatek.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/scsi/ufs/ufs-mediatek.c +1 -4
index c3b78fc83d3f..34aecad04468 100644
@@ -93,7 +93,7 @@ static int ufs_mtk_setup_clocks(struct ufs_hba *hba, bool on,
 				enum ufs_notify_change_status status)
 {
 	struct ufs_mtk_host *host = ufshcd_get_variant(hba);
-	int ret;
+	int ret = -EINVAL;
 
 	/*
 	 * In case ufs_mtk_init() is not yet done, simply ignore.
@@ -112,9 +112,6 @@ static int ufs_mtk_setup_clocks(struct ufs_hba *hba, bool on,
 		if (on)
 			ret = phy_power_on(host->mphy);
 		break;
-	default:
-		ret = -EINVAL;
-		break;
 	}
 
 	return ret;
Signature · 1 line
2.21.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 70 lines · Nathan Chancellor

When building with -Wsometimes-uninitialized, Clang warns:

drivers/scsi/ufs/ufs-mediatek.c:112:7: warning: variable 'ret' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]

                if (on)
                    ^~
drivers/scsi/ufs/ufs-mediatek.c:120:9: note: uninitialized use occurs
here
        return ret;
               ^~~
drivers/scsi/ufs/ufs-mediatek.c:112:3: note: remove the 'if' if its
condition is always true
                if (on)
                ^~~~~~~
drivers/scsi/ufs/ufs-mediatek.c:108:7: warning: variable 'ret' is used
uninitialized whenever 'if' condition is false
[-Wsometimes-uninitialized]
                if (!on)
                    ^~~
drivers/scsi/ufs/ufs-mediatek.c:120:9: note: uninitialized use occurs
here
        return ret;
               ^~~
drivers/scsi/ufs/ufs-mediatek.c:108:3: note: remove the 'if' if its
condition is always true
                if (!on)
                ^~~~~~~~
drivers/scsi/ufs/ufs-mediatek.c:96:9: note: initialize the variable
'ret' to silence this warning
        int ret;
               ^
                = 0

2 warnings generated.

Remove the default case and initialize ret to -EINVAL to properly fix this warning.

Fixes ddd90623ce26 ("scsi: ufs-mediatek: Add UFS support for Mediatek SoC chips")
---
 drivers/scsi/ufs/ufs-mediatek.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/scsi/ufs/ufs-mediatek.c +1 -5
index c3b78fc83d3f..34aecad04468 100644
@@ -93,7 +93,7 @@ static int ufs_mtk_setup_clocks(struct ufs_hba *hba, bool on,
                                enum ufs_notify_change_status status)
 {
        struct ufs_mtk_host *host = ufshcd_get_variant(hba);
-       int ret;
+       int ret = -EINVAL;
 
        /*
         * In case ufs_mtk_init() is not yet done, simply ignore.
@@ -112,9 +112,6 @@ static int ufs_mtk_setup_clocks(struct ufs_hba *hba, bool on,
                if (on)
                        ret = phy_power_on(host->mphy);
                break;
-       default:
-               ret = -EINVAL;
-               break;
        }
 
        return ret;
--
Quoted 2 lines

2.21.0

The enum being switched on (enum ufs_notify_change_status) only has 2 values; so the default case is impossible. A switch is probably overkill, but this change is fine as is. Thanks for sending it.

Signature · 2 lines
Thanks,
~Nick Desaulniers
Reviewed-by
#2 lore raw

Hi,

Quoted 78 lines · Nick Desaulniers
Quoted 70 lines · Nathan Chancellor

When building with -Wsometimes-uninitialized, Clang warns:

drivers/scsi/ufs/ufs-mediatek.c:112:7: warning: variable 'ret' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]

                if (on)
                    ^~
drivers/scsi/ufs/ufs-mediatek.c:120:9: note: uninitialized use occurs
here
        return ret;
               ^~~
drivers/scsi/ufs/ufs-mediatek.c:112:3: note: remove the 'if' if its
condition is always true
                if (on)
                ^~~~~~~
drivers/scsi/ufs/ufs-mediatek.c:108:7: warning: variable 'ret' is used
uninitialized whenever 'if' condition is false
[-Wsometimes-uninitialized]
                if (!on)
                    ^~~
drivers/scsi/ufs/ufs-mediatek.c:120:9: note: uninitialized use occurs
here
        return ret;
               ^~~
drivers/scsi/ufs/ufs-mediatek.c:108:3: note: remove the 'if' if its
condition is always true
                if (!on)
                ^~~~~~~~
drivers/scsi/ufs/ufs-mediatek.c:96:9: note: initialize the variable
'ret' to silence this warning
        int ret;
               ^
                = 0

2 warnings generated.

Remove the default case and initialize ret to -EINVAL to properly fix this warning.

Fixes ddd90623ce26 ("scsi: ufs-mediatek: Add UFS support for Mediatek SoC chips")
---
 drivers/scsi/ufs/ufs-mediatek.c | 5 +----
 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/scsi/ufs/ufs-mediatek.c +1 -5
index c3b78fc83d3f..34aecad04468 100644
@@ -93,7 +93,7 @@ static int ufs_mtk_setup_clocks(struct ufs_hba *hba, bool on,
                                enum ufs_notify_change_status status)
 {
        struct ufs_mtk_host *host = ufshcd_get_variant(hba);
-       int ret;
+       int ret = -EINVAL;
 
        /*
         * In case ufs_mtk_init() is not yet done, simply ignore.
@@ -112,9 +112,6 @@ static int ufs_mtk_setup_clocks(struct ufs_hba *hba, bool on,
                if (on)
                        ret = phy_power_on(host->mphy);
                break;
-       default:
-               ret = -EINVAL;
-               break;
        }
 
        return ret;
--
Quoted 2 lines

2.21.0

The enum being switched on (enum ufs_notify_change_status) only has 2 values; so the default case is impossible. A switch is probably overkill, but this change is fine as is. Thanks for sending it.

Quoted 1 line

Currently the caller is always using "on" with "POST_CHANGE" and "!on" with "PRE_CHANGE", however the warnings shall be fixed. Thanks for fixing it.

#3 lore raw
In reply to Nathan Chancellor

Nathan,

Quoted 2 lines

Remove the default case and initialize ret to -EINVAL to properly fix this warning.

Applied to 5.2/scsi-queue, thanks!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering