[Skiboot] [PATCH 3/4] npu2: Remove side effects in assert() calls.

Cyril Bur cyril.bur at au1.ibm.com
Thu Nov 9 11:44:10 AEDT 2017


This likely looks intentional and will do the correct thing.

The correct behaviour does rely on the fact that skiboot has a custom
assert() which will always generate code. 'Regular' assert() can be made
to generate no code. If we were to do that with this code, the results
would be, interesting!

This patch will also keep Coverity happy which is nice.

Fixes: CID 145242, 172044 and 172045
Signed-off-by: Cyril Bur <cyril.bur at au1.ibm.com>
---
 hw/npu2.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/hw/npu2.c b/hw/npu2.c
index d215b4ce..9f1bc143 100644
--- a/hw/npu2.c
+++ b/hw/npu2.c
@@ -1291,7 +1291,8 @@ static void npu2_probe_phb(struct dt_node *dn)
 	/* Retrieve chip id */
 	path = dt_get_path(dn);
 	gcid = dt_get_chip_id(dn);
-	assert(proc_chip = get_chip(gcid));
+	proc_chip = get_chip(gcid);
+	assert(proc_chip);
 	if ((proc_chip->ec_level & 0xf0) > 0x20) {
 		prerror("NPU2: unsupported ec level on Chip 0x%x!\n", gcid);
 		return;
@@ -1666,9 +1667,12 @@ static void npu2_add_interrupt_map(struct npu2 *p,
 	size_t map_size;
 	uint32_t mask[] = {0xff00, 0x0, 0x0, 0x7};
 
+	assert(p->phb.dt_node);
+	phb_dn = p->phb.dt_node;
+
 	npu2_phandle = dt_prop_get_u32(dn, "ibm,npcq");
-	assert((npu2_dn = dt_find_by_phandle(dt_root, npu2_phandle)));
-	assert((phb_dn = p->phb.dt_node));
+	npu2_dn = dt_find_by_phandle(dt_root, npu2_phandle);
+	assert(npu2_dn);
 	map_size = 7 * sizeof(*map) * p->total_devices;
 	map = malloc(map_size);
 	index = 0;
-- 
2.15.0



More information about the Skiboot mailing list