Skip to content

Commit 5425711

Browse files
Colin Ian Kingdavem330
Colin Ian King
authored andcommitted
net: dsa: sja1105: fix check on while loop exit
The while-loop exit condition check is not correct; the loop should continue if the returns from the function calls are negative or the CRC status returns are invalid. Currently it is ignoring the returns from the function calls. Fix this by removing the status return checks and only break from the loop at the very end when we know that all the success condtions have been met. Kudos to Dan Carpenter for describing the correct fix and Vladimir Oltean for noting the change to the check on the number of retries. Addresses-Coverity: ("Uninitialized scalar variable") Fixes: 8aa9ebc ("net: dsa: Introduce driver for NXP SJA1105 5-port L2 switch") Signed-off-by: Colin Ian King <[email protected]> Tested-by: Vladimir Oltean <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 86dc59e commit 5425711

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

drivers/net/dsa/sja1105/sja1105_spi.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,14 +466,15 @@ int sja1105_static_config_upload(struct sja1105_private *priv)
466466
"invalid, retrying...\n");
467467
continue;
468468
}
469-
} while (--retries && (status.crcchkl == 1 || status.crcchkg == 1 ||
470-
status.configs == 0 || status.ids == 1));
469+
/* Success! */
470+
break;
471+
} while (--retries);
471472

472473
if (!retries) {
473474
rc = -EIO;
474475
dev_err(dev, "Failed to upload config to device, giving up\n");
475476
goto out;
476-
} else if (retries != RETRIES - 1) {
477+
} else if (retries != RETRIES) {
477478
dev_info(dev, "Succeeded after %d tried\n", RETRIES - retries);
478479
}
479480

0 commit comments

Comments
 (0)