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

AlexChen posted 1 patch 3 years, 4 months ago
Test checkpatch passed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/5FA41448.4040404@huawei.com
Maintainers: Laurent Vivier <lvivier@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Thomas Huth <thuth@redhat.com>, Stefan Berger <stefanb@linux.vnet.ibm.com>
tests/qtest/tpm-tests.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
[PATCH] tests/qtest/tpm: Remove redundant check in the tpm_test_swtpm_test()
Posted by AlexChen 3 years, 4 months ago
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.

Reported-by: Euler Robot <euler.robot@huawei.com>
Signed-off-by: Alex Chen <alex.chen@huawei.com>
---
 tests/qtest/tpm-tests.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/tests/qtest/tpm-tests.c b/tests/qtest/tpm-tests.c
index 70c80f8379..0da3a8a4df 100644
--- a/tests/qtest/tpm-tests.c
+++ b/tests/qtest/tpm-tests.c
@@ -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

Re: [PATCH] tests/qtest/tpm: Remove redundant check in the tpm_test_swtpm_test()
Posted by Marc-André Lureau 3 years, 4 months ago
On Thu, Nov 5, 2020 at 7:05 PM AlexChen <alex.chen@huawei.com> wrote:

> 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.
>
> Reported-by: Euler Robot <euler.robot@huawei.com>
> Signed-off-by: Alex Chen <alex.chen@huawei.com>
>

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

---
>  tests/qtest/tpm-tests.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/tests/qtest/tpm-tests.c b/tests/qtest/tpm-tests.c
> index 70c80f8379..0da3a8a4df 100644
> --- a/tests/qtest/tpm-tests.c
> +++ b/tests/qtest/tpm-tests.c
> @@ -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
>
>

-- 
Marc-André Lureau
Re: [PATCH] tests/qtest/tpm: Remove redundant check in the tpm_test_swtpm_test()
Posted by Thomas Huth 3 years, 4 months ago
On 05/11/2020 16.03, AlexChen wrote:
> 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.
> 
> Reported-by: Euler Robot <euler.robot@huawei.com>
> Signed-off-by: Alex Chen <alex.chen@huawei.com>
> ---
>  tests/qtest/tpm-tests.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/tests/qtest/tpm-tests.c b/tests/qtest/tpm-tests.c
> index 70c80f8379..0da3a8a4df 100644
> --- a/tests/qtest/tpm-tests.c
> +++ b/tests/qtest/tpm-tests.c
> @@ -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.

Reviewed-by: Thomas Huth <thuth@redhat.com>

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