Commit fda1cb2e authored by Colin Ian King's avatar Colin Ian King Committed by Kleber Sacilotto de Souza

media: smiapp: fix timeout checking in smiapp_read_nvm

BugLink: https://bugs.launchpad.net/bugs/1791953

[ Upstream commit 7a2148df ]

The current code decrements the timeout counter i and the end of
each loop i is incremented, so the check for timeout will always
be false and hence the timeout mechanism is just a dead code path.
Potentially, if the RD_READY bit is not set, we could end up in
an infinite loop.

Fix this so the timeout starts from 1000 and decrements to zero,
if at the end of the loop i is zero we have a timeout condition.

Detected by CoverityScan, CID#1324008 ("Logically dead code")

Fixes: ccfc97bd ("[media] smiapp: Add driver")
Signed-off-by: default avatarColin Ian King <colin.king@canonical.com>
Signed-off-by: default avatarSakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+samsung@kernel.org>
Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarStefan Bader <stefan.bader@canonical.com>
Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
parent 4f5b7f90
...@@ -981,7 +981,7 @@ static int smiapp_read_nvm(struct smiapp_sensor *sensor, ...@@ -981,7 +981,7 @@ static int smiapp_read_nvm(struct smiapp_sensor *sensor,
if (rval) if (rval)
goto out; goto out;
for (i = 0; i < 1000; i++) { for (i = 1000; i > 0; i--) {
rval = smiapp_read( rval = smiapp_read(
sensor, sensor,
SMIAPP_REG_U8_DATA_TRANSFER_IF_1_STATUS, &s); SMIAPP_REG_U8_DATA_TRANSFER_IF_1_STATUS, &s);
...@@ -992,13 +992,12 @@ static int smiapp_read_nvm(struct smiapp_sensor *sensor, ...@@ -992,13 +992,12 @@ static int smiapp_read_nvm(struct smiapp_sensor *sensor,
if (s & SMIAPP_DATA_TRANSFER_IF_1_STATUS_RD_READY) if (s & SMIAPP_DATA_TRANSFER_IF_1_STATUS_RD_READY)
break; break;
if (--i == 0) { }
if (!i) {
rval = -ETIMEDOUT; rval = -ETIMEDOUT;
goto out; goto out;
} }
}
for (i = 0; i < SMIAPP_NVM_PAGE_SIZE; i++) { for (i = 0; i < SMIAPP_NVM_PAGE_SIZE; i++) {
rval = smiapp_read( rval = smiapp_read(
sensor, sensor,
......
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