diff options
author | Boris Brezillon <boris.brezillon@free-electrons.com> | 2016-11-25 18:30:41 +0100 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2016-12-06 19:38:16 +0100 |
commit | bfb33f2f46a40023aa9820f4cdd99281e41250c1 (patch) | |
tree | 148d0f16e4936218b4d3f89a2ee45d8c12bcfb6b /nand-utils | |
parent | b2a9601cebb67db9e02ac7bbd927a21aa95f5ba3 (diff) |
common: Fix 'unchecked return code' warnings
Several tools are simply not checking return code of functions marked
with 'warn_unused_result'.
Provide wrappers for the read/write functions to avoid patching old
code and providing proper error handling.
Fix the remaining ones (calls to fgets() and system()).
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
Diffstat (limited to 'nand-utils')
-rw-r--r-- | nand-utils/nftl_format.c | 24 | ||||
-rw-r--r-- | nand-utils/nftldump.c | 10 |
2 files changed, 18 insertions, 16 deletions
diff --git a/nand-utils/nftl_format.c b/nand-utils/nftl_format.c index 8485553..a329c59 100644 --- a/nand-utils/nftl_format.c +++ b/nand-utils/nftl_format.c @@ -93,15 +93,15 @@ static unsigned char check_block_2(unsigned long block) erase.start = ofs; for (blockofs = 0; blockofs < meminfo.erasesize; blockofs += 512) { - pread(fd, readbuf, 512, ofs + blockofs); + pread_nocheck(fd, readbuf, 512, ofs + blockofs); if (memcmp(readbuf, writebuf[0], 512)) { /* Block wasn't 0xff after erase */ printf(": Block not 0xff after erase\n"); return ZONE_BAD_ORIGINAL; } - pwrite(fd, writebuf[1], 512, blockofs + ofs); - pread(fd, readbuf, 512, blockofs + ofs); + pwrite_nocheck(fd, writebuf[1], 512, blockofs + ofs); + pread_nocheck(fd, readbuf, 512, blockofs + ofs); if (memcmp(readbuf, writebuf[1], 512)) { printf(": Block not zero after clearing\n"); return ZONE_BAD_ORIGINAL; @@ -114,8 +114,8 @@ static unsigned char check_block_2(unsigned long block) return ZONE_BAD_ORIGINAL; } for (blockofs = 0; blockofs < meminfo.erasesize; blockofs += 512) { - pwrite(fd, writebuf[2], 512, blockofs + ofs); - pread(fd, readbuf, 512, blockofs + ofs); + pwrite_nocheck(fd, writebuf[2], 512, blockofs + ofs); + pread_nocheck(fd, readbuf, 512, blockofs + ofs); if (memcmp(readbuf, writebuf[2], 512)) { printf(": Block not 0x5a after writing\n"); return ZONE_BAD_ORIGINAL; @@ -127,8 +127,8 @@ static unsigned char check_block_2(unsigned long block) return ZONE_BAD_ORIGINAL; } for (blockofs = 0; blockofs < meminfo.erasesize; blockofs += 512) { - pwrite(fd, writebuf[3], 512, blockofs + ofs); - pread(fd, readbuf, 512, blockofs + ofs); + pwrite_nocheck(fd, writebuf[3], 512, blockofs + ofs); + pread_nocheck(fd, readbuf, 512, blockofs + ofs); if (memcmp(readbuf, writebuf[3], 512)) { printf(": Block not 0xa5 after writing\n"); return ZONE_BAD_ORIGINAL; @@ -181,7 +181,7 @@ static int checkbbt(void) unsigned char bits; int i, addr; - if (pread(fd, bbt, 512, 0x800) < 0) { + if (pread_nocheck(fd, bbt, 512, 0x800) < 0) { printf("%s: failed to read BBT, errno=%d\n", PROGRAM_NAME, errno); return (-1); } @@ -402,9 +402,9 @@ int main(int argc, char **argv) /* Phase 2. Writing NFTL Media Headers and Bad Unit Table */ printf("Phase 2.a Writing %s Media Header and Bad Unit Table\n", nftl); - pwrite(fd, writebuf[0], 512, MediaUnit1 * meminfo.erasesize + MediaUnitOff1); + pwrite_nocheck(fd, writebuf[0], 512, MediaUnit1 * meminfo.erasesize + MediaUnitOff1); for (ezone = 0; ezone < (meminfo.size / meminfo.erasesize); ezone += 512) { - pwrite(fd, BadUnitTable + ezone, 512, + pwrite_nocheck(fd, BadUnitTable + ezone, 512, (MediaUnit1 * meminfo.erasesize) + 512 * (1 + ezone / 512)); } @@ -416,9 +416,9 @@ int main(int argc, char **argv) le32_to_cpu(NFTLhdr->FormattedSize)/512); #endif printf("Phase 2.b Writing Spare %s Media Header and Spare Bad Unit Table\n", nftl); - pwrite(fd, writebuf[0], 512, MediaUnit2 * meminfo.erasesize + MediaUnitOff2); + pwrite_nocheck(fd, writebuf[0], 512, MediaUnit2 * meminfo.erasesize + MediaUnitOff2); for (ezone = 0; ezone < (meminfo.size / meminfo.erasesize); ezone += 512) { - pwrite(fd, BadUnitTable + ezone, 512, + pwrite_nocheck(fd, BadUnitTable + ezone, 512, (MediaUnit2 * meminfo.erasesize + MediaUnitOff2) + 512 * (1 + ezone / 512)); } diff --git a/nand-utils/nftldump.c b/nand-utils/nftldump.c index 32f4f2f..30332fe 100644 --- a/nand-utils/nftldump.c +++ b/nand-utils/nftldump.c @@ -39,6 +39,8 @@ #include <mtd/nftl-user.h> #include <mtd_swab.h> +#include "common.h" + static struct NFTLMediaHeader MedHead[2]; static mtd_info_t meminfo; @@ -73,7 +75,7 @@ static unsigned int find_media_headers(void) NumMedHeads = 0; while (ofs < meminfo.size) { - pread(fd, &MedHead[NumMedHeads], sizeof(struct NFTLMediaHeader), ofs); + pread_nocheck(fd, &MedHead[NumMedHeads], sizeof(struct NFTLMediaHeader), ofs); if (!strncmp(MedHead[NumMedHeads].DataOrgID, "ANAND", 6)) { SWAP16(MedHead[NumMedHeads].NumEraseUnits); SWAP16(MedHead[NumMedHeads].FirstPhysicalEUN); @@ -93,7 +95,7 @@ static unsigned int find_media_headers(void) /* read BadUnitTable, I don't know why pread() does not work for larger (7680 bytes) chunks */ for (i = 0; i < MAX_ERASE_ZONES; i += 512) - pread(fd, &BadUnitTable[i], 512, ofs + 512 + i); + pread_nocheck(fd, &BadUnitTable[i], 512, ofs + 512 + i); } else printf("Second NFTL Media Header found at offset 0x%08lx\n",ofs); NumMedHeads++; @@ -233,10 +235,10 @@ static void dump_virtual_units(void) if (lastgoodEUN == 0xffff) memset(readbuf, 0, 512); else - pread(fd, readbuf, 512, + pread_nocheck(fd, readbuf, 512, (lastgoodEUN * ERASESIZE) + (j * 512)); - write(ofd, readbuf, 512); + write_nocheck(ofd, readbuf, 512); } } |