Commit 7a9b5612 authored by Mauro Carvalho Chehab's avatar Mauro Carvalho Chehab

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: default avatarMauro Carvalho Chehab <mchehab+huawei@kernel.org>
parent ddc11db2
...@@ -222,23 +222,24 @@ static int qt1010_init_meas1(struct qt1010_priv *priv, ...@@ -222,23 +222,24 @@ static int qt1010_init_meas1(struct qt1010_priv *priv,
{ QT1010_WR, reg, reg_init_val }, { QT1010_WR, reg, reg_init_val },
{ QT1010_WR, 0x1e, 0x00 }, { QT1010_WR, 0x1e, 0x00 },
{ QT1010_WR, 0x1e, oper }, { QT1010_WR, 0x1e, oper },
{ QT1010_RD, reg, 0xff }
}; };
for (i = 0; i < ARRAY_SIZE(i2c_data); i++) { for (i = 0; i < ARRAY_SIZE(i2c_data); i++) {
if (i2c_data[i].oper == QT1010_WR) { err = qt1010_writereg(priv, i2c_data[i].reg,
err = qt1010_writereg(priv, i2c_data[i].reg, i2c_data[i].val);
i2c_data[i].val); if (err)
} else { return err;
err = qt1010_readreg(priv, i2c_data[i].reg, &val2);
}
if (err) return err;
} }
err = qt1010_readreg(priv, reg, &val2);
if (err)
return err;
do { do {
val1 = val2; val1 = val2;
err = qt1010_readreg(priv, reg, &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", dev_dbg(&priv->i2c->dev, "%s: compare reg:%02x %02x %02x\n",
__func__, reg, val1, val2); __func__, reg, val1, val2);
} while (val1 != val2); } while (val1 != val2);
...@@ -250,7 +251,7 @@ static int qt1010_init_meas1(struct qt1010_priv *priv, ...@@ -250,7 +251,7 @@ static int qt1010_init_meas1(struct qt1010_priv *priv,
static int qt1010_init_meas2(struct qt1010_priv *priv, static int qt1010_init_meas2(struct qt1010_priv *priv,
u8 reg_init_val, u8 *retval) u8 reg_init_val, u8 *retval)
{ {
u8 i, val; u8 i, val = 0xff;
int err; int err;
qt1010_i2c_oper_t i2c_data[] = { qt1010_i2c_oper_t i2c_data[] = {
{ QT1010_WR, 0x07, reg_init_val }, { QT1010_WR, 0x07, reg_init_val },
...@@ -261,6 +262,7 @@ static int qt1010_init_meas2(struct qt1010_priv *priv, ...@@ -261,6 +262,7 @@ static int qt1010_init_meas2(struct qt1010_priv *priv,
{ QT1010_WR, 0x1e, 0x00 }, { QT1010_WR, 0x1e, 0x00 },
{ QT1010_WR, 0x22, 0xff } { QT1010_WR, 0x22, 0xff }
}; };
for (i = 0; i < ARRAY_SIZE(i2c_data); i++) { for (i = 0; i < ARRAY_SIZE(i2c_data); i++) {
if (i2c_data[i].oper == QT1010_WR) { if (i2c_data[i].oper == QT1010_WR) {
err = qt1010_writereg(priv, i2c_data[i].reg, err = qt1010_writereg(priv, i2c_data[i].reg,
...@@ -268,7 +270,8 @@ static int qt1010_init_meas2(struct qt1010_priv *priv, ...@@ -268,7 +270,8 @@ static int qt1010_init_meas2(struct qt1010_priv *priv,
} else { } else {
err = qt1010_readreg(priv, i2c_data[i].reg, &val); err = qt1010_readreg(priv, i2c_data[i].reg, &val);
} }
if (err) return err; if (err)
return err;
} }
*retval = val; *retval = val;
return 0; return 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment