Re: [PATCH] misc: rtsx: Set setting_reg2 before use.

From: Nathan Chancellor
Date: Thu May 19 2022 - 16:58:05 EST


On Tue, May 17, 2022 at 08:10:17AM +0000, Ricky WU wrote:
> > -----Original Message-----
> > From: Kai-Heng Feng <kai.heng.feng@xxxxxxxxxxxxx>
> > Sent: Tuesday, May 17, 2022 9:53 AM
> > To: Tom Rix <trix@xxxxxxxxxx>
> > Cc: Nathan Chancellor <nathan@xxxxxxxxxx>; arnd@xxxxxxxx;
> > gregkh@xxxxxxxxxxxxxxxxxxx; ndesaulniers@xxxxxxxxxx; Ricky WU
> > <ricky_wu@xxxxxxxxxxx>; linux-kernel@xxxxxxxxxxxxxxx; llvm@xxxxxxxxxxxxxxx
> > Subject: Re: [PATCH] misc: rtsx: Set setting_reg2 before use.
> >
> > On Tue, May 17, 2022 at 1:06 AM Tom Rix <trix@xxxxxxxxxx> wrote:
> > >
> > >
> > > On 5/16/22 8:56 AM, Nathan Chancellor wrote:
> > > > On Mon, May 16, 2022 at 09:00:47AM -0400, Tom Rix wrote:
> > > >> The clang build fails with
> > > >> rts5261.c:406:13: error: variable 'setting_reg2' is used uninitialized
> > whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
> > > >> } else if (efuse_valid == 0) {
> > > >> ^~~~~~~~~~~~~~~~
> > > >>
> > > >> setting_reg2 is set in this block
> > > >> if (efuse_valid == 2 || efuse_valid == 3) { ..
> > > >> } else if (efuse_valid == 0) {
> > > >> // default
> > > >> ..
> > > >> }
> > > >> But efuse_valid can also have a value of 1.
> > > >> Change the 'else if' to 'else' to make the second block the default.
> > > >>
> > > >> Fixes: b1c5f3085149 ("misc: rtsx: add rts5261 efuse function")
> > > >> Signed-off-by: Tom Rix <trix@xxxxxxxxxx>
> > > > I am not sure if this fix is correct from a functional standpoint (i.e.
> > > > is treating efuse_valid == 1 the same as efuse_valid == 0 correct?)
> > > > but it is better than not handling this value altogether. For what
> > > > it's
> > > > worth:
> > >
> > > I looked at how the code used to work, this seemed better than
> > > initializing to NULL.
> >
> > Or maybe use a single if block?
> >
> > u16 setting_reg1 =PCR_SETTING_REG1 , setting_reg2 =
> > PCR_SETTING_REG2; ...
> > if ((efuse_valid == 2 || efuse_valid == 3) && (valid != 3) {
> > setting_reg1 = PCR_SETTING_REG4;
> > setting_reg2 = PCR_SETTING_REG5;
> > }
> >
> > Kai-Heng
> >
> > >
> > > >
> > > > Reviewed-by: Nathan Chancellor <nathan@xxxxxxxxxx>
> > > >
> > > > As a side note, it is unfortunate that this change made it into
> > > > -next when there was an outstanding report about this warning:
> > >
> > > From the clang side, this is a build break and my static analysis
> > > infra goes down.
> > >
> > > These build breaks seem to happening every week, is there a precommit
> > > clang gating test that could be done for -next ?
> > >
> > > Tom
> > >
> > > >
> > > > https://lore.kernel.org/202205100220.WyAyhKap-lkp@xxxxxxxxx/
> > > >
> > > >> ---
> > > >> drivers/misc/cardreader/rts5261.c | 2 +-
> > > >> 1 file changed, 1 insertion(+), 1 deletion(-)
> > > >>
> > > >> diff --git a/drivers/misc/cardreader/rts5261.c
> > > >> b/drivers/misc/cardreader/rts5261.c
> > > >> index 749cc5a46d13..f22634b14dc8 100644
> > > >> --- a/drivers/misc/cardreader/rts5261.c
> > > >> +++ b/drivers/misc/cardreader/rts5261.c
> > > >> @@ -403,7 +403,7 @@ static void rts5261_init_from_hw(struct rtsx_pcr
> > *pcr)
> > > >> setting_reg1 = PCR_SETTING_REG4;
> > > >> setting_reg2 = PCR_SETTING_REG5;
> > > >> }
> > > >> - } else if (efuse_valid == 0) {
> > > >> + } else {
> > > >> // default
> > > >> setting_reg1 = PCR_SETTING_REG1;
> > > >> setting_reg2 = PCR_SETTING_REG2;
>
> Sorry for the trouble
> here can be changed to
> ...
> } else if (efuse_valid == 0) {
> // default
> setting_reg1 = PCR_SETTING_REG1;
> setting_reg2 = PCR_SETTING_REG2;
> } else {
> return;
> }
> Because other values are invalid

Tom, were you going to send a v2 of this?

Cheers,
Nathan