diff mbox

[4/8] Enable -Werror for -Wformat

Message ID 1447735147-25957-4-git-send-email-stewart@linux.vnet.ibm.com
State Accepted
Headers show

Commit Message

Stewart Smith Nov. 17, 2015, 4:39 a.m. UTC
We create our own inttypes.h to get the correct printf formatting for
64bit numbers.

Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
---
 Makefile.main                         |  2 +-
 core/mem_region.c                     |  8 ++++---
 core/test/run-mem_range_is_reserved.c |  2 +-
 hdata/iohub.c                         | 21 +++++++++--------
 hdata/vpd.c                           |  3 ++-
 include/inttypes.h                    | 44 +++++++++++++++++++++++++++++++++++
 6 files changed, 64 insertions(+), 16 deletions(-)
 create mode 100644 include/inttypes.h
diff mbox

Patch

diff --git a/Makefile.main b/Makefile.main
index 78bab2d1caa9..dc36426f6dea 100644
--- a/Makefile.main
+++ b/Makefile.main
@@ -28,7 +28,7 @@  CWARNS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
 	  -Wwrite-strings -Wcast-align \
 	  -Winit-self \
 	  -Wframe-larger-than=1024 \
-	  -Werror -Wno-error=format
+	  -Werror
 
 # Host tools and options
 HOSTCC=gcc
diff --git a/core/mem_region.c b/core/mem_region.c
index f8d9a11aabb4..40b486b013c6 100644
--- a/core/mem_region.c
+++ b/core/mem_region.c
@@ -14,6 +14,7 @@ 
  * limitations under the License.
  */
 
+#include <inttypes.h>
 #include <skiboot.h>
 #include <mem-map.h>
 #include <libfdt_env.h>
@@ -320,11 +321,12 @@  int64_t mem_dump_free(void)
 
 			region_free+= hdr->num_longs * sizeof(long);
 		}
-		printf("Region %s free: %llu\n", region->name, region_free);
+		printf("Region %s free: %"PRIx64"\n",
+		       region->name, region_free);
 		total_free += region_free;
 	}
 
-	printf("Total free: %llu\n", total_free);
+	printf("Total free: %"PRIu64"\n", total_free);
 
 	return total_free;
 }
@@ -686,7 +688,7 @@  static bool add_region(struct mem_region *region)
 	struct mem_region *r;
 
 	if (mem_regions_finalised) {
-		prerror("MEM: add_region(%s@0x%llx) called after finalise!\n",
+		prerror("MEM: add_region(%s@0x%"PRIx64") called after finalise!\n",
 				region->name, region->start);
 		return false;
 	}
diff --git a/core/test/run-mem_range_is_reserved.c b/core/test/run-mem_range_is_reserved.c
index b50432615c89..0efe9b921cf4 100644
--- a/core/test/run-mem_range_is_reserved.c
+++ b/core/test/run-mem_range_is_reserved.c
@@ -178,7 +178,7 @@  static void run_test(struct test *test)
 		fprintf(stderr, "reserved regions:\n");
 
 		list_for_each(&regions, r, list) {
-			fprintf(stderr, "\t: %08x[%08x] %s\n",
+			fprintf(stderr, "\t: %08"PRIx64"[%08"PRIx64"] %s\n",
 					r->start, r->len, r->name);
 		}
 		exit(EXIT_FAILURE);
diff --git a/hdata/iohub.c b/hdata/iohub.c
index 42b1fafec56b..4fa256de6211 100644
--- a/hdata/iohub.c
+++ b/hdata/iohub.c
@@ -25,6 +25,7 @@ 
 #include <p5ioc2.h>
 #include <p7ioc.h>
 #include <vpd.h>
+#include <inttypes.h>
 
 #include "hdata.h"
 
@@ -142,15 +143,15 @@  static struct dt_node *io_add_p5ioc2(const struct cechub_io_hub *hub,
 	prlog(PR_DEBUG, "    GX#%d BUID_Ext = 0x%x\n",
 	      be32_to_cpu(hub->gx_index),
 	      be32_to_cpu(hub->buid_ext));
-	prlog(PR_DEBUG, "    GX BAR 0 = 0x%016llx\n",
+	prlog(PR_DEBUG, "    GX BAR 0 = 0x%016"PRIx64"\n",
 	      be64_to_cpu(hub->gx_ctrl_bar0));
-	prlog(PR_DEBUG, "    GX BAR 1 = 0x%016llx\n",
+	prlog(PR_DEBUG, "    GX BAR 1 = 0x%016"PRIx64"\n",
 	      be64_to_cpu(hub->gx_ctrl_bar1));
-	prlog(PR_DEBUG, "    GX BAR 2 = 0x%016llx\n",
+	prlog(PR_DEBUG, "    GX BAR 2 = 0x%016"PRIx64"\n",
 	      be64_to_cpu(hub->gx_ctrl_bar2));
-	prlog(PR_DEBUG, "    GX BAR 3 = 0x%016llx\n",
+	prlog(PR_DEBUG, "    GX BAR 3 = 0x%016"PRIx64"\n",
 	      be64_to_cpu(hub->gx_ctrl_bar3));
-	prlog(PR_DEBUG, "    GX BAR 4 = 0x%016llx\n",
+	prlog(PR_DEBUG, "    GX BAR 4 = 0x%016"PRIx64"\n",
 	      be64_to_cpu(hub->gx_ctrl_bar4));
 
 	/* We assume SBAR == GX0 + some hard coded offset */
@@ -194,15 +195,15 @@  static struct dt_node *io_add_p7ioc(const struct cechub_io_hub *hub,
 	prlog(PR_DEBUG, "    GX#%d BUID_Ext = 0x%x\n",
 	      be32_to_cpu(hub->gx_index),
 	      be32_to_cpu(hub->buid_ext));
-	prlog(PR_DEBUG, "    GX BAR 0 = 0x%016llx\n",
+	prlog(PR_DEBUG, "    GX BAR 0 = 0x%016"PRIx64"\n",
 	      be64_to_cpu(hub->gx_ctrl_bar0));
-	prlog(PR_DEBUG, "    GX BAR 1 = 0x%016llx\n",
+	prlog(PR_DEBUG, "    GX BAR 1 = 0x%016"PRIx64"\n",
 	      be64_to_cpu(hub->gx_ctrl_bar1));
-	prlog(PR_DEBUG, "    GX BAR 2 = 0x%016llx\n",
+	prlog(PR_DEBUG, "    GX BAR 2 = 0x%016"PRIx64"\n",
 	      be64_to_cpu(hub->gx_ctrl_bar2));
-	prlog(PR_DEBUG, "    GX BAR 3 = 0x%016llx\n",
+	prlog(PR_DEBUG, "    GX BAR 3 = 0x%016"PRIx64"\n",
 	      be64_to_cpu(hub->gx_ctrl_bar3));
-	prlog(PR_DEBUG, "    GX BAR 4 = 0x%016llx\n",
+	prlog(PR_DEBUG, "    GX BAR 4 = 0x%016"PRIx64"\n",
 	      be64_to_cpu(hub->gx_ctrl_bar4));
 
 	/* We only know about memory map 1 */
diff --git a/hdata/vpd.c b/hdata/vpd.c
index b317027eee57..d9ee77c6335b 100644
--- a/hdata/vpd.c
+++ b/hdata/vpd.c
@@ -21,6 +21,7 @@ 
 #include "hdata.h"
 #include <device.h>
 #include "hdata.h"
+#include <inttypes.h>
 
 struct card_info {
 	const char *ccin; 	/* Customer card identification number */
@@ -502,7 +503,7 @@  static struct dt_node *dt_create_vpd_node(struct dt_node *parent,
 	addr = (uint64_t)be16_to_cpu(entry->rsrc_id);
 	node = dt_new_addr(parent, name, addr);
 	if (!node) {
-		prerror("VPD: Creating node at %s@%llx failed\n", name, addr);
+		prerror("VPD: Creating node at %s@%"PRIx64" failed\n", name, addr);
 		return NULL;
 	}
 
diff --git a/include/inttypes.h b/include/inttypes.h
new file mode 100644
index 000000000000..8e640cac8e51
--- /dev/null
+++ b/include/inttypes.h
@@ -0,0 +1,44 @@ 
+/* Copyright 2015 IBM Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * 	http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* This file exists because a bunch of files are built as part of
+ * unit tests as well as skiboot and inttypes.h is part of libc rather
+ * than gcc, so to get the magic to work when we don't have libc sitting
+ * around, we get to rewrite inttypes.h.
+ */
+
+#ifndef __SKIBOOT_INTTYPES_H
+#define __SKIBOOT_INTTYPES_H
+
+#include <stdint.h>
+
+#ifndef __WORDSIZE
+/* If we don't have __WORDSIZE it means we're *certainly* building skiboot
+ * which will *ALWAYS* have a word size of 32bits.
+ * (unless someone goes and ports skiboot to something that isn't powerpc)
+ */
+#define __WORDSIZE 32
+#endif
+
+#if __WORDSIZE == 64
+#define PRIu64 "lu"
+#define PRIx64 "lx"
+#else
+#define PRIu64 "llu"
+#define PRIx64 "llx"
+#endif
+
+#endif