diff mbox series

uefi: uefirttime: make status static, cleans up cppcheck warnings

Message ID 20190611092843.28519-1-colin.king@canonical.com
State Accepted
Headers show
Series uefi: uefirttime: make status static, cleans up cppcheck warnings | expand

Commit Message

Colin Ian King June 11, 2019, 9:28 a.m. UTC
From: Colin Ian King <colin.king@canonical.com>

Using an auto-variable (declared on the stack) for the status
is problematic because we return the address of this variable
back to the callee via a function parameter. Thus there is a
potential of the callee referencing the now dead stack variable.
Although this is not actually referenced later, it's worth just
cleaning this up by making the variable static so we avoid any
potential risk in the future.  Cleans up 3 cppcheck warnings
of the kind:

"(error) Address of local auto-variable assigned to a function parameter."

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/uefi/uefirttime/uefirttime.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

Comments

Alex Hung June 11, 2019, 4:32 p.m. UTC | #1
On 2019-06-11 2:28 a.m., Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> Using an auto-variable (declared on the stack) for the status
> is problematic because we return the address of this variable
> back to the callee via a function parameter. Thus there is a
> potential of the callee referencing the now dead stack variable.
> Although this is not actually referenced later, it's worth just
> cleaning this up by making the variable static so we avoid any
> potential risk in the future.  Cleans up 3 cppcheck warnings
> of the kind:
> 
> "(error) Address of local auto-variable assigned to a function parameter."
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/uefi/uefirttime/uefirttime.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/src/uefi/uefirttime/uefirttime.c b/src/uefi/uefirttime/uefirttime.c
> index 7626f06e..647bd5a7 100644
> --- a/src/uefi/uefirttime/uefirttime.c
> +++ b/src/uefi/uefirttime/uefirttime.c
> @@ -401,8 +401,9 @@ static int uefirttime_test_settime_invalid(
>  	struct efi_settime *settime)
>  {
>  	long ioret;
> -	uint64_t status = ~0ULL;
> +	static uint64_t status;
>  
> +	status = ~0ULL;
>  	settime->status = &status;
>  
>  	ioret = ioctl(fd, EFI_RUNTIME_SET_TIME, settime);
> @@ -648,7 +649,9 @@ static int uefirttime_test_getwaketime_invalid(
>  	struct efi_getwakeuptime *getwakeuptime)
>  {
>  	long ioret;
> -	uint64_t status = ~0ULL;
> +	static uint64_t status;
> +
> +	status = ~0ULL;
>  	getwakeuptime->status = &status;
>  
>  	ioret = ioctl(fd, EFI_RUNTIME_GET_WAKETIME, getwakeuptime);
> @@ -854,8 +857,9 @@ static int uefirttime_test_setwakeuptime_invalid(
>  )
>  {
>  	long ioret;
> -	uint64_t status = ~0ULL;
> +	static uint64_t status;
>  
> +	status = ~0ULL;
>  	setwakeuptime->status = &status;
>  
>  	ioret = ioctl(fd, EFI_RUNTIME_SET_WAKETIME, setwakeuptime);
> 


Acked-by: Alex Hung <alex.hung@canonical.com>
Ivan Hu June 12, 2019, 3:42 a.m. UTC | #2
On 6/11/19 5:28 PM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Using an auto-variable (declared on the stack) for the status
> is problematic because we return the address of this variable
> back to the callee via a function parameter. Thus there is a
> potential of the callee referencing the now dead stack variable.
> Although this is not actually referenced later, it's worth just
> cleaning this up by making the variable static so we avoid any
> potential risk in the future.  Cleans up 3 cppcheck warnings
> of the kind:
>
> "(error) Address of local auto-variable assigned to a function parameter."
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/uefi/uefirttime/uefirttime.c | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
>
> diff --git a/src/uefi/uefirttime/uefirttime.c b/src/uefi/uefirttime/uefirttime.c
> index 7626f06e..647bd5a7 100644
> --- a/src/uefi/uefirttime/uefirttime.c
> +++ b/src/uefi/uefirttime/uefirttime.c
> @@ -401,8 +401,9 @@ static int uefirttime_test_settime_invalid(
>  	struct efi_settime *settime)
>  {
>  	long ioret;
> -	uint64_t status = ~0ULL;
> +	static uint64_t status;
>  
> +	status = ~0ULL;
>  	settime->status = &status;
>  
>  	ioret = ioctl(fd, EFI_RUNTIME_SET_TIME, settime);
> @@ -648,7 +649,9 @@ static int uefirttime_test_getwaketime_invalid(
>  	struct efi_getwakeuptime *getwakeuptime)
>  {
>  	long ioret;
> -	uint64_t status = ~0ULL;
> +	static uint64_t status;
> +
> +	status = ~0ULL;
>  	getwakeuptime->status = &status;
>  
>  	ioret = ioctl(fd, EFI_RUNTIME_GET_WAKETIME, getwakeuptime);
> @@ -854,8 +857,9 @@ static int uefirttime_test_setwakeuptime_invalid(
>  )
>  {
>  	long ioret;
> -	uint64_t status = ~0ULL;
> +	static uint64_t status;
>  
> +	status = ~0ULL;
>  	setwakeuptime->status = &status;
>  
>  	ioret = ioctl(fd, EFI_RUNTIME_SET_WAKETIME, setwakeuptime);


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

Patch

diff --git a/src/uefi/uefirttime/uefirttime.c b/src/uefi/uefirttime/uefirttime.c
index 7626f06e..647bd5a7 100644
--- a/src/uefi/uefirttime/uefirttime.c
+++ b/src/uefi/uefirttime/uefirttime.c
@@ -401,8 +401,9 @@  static int uefirttime_test_settime_invalid(
 	struct efi_settime *settime)
 {
 	long ioret;
-	uint64_t status = ~0ULL;
+	static uint64_t status;
 
+	status = ~0ULL;
 	settime->status = &status;
 
 	ioret = ioctl(fd, EFI_RUNTIME_SET_TIME, settime);
@@ -648,7 +649,9 @@  static int uefirttime_test_getwaketime_invalid(
 	struct efi_getwakeuptime *getwakeuptime)
 {
 	long ioret;
-	uint64_t status = ~0ULL;
+	static uint64_t status;
+
+	status = ~0ULL;
 	getwakeuptime->status = &status;
 
 	ioret = ioctl(fd, EFI_RUNTIME_GET_WAKETIME, getwakeuptime);
@@ -854,8 +857,9 @@  static int uefirttime_test_setwakeuptime_invalid(
 )
 {
 	long ioret;
-	uint64_t status = ~0ULL;
+	static uint64_t status;
 
+	status = ~0ULL;
 	setwakeuptime->status = &status;
 
 	ioret = ioctl(fd, EFI_RUNTIME_SET_WAKETIME, setwakeuptime);