Jedec.c was missing error handling in a few cases

Fix. jedec.c error handling used double negation in too many places for
no good reason. Clean up.

Corresponding to flashrom svn r779.

Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@gmx.net>
Acked-by: Sean Nelson <audiohacked@gmail.com>
diff --git a/jedec.c b/jedec.c
index 69a59b3..f352c6b 100644
--- a/jedec.c
+++ b/jedec.c
@@ -262,7 +262,7 @@
 int write_page_write_jedec(struct flashchip *flash, uint8_t *src,
 			   int start, int page_size)
 {
-	int i, tried = 0, ok;
+	int i, tried = 0, failed;
 	uint8_t *s = src;
 	chipaddr bios = flash->virtual_memory;
 	chipaddr dst = bios + start;
@@ -287,27 +287,27 @@
 
 	dst = d;
 	src = s;
-	ok = !verify_range(flash, src, start, page_size, NULL);
+	failed = verify_range(flash, src, start, page_size, NULL);
 
-	if (!ok && tried++ < MAX_REFLASH_TRIES) {
+	if (failed && tried++ < MAX_REFLASH_TRIES) {
 		fprintf(stderr, "retrying.\n");
 		goto retry;
 	}
-	if (!ok) {
+	if (failed) {
 		fprintf(stderr, " page 0x%lx failed!\n",
 			(d - bios) / page_size);
 	}
-	return !ok;
+	return failed;
 }
 
 int write_byte_program_jedec(chipaddr bios, uint8_t *src,
 			     chipaddr dst)
 {
-	int tried = 0, ok = 1;
+	int tried = 0, failed = 0;
 
-	/* If the data is 0xFF, don't program it */
+	/* If the data is 0xFF, don't program it and don't complain. */
 	if (*src == 0xFF) {
-		return -1;
+		return 0;
 	}
 
 retry:
@@ -325,27 +325,32 @@
 	}
 
 	if (tried >= MAX_REFLASH_TRIES)
-		ok = 0;
+		failed = 1;
 
-	return !ok;
+	return failed;
 }
 
 int write_sector_jedec(chipaddr bios, uint8_t *src,
 		       chipaddr dst, unsigned int page_size)
 {
-	int i;
+	int i, failed = 0;
+	chipaddr olddst;
 
+	olddst = dst;
 	for (i = 0; i < page_size; i++) {
-		write_byte_program_jedec(bios, src, dst);
+		if (write_byte_program_jedec(bios, src, dst))
+			failed = 1;
 		dst++, src++;
 	}
+	if (failed)
+		fprintf(stderr, " writing sector at 0x%lx failed!\n", olddst);
 
-	return 0;
+	return failed;
 }
 
 int write_jedec(struct flashchip *flash, uint8_t *buf)
 {
-	int i;
+	int i, failed = 0;
 	int total_size = flash->total_size * 1024;
 	int page_size = flash->page_size;
 	chipaddr bios = flash->virtual_memory;
@@ -358,12 +363,13 @@
 	printf("Programming page: ");
 	for (i = 0; i < total_size / page_size; i++) {
 		printf("%04d at address: 0x%08x", i, i * page_size);
-		write_page_write_jedec(flash, buf + i * page_size,
-				       i * page_size, page_size);
+		if (write_page_write_jedec(flash, buf + i * page_size,
+					   i * page_size, page_size))
+			failed = 1;
 		printf("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b");
 	}
 	printf("\n");
 	protect_jedec(bios);
 
-	return 0;
+	return failed;
 }