diff mbox series

[v2,04/16] tools: Avoid showing return value of clock_gettime()

Message ID 20210514014011.2832707-3-sjg@chromium.org
State Accepted
Commit 7f0f4e1825d1cbc64f6f8cba17f6deb7282acb2b
Delegated to: Tom Rini
Headers show
Series [v2,01/16] sandbox: net: Ensure host name is always a valid string | expand

Commit Message

Simon Glass May 14, 2021, 1:39 a.m. UTC
This value is either 0 for success or -1 for error. Coverity reports that
"ret" is passed to a parameter that cannot be negative, pointing to the
condition 'if (ret < 0)'.

Adjust it to just check for non-zero and avoid showing -1 in the error
message, which is pointless. Perhaps these changes will molify Coverity.

Reported-by: Coverity (CID: 312956)
Signed-off-by: Simon Glass <sjg@chromium.org>
---

(no changes since v1)

 tools/image-host.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Comments

Tom Rini July 16, 2021, 3:51 p.m. UTC | #1
On Thu, May 13, 2021 at 07:39:20PM -0600, Simon Glass wrote:

> This value is either 0 for success or -1 for error. Coverity reports that
> "ret" is passed to a parameter that cannot be negative, pointing to the
> condition 'if (ret < 0)'.
> 
> Adjust it to just check for non-zero and avoid showing -1 in the error
> message, which is pointless. Perhaps these changes will molify Coverity.
> 
> Reported-by: Coverity (CID: 312956)
> Signed-off-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/tools/image-host.c b/tools/image-host.c
index 270d36fe451..be7066d9433 100644
--- a/tools/image-host.c
+++ b/tools/image-host.c
@@ -327,7 +327,7 @@  static int get_random_data(void *data, int size)
 {
 	unsigned char *tmp = data;
 	struct timespec date;
-	int i, ret = 0;
+	int i, ret;
 
 	if (!tmp) {
 		printf("%s: pointer data is NULL\n", __func__);
@@ -336,9 +336,9 @@  static int get_random_data(void *data, int size)
 	}
 
 	ret = clock_gettime(CLOCK_MONOTONIC, &date);
-	if (ret < 0) {
-		printf("%s: clock_gettime has failed (err=%d, str=%s)\n",
-		       __func__, ret, strerror(errno));
+	if (ret) {
+		printf("%s: clock_gettime has failed (%s)\n", __func__,
+		       strerror(errno));
 		goto out;
 	}