soc: mediatek: pwrap: Zero initialize rdata in pwrap_init_cipher
PATCH 1/1 soc: mediatek: pwrap: Zero initialize rdata in pwrap_init_cipher
When building with -Wsometimes-uninitialized, Clang warns:
drivers/soc/mediatek/mtk-pmic-wrap.c:1358:6: error: variable 'rdata' is used uninitialized whenever '||' condition is true [-Werror,-Wsometimes-uninitialized]
If pwrap_write returns non-zero, pwrap_read will not be called to initialize rdata, meaning that we will use some random uninitialized stack value in our print statement. Zero initialize rdata in case this happens.
---
I don't know if this is better or to just restructure the if statement below (I'm not an expert in this code so I'll leave that up to the maintainers to decide).
drivers/soc/mediatek/mtk-pmic-wrap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/soc/mediatek/mtk-pmic-wrap.c +1 -1
@@ -1281,7 +1281,7 @@ static bool pwrap_is_pmic_cipher_ready(struct pmic_wrapper *wrp)static int pwrap_init_cipher (struct pmic_wrapper *wrp) {int ret; -u32 rdata; +u32 rdata =0 ;pwrap_writel (wrp,0x1 ,PWRAP_CIPHER_SWRST );pwrap_writel (wrp,0x0 ,PWRAP_CIPHER_SWRST );
Signature · 1 line
2.21.0
Quoted 12 lines · Nathan Chancellor
When building with -Wsometimes-uninitialized, Clang warns:
drivers/soc/mediatek/mtk-pmic-wrap.c:1358:6: error: variable 'rdata' is used uninitialized whenever '||' condition is true [-Werror,-Wsometimes-uninitialized]If
pwrap_writereturns non-zero,pwrap_readwill not be called to initialize rdata, meaning that we will use some random uninitialized stack value in our print statement. Zero initialize rdata in case this happens.
Quoted 7 lines
Signed-off-by Nathan Chancellor <[email protected]>---
I don't know if this is better or to just restructure the if statement below (I'm not an expert in this code so I'll leave that up to the maintainers to decide).
No, I the way you have it here is most correct. That condition writes a value somewhere, reads it back, then compares it. The write or read could fail. Better to just initialize rdata in case the write fails. Thanks for the patch.
Quoted 20 lines
drivers/soc/mediatek/mtk-pmic-wrap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/soc/mediatek/mtk-pmic-wrap.c +1
-2@@ -1281,7 +1281,7 @@ static bool pwrap_is_pmic_cipher_ready(struct pmic_wrapper *wrp)static int pwrap_init_cipher (struct pmic_wrapper *wrp) {int ret; -u32 rdata; +u32 rdata =0 ;pwrap_writel (wrp,0x1 ,PWRAP_CIPHER_SWRST );pwrap_writel (wrp,0x0 ,PWRAP_CIPHER_SWRST ); --2.21.0
Signature · 2 lines
Thanks, ~Nick Desaulniers
Arnd Bergmann
Reviewed-byQuoted 23 lines · Nick Desaulniers' via Clang Built Linux
Quoted 12 lines · Nathan Chancellor
When building with -Wsometimes-uninitialized, Clang warns:
drivers/soc/mediatek/mtk-pmic-wrap.c:1358:6: error: variable 'rdata' is used uninitialized whenever '||' condition is true [-Werror,-Wsometimes-uninitialized]If
pwrap_writereturns non-zero,pwrap_readwill not be called to initialize rdata, meaning that we will use some random uninitialized stack value in our print statement. Zero initialize rdata in case this happens.Quoted 7 lines
Signed-off-by Nathan Chancellor <[email protected]>---
I don't know if this is better or to just restructure the if statement below (I'm not an expert in this code so I'll leave that up to the maintainers to decide).
Quoted 5 lines
No, I the way you have it here is most correct. That condition writes a value somewhere, reads it back, then compares it. The write or read could fail. Better to just initialize rdata in case the write fails. Thanks for the patch.
Reviewed-by Nick Desaulniers <[email protected]>
I also came up with a similar patch here, but I move the initialization to just before the first use of the variable:
(quoted diff) +0 -0
b/drivers/soc/mediatek/mtk-pmic-wrap.c
index 8236a6c87e19..eb5035fd8ecd 100644
drivers/soc/mediatek/mtk-pmic-wrap.c +1 -0
@@ -1355,6 +1355,7 @@ static int pwrap_init_cipher(struct pmic_wrapper *wrp)pwrap_writel (wrp,1 ,PWRAP_CIPHER_MODE );/* Write Test */ + rdata =0 ;if (pwrap_write (wrp, wrp->slave->dew_regs[PWRAP_DEW_WRITE_TEST ],PWRAP_DEW_WRITE_TEST_VAL ) || pwrap_read(wrp, wrp->slave->dew_regs[PWRAP_DEW_WRITE_TEST],
Very little difference, so let's go with your patch
Quoted 38 lines · Nathan Chancellor
When building with -Wsometimes-uninitialized, Clang warns:
drivers/soc/mediatek/mtk-pmic-wrap.c:1358:6: error: variable 'rdata' is used uninitialized whenever '||' condition is true [-Werror,-Wsometimes-uninitialized]If
pwrap_writereturns non-zero,pwrap_readwill not be called to initialize rdata, meaning that we will use some random uninitialized stack value in our print statement. Zero initialize rdata in case this happens.Signed-off-by Nathan Chancellor <[email protected]>---
I don't know if this is better or to just restructure the if statement below (I'm not an expert in this code so I'll leave that up to the maintainers to decide).
drivers/soc/mediatek/mtk-pmic-wrap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/soc/mediatek/mtk-pmic-wrap.c +1
-1@@ -1281,7 +1281,7 @@ static bool pwrap_is_pmic_cipher_ready(struct pmic_wrapper *wrp)static int pwrap_init_cipher (struct pmic_wrapper *wrp) {int ret; -u32 rdata; +u32 rdata =0 ;pwrap_writel (wrp,0x1 ,PWRAP_CIPHER_SWRST );pwrap_writel (wrp,0x0 ,PWRAP_CIPHER_SWRST );Signature · 1 line
2.21.0
Gentle ping (if there was a response to this, I didn't receive it). I know I sent it in the middle of a merge window so I get if it slipped through the cracks.
Thanks,
Nathan
Matthias Brugger
maintainerQuoted 34 lines · Nathan Chancellor
Quoted 33 lines · Nathan Chancellor
When building with -Wsometimes-uninitialized, Clang warns:
drivers/soc/mediatek/mtk-pmic-wrap.c:1358:6: error: variable 'rdata' is used uninitialized whenever '||' condition is true [-Werror,-Wsometimes-uninitialized]If
pwrap_writereturns non-zero,pwrap_readwill not be called to initialize rdata, meaning that we will use some random uninitialized stack value in our print statement. Zero initialize rdata in case this happens.Signed-off-by Nathan Chancellor <[email protected]>---
I don't know if this is better or to just restructure the if statement below (I'm not an expert in this code so I'll leave that up to the maintainers to decide).
drivers/soc/mediatek/mtk-pmic-wrap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/soc/mediatek/mtk-pmic-wrap.c +1
-1@@ -1281,7 +1281,7 @@ static bool pwrap_is_pmic_cipher_ready(struct pmic_wrapper *wrp)static int pwrap_init_cipher (struct pmic_wrapper *wrp) {int ret; -u32 rdata; +u32 rdata =0 ;
Quoted 10 lines
Quoted 5 lines
drivers/soc/mediatek/mtk-pmic-wrap.c +0
-0pwrap_writel (wrp,0x1 ,PWRAP_CIPHER_SWRST );pwrap_writel (wrp,0x0 ,PWRAP_CIPHER_SWRST );Signature · 1 line
2.21.0Gentle ping (if there was a response to this, I didn't receive it). I know I sent it in the middle of a merge window so I get if it slipped through the cracks.
applied now to v5.1-next/soc
thanks