From c36eb1d0a88310f38d48716e4c81cc22c8b71be3 Mon Sep 17 00:00:00 2001 From: Rod Whitby Date: Sun, 6 Nov 2022 17:14:50 +1030 Subject: [PATCH] spiFlash: Fix return value checking polarity and error reporting in protect_flash() and unprotect_flash() The return value fro flash.enable_protection is an integer, where 0 means success. So it must be compared to 0 to result in a true value for ret. If flash.disable_protect() returns non-zero, then ret will be false, so there's no point in doing a std::to_string on ret. You would need an integer intermediate value if you wanted to print the error value. --- src/spiInterface.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/spiInterface.cpp b/src/spiInterface.cpp index 5a366bb..7abe1b8 100644 --- a/src/spiInterface.cpp +++ b/src/spiInterface.cpp @@ -39,8 +39,8 @@ bool SPIInterface::protect_flash(uint32_t len) SPIFlash flash(this, false, _spif_verbose); /* configure flash protection */ - ret = flash.enable_protection(len) != 0; - if (ret != 0) + ret = (flash.enable_protection(len) == 0); + if (!ret) printError("Fail"); else printSuccess("Done"); @@ -72,7 +72,7 @@ bool SPIInterface::unprotect_flash() printInfo("unprotect_flash: ", false); ret = (flash.disable_protection() == 0); if (!ret) - printError("Fail " + std::to_string(ret)); + printError("Fail"); else printSuccess("Done"); } catch (std::exception &e) {