[Skiboot] [PATCH 3/6] fsp/chiptod: Fix initialised variable

Joel Stanley joel at jms.id.au
Tue Jul 21 13:23:12 AEST 2015


If chiptod_adjust_topology returned true, rc would be uninitialised and the
message type passed to fsp_mkmsg would be undefined.

This also changes chiptod_adjust_topology to return true/false instead
of -1 and 0.

hw/fsp/fsp-chiptod.c:45:7: error: variable 'rc' is used uninitialized whenever
      'if' condition is false [-Werror,-Wsometimes-uninitialized]
                if (chiptod_adjust_topology(topo, action) < 0)
                    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
hw/fsp/fsp-chiptod.c:48:50: note: uninitialized use occurs here
                resp = fsp_mkmsg(FSP_RSP_TOPO_ENABLE_DISABLE | rc, 0);
                                                               ^~
hw/fsp/fsp-chiptod.c:45:3: note: remove the 'if' if its condition is always true
                if (chiptod_adjust_topology(topo, action) < 0)
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
hw/fsp/fsp-chiptod.c:30:12: note: initialize the variable 'rc' to silence this
      warning
        uint8_t rc;
                  ^
                   = '\0'

Signed-off-by: Joel Stanley <joel at jms.id.au>

foo

Signed-off-by: Joel Stanley <joel at jms.id.au>
---
 hw/chiptod.c         | 10 +++++-----
 hw/fsp/fsp-chiptod.c | 12 +++++++-----
 include/chiptod.h    |  2 +-
 3 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/hw/chiptod.c b/hw/chiptod.c
index bae4b50..69e05d9 100644
--- a/hw/chiptod.c
+++ b/hw/chiptod.c
@@ -1657,12 +1657,12 @@ static void chiptod_discover_new_backup(enum chiptod_topology topo)
  * topology.
  *
  * Return values:
- *	0	<= Success
- *	-1	<= Topology is active and in use.
+ *	true	<= Success
+ *	false	<= Topology is active and in use.
  */
-int chiptod_adjust_topology(enum chiptod_topology topo, bool enable)
+bool chiptod_adjust_topology(enum chiptod_topology topo, bool enable)
 {
-	uint8_t rc = 0;
+	uint8_t rc = true;
 	/*
 	 * The FSP can only request that the currently inactive topology
 	 * be disabled or enabled. If the requested topology is currently
@@ -1671,7 +1671,7 @@ int chiptod_adjust_topology(enum chiptod_topology topo, bool enable)
 	 */
 	lock(&chiptod_lock);
 	if (topo == current_topology) {
-		rc = -1;
+		rc = false;
 		goto out;
 	}
 
diff --git a/hw/fsp/fsp-chiptod.c b/hw/fsp/fsp-chiptod.c
index 69c59c6..fc8125f 100644
--- a/hw/fsp/fsp-chiptod.c
+++ b/hw/fsp/fsp-chiptod.c
@@ -22,12 +22,12 @@
 #define FSP_STATUS_TOPO_IN_USE	0xb8		/* topology is in use */
 
 static bool fsp_chiptod_update_topology(uint32_t cmd_sub_mod,
-					       struct fsp_msg *msg __unused)
+					struct fsp_msg *msg)
 {
 	struct fsp_msg *resp;
 	enum chiptod_topology topo;
 	bool action;
-	uint8_t rc;
+	uint8_t status;
 
 	switch (cmd_sub_mod) {
 	case FSP_CMD_TOPO_ENABLE_DISABLE:
@@ -42,10 +42,12 @@ static bool fsp_chiptod_update_topology(uint32_t cmd_sub_mod,
 					action ? "Enable" : "Disable",
 					topo ? "Secondary" : "Primary");
 
-		if (chiptod_adjust_topology(topo, action) < 0)
-			rc = FSP_STATUS_TOPO_IN_USE;
+		if (!chiptod_adjust_topology(topo, action))
+			status = FSP_STATUS_TOPO_IN_USE;
+		else
+			status = 0x00;
 
-		resp = fsp_mkmsg(FSP_RSP_TOPO_ENABLE_DISABLE | rc, 0);
+		resp = fsp_mkmsg(FSP_RSP_TOPO_ENABLE_DISABLE | status, 0);
 		if (!resp) {
 			prerror("CHIPTOD: Response allocation failed\n");
 			return false;
diff --git a/include/chiptod.h b/include/chiptod.h
index b220fd7..daf37b1 100644
--- a/include/chiptod.h
+++ b/include/chiptod.h
@@ -31,7 +31,7 @@ extern void chiptod_init(void);
 extern bool chiptod_wakeup_resync(void);
 extern int chiptod_recover_tb_errors(void);
 extern void chiptod_reset_tb(void);
-extern int chiptod_adjust_topology(enum chiptod_topology topo, bool enable);
+extern bool chiptod_adjust_topology(enum chiptod_topology topo, bool enable);
 extern bool chiptod_capp_timebase_sync(uint32_t chip_id);
 
 #endif /* __CHIPTOD_H */
-- 
2.1.4



More information about the Skiboot mailing list