diff mbox series

tests/qtest/tpm: Declare input buffers const and static

Message ID 20200902080909.161034-1-philmd@redhat.com
State New
Headers show
Series tests/qtest/tpm: Declare input buffers const and static | expand

Commit Message

Philippe Mathieu-Daudé Sept. 2, 2020, 8:09 a.m. UTC
The functions using these arrays expect a "const unsigned char *"
argument, it is safe to declare these as 'static const'.

Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 tests/qtest/tpm-tests.c |  4 ++--
 tests/qtest/tpm-util.c  | 10 +++++-----
 2 files changed, 7 insertions(+), 7 deletions(-)

Comments

Darren Kenny Sept. 2, 2020, 8:39 a.m. UTC | #1
On Wednesday, 2020-09-02 at 10:09:09 +02, Philippe Mathieu-Daudé wrote:
> The functions using these arrays expect a "const unsigned char *"
> argument, it is safe to declare these as 'static const'.
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>

Reviewed-by: Darren Kenny <darren.kenny@oracle.com>

> ---
>  tests/qtest/tpm-tests.c |  4 ++--
>  tests/qtest/tpm-util.c  | 10 +++++-----
>  2 files changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/tests/qtest/tpm-tests.c b/tests/qtest/tpm-tests.c
> index a2f2838e15b..70c80f8379a 100644
> --- a/tests/qtest/tpm-tests.c
> +++ b/tests/qtest/tpm-tests.c
> @@ -59,7 +59,7 @@ void tpm_test_swtpm_test(const char *src_tpm_path, tx_func *tx,
>      tpm_util_startup(s, tx);
>      tpm_util_pcrextend(s, tx);
>  
> -    unsigned char tpm_pcrread_resp[] =
> +    static const unsigned char tpm_pcrread_resp[] =
>          "\x80\x01\x00\x00\x00\x3e\x00\x00\x00\x00\x00\x00\x00\x16\x00\x00"
>          "\x00\x01\x00\x0b\x03\x00\x04\x00\x00\x00\x00\x01\x00\x20\xf6\x85"
>          "\x98\xe5\x86\x8d\xe6\x8b\x97\x29\x99\x60\xf2\x71\x7d\x17\x67\x89"
> @@ -107,7 +107,7 @@ void tpm_test_swtpm_migration_test(const char *src_tpm_path,
>      tpm_util_startup(src_qemu, tx);
>      tpm_util_pcrextend(src_qemu, tx);
>  
> -    unsigned char tpm_pcrread_resp[] =
> +    static const unsigned char tpm_pcrread_resp[] =
>          "\x80\x01\x00\x00\x00\x3e\x00\x00\x00\x00\x00\x00\x00\x16\x00\x00"
>          "\x00\x01\x00\x0b\x03\x00\x04\x00\x00\x00\x00\x01\x00\x20\xf6\x85"
>          "\x98\xe5\x86\x8d\xe6\x8b\x97\x29\x99\x60\xf2\x71\x7d\x17\x67\x89"
> diff --git a/tests/qtest/tpm-util.c b/tests/qtest/tpm-util.c
> index e2b29ef0f8c..3ed6c8548a6 100644
> --- a/tests/qtest/tpm-util.c
> +++ b/tests/qtest/tpm-util.c
> @@ -98,9 +98,9 @@ void tpm_util_tis_transfer(QTestState *s,
>  void tpm_util_startup(QTestState *s, tx_func *tx)
>  {
>      unsigned char buffer[1024];
> -    unsigned char tpm_startup[] =
> +    static const unsigned char tpm_startup[] =
>          "\x80\x01\x00\x00\x00\x0c\x00\x00\x01\x44\x00\x00";
> -    unsigned char tpm_startup_resp[] =
> +    static const unsigned char tpm_startup_resp[] =
>          "\x80\x01\x00\x00\x00\x0a\x00\x00\x00\x00";
>  
>      tx(s, tpm_startup, sizeof(tpm_startup), buffer, sizeof(buffer));
> @@ -112,14 +112,14 @@ void tpm_util_startup(QTestState *s, tx_func *tx)
>  void tpm_util_pcrextend(QTestState *s, tx_func *tx)
>  {
>      unsigned char buffer[1024];
> -    unsigned char tpm_pcrextend[] =
> +    static const unsigned char tpm_pcrextend[] =
>          "\x80\x02\x00\x00\x00\x41\x00\x00\x01\x82\x00\x00\x00\x0a\x00\x00"
>          "\x00\x09\x40\x00\x00\x09\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00"
>          "\x0b\x74\x65\x73\x74\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
>          "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
>          "\x00";
>  
> -    unsigned char tpm_pcrextend_resp[] =
> +    static const unsigned char tpm_pcrextend_resp[] =
>          "\x80\x02\x00\x00\x00\x13\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
>          "\x01\x00\x00";
>  
> @@ -133,7 +133,7 @@ void tpm_util_pcrread(QTestState *s, tx_func *tx,
>                        const unsigned char *exp_resp, size_t exp_resp_size)
>  {
>      unsigned char buffer[1024];
> -    unsigned char tpm_pcrread[] =
> +    static const unsigned char tpm_pcrread[] =
>          "\x80\x01\x00\x00\x00\x14\x00\x00\x01\x7e\x00\x00\x00\x01\x00\x0b"
>          "\x03\x00\x04\x00";
>  
> -- 
> 2.26.2
Stefan Berger Sept. 2, 2020, 2:37 p.m. UTC | #2
On 9/2/20 4:39 AM, Darren Kenny wrote:
> On Wednesday, 2020-09-02 at 10:09:09 +02, Philippe Mathieu-Daudé wrote:
>> The functions using these arrays expect a "const unsigned char *"
>> argument, it is safe to declare these as 'static const'.
>>
>> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
> Reviewed-by: Darren Kenny <darren.kenny@oracle.com>

Would this qualify for qemu-trivial?

Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Thomas Huth Sept. 2, 2020, 3:59 p.m. UTC | #3
On 02/09/2020 16.37, Stefan Berger wrote:
> On 9/2/20 4:39 AM, Darren Kenny wrote:
>> On Wednesday, 2020-09-02 at 10:09:09 +02, Philippe Mathieu-Daudé wrote:
>>> The functions using these arrays expect a "const unsigned char *"
>>> argument, it is safe to declare these as 'static const'.
>>>
>>> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
>> Reviewed-by: Darren Kenny <darren.kenny@oracle.com>
> 
> Would this qualify for qemu-trivial?
> 
> Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>

I can take it through the qtest tree.

 Thomas
diff mbox series

Patch

diff --git a/tests/qtest/tpm-tests.c b/tests/qtest/tpm-tests.c
index a2f2838e15b..70c80f8379a 100644
--- a/tests/qtest/tpm-tests.c
+++ b/tests/qtest/tpm-tests.c
@@ -59,7 +59,7 @@  void tpm_test_swtpm_test(const char *src_tpm_path, tx_func *tx,
     tpm_util_startup(s, tx);
     tpm_util_pcrextend(s, tx);
 
-    unsigned char tpm_pcrread_resp[] =
+    static const unsigned char tpm_pcrread_resp[] =
         "\x80\x01\x00\x00\x00\x3e\x00\x00\x00\x00\x00\x00\x00\x16\x00\x00"
         "\x00\x01\x00\x0b\x03\x00\x04\x00\x00\x00\x00\x01\x00\x20\xf6\x85"
         "\x98\xe5\x86\x8d\xe6\x8b\x97\x29\x99\x60\xf2\x71\x7d\x17\x67\x89"
@@ -107,7 +107,7 @@  void tpm_test_swtpm_migration_test(const char *src_tpm_path,
     tpm_util_startup(src_qemu, tx);
     tpm_util_pcrextend(src_qemu, tx);
 
-    unsigned char tpm_pcrread_resp[] =
+    static const unsigned char tpm_pcrread_resp[] =
         "\x80\x01\x00\x00\x00\x3e\x00\x00\x00\x00\x00\x00\x00\x16\x00\x00"
         "\x00\x01\x00\x0b\x03\x00\x04\x00\x00\x00\x00\x01\x00\x20\xf6\x85"
         "\x98\xe5\x86\x8d\xe6\x8b\x97\x29\x99\x60\xf2\x71\x7d\x17\x67\x89"
diff --git a/tests/qtest/tpm-util.c b/tests/qtest/tpm-util.c
index e2b29ef0f8c..3ed6c8548a6 100644
--- a/tests/qtest/tpm-util.c
+++ b/tests/qtest/tpm-util.c
@@ -98,9 +98,9 @@  void tpm_util_tis_transfer(QTestState *s,
 void tpm_util_startup(QTestState *s, tx_func *tx)
 {
     unsigned char buffer[1024];
-    unsigned char tpm_startup[] =
+    static const unsigned char tpm_startup[] =
         "\x80\x01\x00\x00\x00\x0c\x00\x00\x01\x44\x00\x00";
-    unsigned char tpm_startup_resp[] =
+    static const unsigned char tpm_startup_resp[] =
         "\x80\x01\x00\x00\x00\x0a\x00\x00\x00\x00";
 
     tx(s, tpm_startup, sizeof(tpm_startup), buffer, sizeof(buffer));
@@ -112,14 +112,14 @@  void tpm_util_startup(QTestState *s, tx_func *tx)
 void tpm_util_pcrextend(QTestState *s, tx_func *tx)
 {
     unsigned char buffer[1024];
-    unsigned char tpm_pcrextend[] =
+    static const unsigned char tpm_pcrextend[] =
         "\x80\x02\x00\x00\x00\x41\x00\x00\x01\x82\x00\x00\x00\x0a\x00\x00"
         "\x00\x09\x40\x00\x00\x09\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00"
         "\x0b\x74\x65\x73\x74\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x00";
 
-    unsigned char tpm_pcrextend_resp[] =
+    static const unsigned char tpm_pcrextend_resp[] =
         "\x80\x02\x00\x00\x00\x13\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
         "\x01\x00\x00";
 
@@ -133,7 +133,7 @@  void tpm_util_pcrread(QTestState *s, tx_func *tx,
                       const unsigned char *exp_resp, size_t exp_resp_size)
 {
     unsigned char buffer[1024];
-    unsigned char tpm_pcrread[] =
+    static const unsigned char tpm_pcrread[] =
         "\x80\x01\x00\x00\x00\x14\x00\x00\x01\x7e\x00\x00\x00\x01\x00\x0b"
         "\x03\x00\x04\x00";