diff mbox series

lib: fwts_firmware: cast 1 to UL to ensure no signed extension, clean up comments

Message ID 20201126113541.1978693-1-colin.king@canonical.com
State Accepted
Headers show
Series lib: fwts_firmware: cast 1 to UL to ensure no signed extension, clean up comments | expand

Commit Message

Colin Ian King Nov. 26, 2020, 11:35 a.m. UTC
From: Colin Ian King <colin.king@canonical.com>

Ensure the value being shifted is unsigned to avoid any signed extension
warnings by static analysis.  Also clean up a few comments.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/lib/src/fwts_firmware.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Comments

Alex Hung Nov. 26, 2020, 9:17 p.m. UTC | #1
On 2020-11-26 4:35 a.m., Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Ensure the value being shifted is unsigned to avoid any signed extension
> warnings by static analysis.  Also clean up a few comments.
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/lib/src/fwts_firmware.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/src/lib/src/fwts_firmware.c b/src/lib/src/fwts_firmware.c
> index 636f6701..7655140a 100644
> --- a/src/lib/src/fwts_firmware.c
> +++ b/src/lib/src/fwts_firmware.c
> @@ -78,7 +78,6 @@ int fwts_firmware_features(void)
>  	}
>  
>  	/* just check for IPMI device presence */
> -
>  	if (!stat("/dev/ipmi0", &ipmi_statbuf))
>  		features |= FWTS_FW_FEATURE_IPMI;
>  
> @@ -94,14 +93,16 @@ const char *fwts_firmware_feature_string(const fwts_firmware_feature features)
>  	char *p;
>  	int i;
>  
> -	/* ensure we have enough space in str to store n names, plus n-1
> -	 * separators, plus a trailing nul */
> +	/*
> +	 * ensure we have enough space in str to store n names, plus n-1
> +	 * separators, plus a trailing nul
> +	 */
>  	FWTS_ASSERT((n * (sizeof(feature_names[0].name) - 1)) +
>  				((n-1) * (sizeof(sep) - 1)) + 1 <
>  			sizeof(str), str_too_small);
>  
>  	/* ensure we have a name defined for all features */
> -	FWTS_ASSERT(((1 << n) - 1) == FWTS_FW_FEATURE_ALL,
> +	FWTS_ASSERT(((1UL << n) - 1) == FWTS_FW_FEATURE_ALL,
>  			invalid_feature_names);
>  
>  	for (p = str, i = 0; i < n; i++) {
> 


Acked-by: Alex Hung <alex.hung@canonical.com>
Ivan Hu Nov. 30, 2020, 6:02 a.m. UTC | #2
On 11/26/20 7:35 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Ensure the value being shifted is unsigned to avoid any signed extension
> warnings by static analysis.  Also clean up a few comments.
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/lib/src/fwts_firmware.c | 9 +++++----
>  1 file changed, 5 insertions(+), 4 deletions(-)
> 
> diff --git a/src/lib/src/fwts_firmware.c b/src/lib/src/fwts_firmware.c
> index 636f6701..7655140a 100644
> --- a/src/lib/src/fwts_firmware.c
> +++ b/src/lib/src/fwts_firmware.c
> @@ -78,7 +78,6 @@ int fwts_firmware_features(void)
>  	}
>  
>  	/* just check for IPMI device presence */
> -
>  	if (!stat("/dev/ipmi0", &ipmi_statbuf))
>  		features |= FWTS_FW_FEATURE_IPMI;
>  
> @@ -94,14 +93,16 @@ const char *fwts_firmware_feature_string(const fwts_firmware_feature features)
>  	char *p;
>  	int i;
>  
> -	/* ensure we have enough space in str to store n names, plus n-1
> -	 * separators, plus a trailing nul */
> +	/*
> +	 * ensure we have enough space in str to store n names, plus n-1
> +	 * separators, plus a trailing nul
> +	 */
>  	FWTS_ASSERT((n * (sizeof(feature_names[0].name) - 1)) +
>  				((n-1) * (sizeof(sep) - 1)) + 1 <
>  			sizeof(str), str_too_small);
>  
>  	/* ensure we have a name defined for all features */
> -	FWTS_ASSERT(((1 << n) - 1) == FWTS_FW_FEATURE_ALL,
> +	FWTS_ASSERT(((1UL << n) - 1) == FWTS_FW_FEATURE_ALL,
>  			invalid_feature_names);
>  
>  	for (p = str, i = 0; i < n; i++) {
> 


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

Patch

diff --git a/src/lib/src/fwts_firmware.c b/src/lib/src/fwts_firmware.c
index 636f6701..7655140a 100644
--- a/src/lib/src/fwts_firmware.c
+++ b/src/lib/src/fwts_firmware.c
@@ -78,7 +78,6 @@  int fwts_firmware_features(void)
 	}
 
 	/* just check for IPMI device presence */
-
 	if (!stat("/dev/ipmi0", &ipmi_statbuf))
 		features |= FWTS_FW_FEATURE_IPMI;
 
@@ -94,14 +93,16 @@  const char *fwts_firmware_feature_string(const fwts_firmware_feature features)
 	char *p;
 	int i;
 
-	/* ensure we have enough space in str to store n names, plus n-1
-	 * separators, plus a trailing nul */
+	/*
+	 * ensure we have enough space in str to store n names, plus n-1
+	 * separators, plus a trailing nul
+	 */
 	FWTS_ASSERT((n * (sizeof(feature_names[0].name) - 1)) +
 				((n-1) * (sizeof(sep) - 1)) + 1 <
 			sizeof(str), str_too_small);
 
 	/* ensure we have a name defined for all features */
-	FWTS_ASSERT(((1 << n) - 1) == FWTS_FW_FEATURE_ALL,
+	FWTS_ASSERT(((1UL << n) - 1) == FWTS_FW_FEATURE_ALL,
 			invalid_feature_names);
 
 	for (p = str, i = 0; i < n; i++) {