diff mbox series

fwts_tpm: make function args and a variable const

Message ID 20210411135101.1204045-1-colin.king@canonical.com
State Accepted
Headers show
Series fwts_tpm: make function args and a variable const | expand

Commit Message

Colin Ian King April 11, 2021, 1:51 p.m. UTC
From: Colin Ian King <colin.king@canonical.com>

Make read-only function arguments and a variable const

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/lib/include/fwts_tpm.h |  5 +++--
 src/lib/src/fwts_tpm.c     | 10 +++++++---
 2 files changed, 10 insertions(+), 5 deletions(-)

Comments

Alex Hung April 11, 2021, 8:55 p.m. UTC | #1
On 2021-04-11 7:51 a.m., Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Make read-only function arguments and a variable const
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/lib/include/fwts_tpm.h |  5 +++--
>  src/lib/src/fwts_tpm.c     | 10 +++++++---
>  2 files changed, 10 insertions(+), 5 deletions(-)
> 
> diff --git a/src/lib/include/fwts_tpm.h b/src/lib/include/fwts_tpm.h
> index 08ed52c1..ca96f971 100644
> --- a/src/lib/include/fwts_tpm.h
> +++ b/src/lib/include/fwts_tpm.h
> @@ -167,8 +167,9 @@ typedef struct {
>  */
>  } __attribute__ ((packed)) fwts_tcg_pcr_event2;
>  
> -void fwts_tpm_data_hexdump(fwts_framework *fw, uint8_t *data, size_t size, char *str);
> -uint8_t fwts_tpm_get_hash_size(TPM2_ALG_ID hash);
> +void fwts_tpm_data_hexdump(fwts_framework *fw, const uint8_t *data,
> +	const size_t size, const char *str);
> +uint8_t fwts_tpm_get_hash_size(const TPM2_ALG_ID hash);
>  
>  PRAGMA_POP
>  
> diff --git a/src/lib/src/fwts_tpm.c b/src/lib/src/fwts_tpm.c
> index c3c88dac..b79c200c 100644
> --- a/src/lib/src/fwts_tpm.c
> +++ b/src/lib/src/fwts_tpm.c
> @@ -24,14 +24,18 @@
>   *  fwts_tpm_data_hexdump
>   *	hex dump of a tpm event log data
>   */
> -void fwts_tpm_data_hexdump(fwts_framework *fw, uint8_t *data, size_t size, char *str)
> +void fwts_tpm_data_hexdump(
> +	fwts_framework *fw,
> +	const uint8_t *data,
> +	const size_t size,
> +	const char *str)
>  {
>  	size_t i;
>  
>  	fwts_log_info_verbatim(fw, "%s: ", str);
>  	for (i = 0; i < size; i += 16) {
>  		char buffer[128];
> -		size_t left = size - i;
> +		const size_t left = size - i;
>  
>  		fwts_dump_raw_data(buffer, sizeof(buffer), data + i, i, left > 16 ? 16 : left);
>  		fwts_log_info_verbatim(fw, "%s", buffer + 2);
> @@ -42,7 +46,7 @@ void fwts_tpm_data_hexdump(fwts_framework *fw, uint8_t *data, size_t size, char
>   *  fwts_tpm_evlog_type_to_string
>   *	get hash size
>   */
> -uint8_t fwts_tpm_get_hash_size (TPM2_ALG_ID hash)
> +uint8_t fwts_tpm_get_hash_size(const TPM2_ALG_ID hash)
>  {
>  	uint8_t sz;
>  
> 

Acked-by: Alex Hung <alex.hung@canonical.com>
ivanhu April 12, 2021, 7:37 a.m. UTC | #2
On 4/11/21 9:51 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Make read-only function arguments and a variable const
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/lib/include/fwts_tpm.h |  5 +++--
>  src/lib/src/fwts_tpm.c     | 10 +++++++---
>  2 files changed, 10 insertions(+), 5 deletions(-)
> 
> diff --git a/src/lib/include/fwts_tpm.h b/src/lib/include/fwts_tpm.h
> index 08ed52c1..ca96f971 100644
> --- a/src/lib/include/fwts_tpm.h
> +++ b/src/lib/include/fwts_tpm.h
> @@ -167,8 +167,9 @@ typedef struct {
>  */
>  } __attribute__ ((packed)) fwts_tcg_pcr_event2;
>  
> -void fwts_tpm_data_hexdump(fwts_framework *fw, uint8_t *data, size_t size, char *str);
> -uint8_t fwts_tpm_get_hash_size(TPM2_ALG_ID hash);
> +void fwts_tpm_data_hexdump(fwts_framework *fw, const uint8_t *data,
> +	const size_t size, const char *str);
> +uint8_t fwts_tpm_get_hash_size(const TPM2_ALG_ID hash);
>  
>  PRAGMA_POP
>  
> diff --git a/src/lib/src/fwts_tpm.c b/src/lib/src/fwts_tpm.c
> index c3c88dac..b79c200c 100644
> --- a/src/lib/src/fwts_tpm.c
> +++ b/src/lib/src/fwts_tpm.c
> @@ -24,14 +24,18 @@
>   *  fwts_tpm_data_hexdump
>   *	hex dump of a tpm event log data
>   */
> -void fwts_tpm_data_hexdump(fwts_framework *fw, uint8_t *data, size_t size, char *str)
> +void fwts_tpm_data_hexdump(
> +	fwts_framework *fw,
> +	const uint8_t *data,
> +	const size_t size,
> +	const char *str)
>  {
>  	size_t i;
>  
>  	fwts_log_info_verbatim(fw, "%s: ", str);
>  	for (i = 0; i < size; i += 16) {
>  		char buffer[128];
> -		size_t left = size - i;
> +		const size_t left = size - i;
>  
>  		fwts_dump_raw_data(buffer, sizeof(buffer), data + i, i, left > 16 ? 16 : left);
>  		fwts_log_info_verbatim(fw, "%s", buffer + 2);
> @@ -42,7 +46,7 @@ void fwts_tpm_data_hexdump(fwts_framework *fw, uint8_t *data, size_t size, char
>   *  fwts_tpm_evlog_type_to_string
>   *	get hash size
>   */
> -uint8_t fwts_tpm_get_hash_size (TPM2_ALG_ID hash)
> +uint8_t fwts_tpm_get_hash_size(const TPM2_ALG_ID hash)
>  {
>  	uint8_t sz;
>  
> 

Acked-by: Ivan Hu <ivan.hu@canonical.com>
diff mbox series

Patch

diff --git a/src/lib/include/fwts_tpm.h b/src/lib/include/fwts_tpm.h
index 08ed52c1..ca96f971 100644
--- a/src/lib/include/fwts_tpm.h
+++ b/src/lib/include/fwts_tpm.h
@@ -167,8 +167,9 @@  typedef struct {
 */
 } __attribute__ ((packed)) fwts_tcg_pcr_event2;
 
-void fwts_tpm_data_hexdump(fwts_framework *fw, uint8_t *data, size_t size, char *str);
-uint8_t fwts_tpm_get_hash_size(TPM2_ALG_ID hash);
+void fwts_tpm_data_hexdump(fwts_framework *fw, const uint8_t *data,
+	const size_t size, const char *str);
+uint8_t fwts_tpm_get_hash_size(const TPM2_ALG_ID hash);
 
 PRAGMA_POP
 
diff --git a/src/lib/src/fwts_tpm.c b/src/lib/src/fwts_tpm.c
index c3c88dac..b79c200c 100644
--- a/src/lib/src/fwts_tpm.c
+++ b/src/lib/src/fwts_tpm.c
@@ -24,14 +24,18 @@ 
  *  fwts_tpm_data_hexdump
  *	hex dump of a tpm event log data
  */
-void fwts_tpm_data_hexdump(fwts_framework *fw, uint8_t *data, size_t size, char *str)
+void fwts_tpm_data_hexdump(
+	fwts_framework *fw,
+	const uint8_t *data,
+	const size_t size,
+	const char *str)
 {
 	size_t i;
 
 	fwts_log_info_verbatim(fw, "%s: ", str);
 	for (i = 0; i < size; i += 16) {
 		char buffer[128];
-		size_t left = size - i;
+		const size_t left = size - i;
 
 		fwts_dump_raw_data(buffer, sizeof(buffer), data + i, i, left > 16 ? 16 : left);
 		fwts_log_info_verbatim(fw, "%s", buffer + 2);
@@ -42,7 +46,7 @@  void fwts_tpm_data_hexdump(fwts_framework *fw, uint8_t *data, size_t size, char
  *  fwts_tpm_evlog_type_to_string
  *	get hash size
  */
-uint8_t fwts_tpm_get_hash_size (TPM2_ALG_ID hash)
+uint8_t fwts_tpm_get_hash_size(const TPM2_ALG_ID hash)
 {
 	uint8_t sz;