diff options
author | Mauro Carvalho Chehab <mchehab+huawei@kernel.org> | 2020-09-01 11:05:19 +0200 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab+huawei@kernel.org> | 2020-09-03 11:07:57 +0200 |
commit | 7a9b56123a036483d3b26bbd37d0dab4ca4c9eae (patch) | |
tree | 0a45566554b6bf9715b48325e0ec67a16384f103 /drivers/media/tuners | |
parent | ddc11db26ccbd40ccb42449b747c86c12f2ec636 (diff) | |
download | linux-7a9b56123a036483d3b26bbd37d0dab4ca4c9eae.tar.bz2 |
media: qt1010: fix usage of unititialized value
As pointed by smatch:
drivers/media/tuners/qt1010.c:239 qt1010_init_meas1() error: uninitialized symbol 'val2'.
drivers/media/tuners/qt1010.c:273 qt1010_init_meas2() error: uninitialized symbol 'val'.
The logic is ok, but it is hard for static analyzers
to parse it, as it depends on a value read in the middle
of a loop.
Also, it takes a while for humans to verify.
Re-write the first function to use a more direct way.
At the second one, I opted to just initialize the read var,
in order to shut up the report.
While here, address a few coding style issues at the
function code.
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Diffstat (limited to 'drivers/media/tuners')
-rw-r--r-- | drivers/media/tuners/qt1010.c | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/drivers/media/tuners/qt1010.c b/drivers/media/tuners/qt1010.c index e48faf942830..3853a3d43d4f 100644 --- a/drivers/media/tuners/qt1010.c +++ b/drivers/media/tuners/qt1010.c @@ -222,23 +222,24 @@ static int qt1010_init_meas1(struct qt1010_priv *priv, { QT1010_WR, reg, reg_init_val }, { QT1010_WR, 0x1e, 0x00 }, { QT1010_WR, 0x1e, oper }, - { QT1010_RD, reg, 0xff } }; for (i = 0; i < ARRAY_SIZE(i2c_data); i++) { - if (i2c_data[i].oper == QT1010_WR) { - err = qt1010_writereg(priv, i2c_data[i].reg, - i2c_data[i].val); - } else { - err = qt1010_readreg(priv, i2c_data[i].reg, &val2); - } - if (err) return err; + err = qt1010_writereg(priv, i2c_data[i].reg, + i2c_data[i].val); + if (err) + return err; } + err = qt1010_readreg(priv, reg, &val2); + if (err) + return err; do { val1 = val2; err = qt1010_readreg(priv, reg, &val2); - if (err) return err; + if (err) + return err; + dev_dbg(&priv->i2c->dev, "%s: compare reg:%02x %02x %02x\n", __func__, reg, val1, val2); } while (val1 != val2); @@ -250,7 +251,7 @@ static int qt1010_init_meas1(struct qt1010_priv *priv, static int qt1010_init_meas2(struct qt1010_priv *priv, u8 reg_init_val, u8 *retval) { - u8 i, val; + u8 i, val = 0xff; int err; qt1010_i2c_oper_t i2c_data[] = { { QT1010_WR, 0x07, reg_init_val }, @@ -261,6 +262,7 @@ static int qt1010_init_meas2(struct qt1010_priv *priv, { QT1010_WR, 0x1e, 0x00 }, { QT1010_WR, 0x22, 0xff } }; + for (i = 0; i < ARRAY_SIZE(i2c_data); i++) { if (i2c_data[i].oper == QT1010_WR) { err = qt1010_writereg(priv, i2c_data[i].reg, @@ -268,7 +270,8 @@ static int qt1010_init_meas2(struct qt1010_priv *priv, } else { err = qt1010_readreg(priv, i2c_data[i].reg, &val); } - if (err) return err; + if (err) + return err; } *retval = val; return 0; |