From patchwork Fri Nov 8 08:35:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Alexey Kardashevskiy X-Patchwork-Id: 1191721 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 478Ydn6Kvpz9sP3 for ; Fri, 8 Nov 2019 19:41:17 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.ru Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 478Ydn548FzF6pc for ; Fri, 8 Nov 2019 19:41:17 +1100 (AEDT) X-Original-To: slof@lists.ozlabs.org Delivered-To: slof@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.ru (client-ip=107.174.27.60; helo=ozlabs.ru; envelope-from=aik@ozlabs.ru; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=ozlabs.ru Received: from ozlabs.ru (unknown [107.174.27.60]) by lists.ozlabs.org (Postfix) with ESMTP id 478Ydk0L3czF6pT for ; Fri, 8 Nov 2019 19:41:13 +1100 (AEDT) Received: from fstn1-p1.ozlabs.ibm.com (localhost [IPv6:::1]) by ozlabs.ru (Postfix) with ESMTP id 195E4AE807E2; Fri, 8 Nov 2019 03:34:37 -0500 (EST) From: Alexey Kardashevskiy To: slof@lists.ozlabs.org Date: Fri, 8 Nov 2019 19:35:28 +1100 Message-Id: <20191108083528.103409-1-aik@ozlabs.ru> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 Subject: [SLOF] [PATCH slof] sloffs: Fix -Wunused-result gcc warnings in read/write X-BeenThere: slof@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Patches for https://github.com/aik/SLOF" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "SLOF" This fixes these: sloffs.c:466:2: warning: ignoring return value of ‘read’, declared with attribute warn_unused_result [-Wunused-result] read(fd, data, header_len); ^~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Alexey Kardashevskiy --- tools/sloffs.c | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/tools/sloffs.c b/tools/sloffs.c index 9a1eace8d619..9d0a70a796b9 100644 --- a/tools/sloffs.c +++ b/tools/sloffs.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -176,6 +177,7 @@ sloffs_header(const int fd) struct sloffs file; struct sloffs *sloffs; struct stH *header; + size_t rc; header = (struct stH *)malloc(sizeof(struct stH)); @@ -187,8 +189,14 @@ sloffs_header(const int fd) return NULL; } - read(fd, header, sizeof(struct stH)); + rc = read(fd, header, sizeof(struct stH)); + if (rc != sizeof(struct stH)) { + printf("Reading header, rc %ld, errno %d\n", rc, errno); + free(header); + return NULL; + } free(sloffs->name); + return header; } @@ -298,6 +306,7 @@ sloffs_append(const int file, const char *name, const char *dest) struct sloffs new_file; uint64_t read_len; int i; + size_t rc; fd = open(name, O_RDONLY); @@ -328,7 +337,11 @@ sloffs_append(const int file, const char *name, const char *dest) /* write byte at the end to be able to mmap it */ lseek(out, new_len - 1, SEEK_SET); - write(out, "", 1); + rc = write(out, "", 1); + if (rc != 1) { + printf("Extending file failed, rc %ld, errno %d\n", rc, errno); + exit(1); + } write_start = mmap(NULL, new_len, PROT_READ | PROT_WRITE, MAP_SHARED, out, 0); @@ -427,6 +440,7 @@ sloffs_dump(const int fd) int i; uint64_t crc; uint64_t header_len; + size_t rc; header = sloffs_header(fd); @@ -463,7 +477,11 @@ sloffs_dump(const int fd) /* no copy the header to memory to crc test it */ data = malloc(header_len); lseek(fd, 0, SEEK_SET); - read(fd, data, header_len); + rc = read(fd, data, header_len); + if (rc != header_len) { + printf("Reading header failed, rc %ld, errno %d\n", rc, errno); + return; + } crc = calCRCword((unsigned char *)data, header_length(fd), 0); free(data); if (!crc) @@ -476,7 +494,11 @@ sloffs_dump(const int fd) /* move to the CRC */ lseek(fd, crc - 8, SEEK_SET); /* read it */ - read(fd, &crc, 8); + rc = read(fd, &crc, 8); + if (rc != 8) { + printf("Reading crc failed, rc %ld, errno %d\n", rc, errno); + return; + } crc = be64_to_cpu(crc); printf(" Image CRC : 0x%016lx CRC check: ", crc); crc = check_image_crc(fd, be64_to_cpu(header->flashlen)); @@ -581,6 +603,7 @@ sloffs_copy(const int file, const char *name) unsigned char *write_buf; int i; struct stH *header; + size_t rc; header = sloffs_header(file); @@ -598,7 +621,11 @@ sloffs_copy(const int file, const char *name) } /* write byte at the end to be able to mmap it */ lseek(out, len - 1, SEEK_SET); - write(out, "", 1); + rc = write(out, "", 1); + if (rc != 1) { + printf("Extending file failed, rc %ld, errno %d\n", rc, errno); + exit(1); + } write_buf = mmap(NULL, len, PROT_WRITE, MAP_SHARED, out, 0); if (write_buf == MAP_FAILED) {