Skip to contentSkip to conversation

tests/qtest/tpm: Remove redundant check in the tpm_test_swtpm_test()

PATCH In review AlexChen 3 participants 3 messages Nov 5, 2020 – Nov 9, 2020

lore
Share & tools
lore

AlexChen

author
#0 lore raw

PATCH 1/1 tests/qtest/tpm: Remove redundant check in the tpm_test_swtpm_test()

The 'addr' would not be NULL after checking 'succ' is valid,
and it has been dereferenced in the previous code(args = g_strdup_printf()). So the check on 'addr' in the tpm_test_swtpm_test() is redundant. Remove it.

---
 tests/qtest/tpm-tests.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
tests/qtest/tpm-tests.c +2 -4
index 70c80f8379..0da3a8a4df 100644
@@ -70,10 +70,8 @@ void tpm_test_swtpm_test(const char *src_tpm_path, tx_func *tx,
     qtest_end();
     tpm_util_swtpm_kill(swtpm_pid);
 
-    if (addr) {
-        g_unlink(addr->u.q_unix.path);
-        qapi_free_SocketAddress(addr);
-    }
+    g_unlink(addr->u.q_unix.path);
+    qapi_free_SocketAddress(addr);
 }
 
 void tpm_test_swtpm_migration_test(const char *src_tpm_path,
Signature · 1 line
2.19.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · AlexChen

The 'addr' would not be NULL after checking 'succ' is valid, and it has been dereferenced in the previous code(args = g_strdup_printf()).
So the check on 'addr' in the tpm_test_swtpm_test() is redundant. Remove it.

---

Quoted 25 lines
 tests/qtest/tpm-tests.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
tests/qtest/tpm-tests.c +2 -4
index 70c80f8379..0da3a8a4df 100644
@@ -70,10 +70,8 @@ void tpm_test_swtpm_test(const char *src_tpm_path,
 tx_func *tx,
     qtest_end();
     tpm_util_swtpm_kill(swtpm_pid);
 
-    if (addr) {
-        g_unlink(addr->u.q_unix.path);
-        qapi_free_SocketAddress(addr);
-    }
+    g_unlink(addr->u.q_unix.path);
+    qapi_free_SocketAddress(addr);
 }
 

void tpm_test_swtpm_migration_test(const char *src_tpm_path,
--
2.19.1

Signature · 1 line
Marc-André Lureau
Reviewed-by on v1 1/1
#2 lore raw
In reply to AlexChen
Quoted 15 lines · AlexChen

The 'addr' would not be NULL after checking 'succ' is valid,
and it has been dereferenced in the previous code(args = g_strdup_printf()). So the check on 'addr' in the tpm_test_swtpm_test() is redundant. Remove it.

---
 tests/qtest/tpm-tests.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
tests/qtest/tpm-tests.c +0 -0
index 70c80f8379..0da3a8a4df 100644

tests/qtest/tpm-tests.c void tpm_test_swtpm_test(const char *src_tpm_path, tx_func *tx, · line 75

Quoted 10 lines
tests/qtest/tpm-tests.c +2 -4
@@ -70,10 +70,8 @@ void tpm_test_swtpm_test(const char *src_tpm_path, tx_func *tx,
     qtest_end();
     tpm_util_swtpm_kill(swtpm_pid);
 
-    if (addr) {
-        g_unlink(addr->u.q_unix.path);
-        qapi_free_SocketAddress(addr);
-    }
+    g_unlink(addr->u.q_unix.path);
+    qapi_free_SocketAddress(addr);
 }

Right, addr gets already dereferenced earlier in this function, so it can not be NULL here.

Thanks, I'll queue this for my next pull request.