Linux Kernel Selftest development
 help / color / mirror / Atom feed
* [PATCH] kselftest: vDSO: Fix accumulation of uninitialized ret when CLOCK_REALTIME is undefined
@ 2023-04-17 10:47 Colin Ian King
  2023-04-18 10:10 ` Vincenzo Frascino
  0 siblings, 1 reply; 4+ messages in thread
From: Colin Ian King @ 2023-04-17 10:47 UTC (permalink / raw)
  To: Shuah Khan, Thomas Gleixner, Vincenzo Frascino, linux-kselftest
  Cc: kernel-janitors, linux-kernel

In the unlikely case that CLOCK_REALTIME is not defined, variable ret is
not initialized and further accumulation of return values to ret can leave
ret in an undefined state. Fix this by initialized ret to zero and changing
the assignment of ret to an accumulation for the CLOCK_REALTIME case.

Fixes: 03f55c7952c9 ("kselftest: Extend vDSO selftest to clock_getres")
Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
---
 tools/testing/selftests/vDSO/vdso_test_clock_getres.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/vDSO/vdso_test_clock_getres.c b/tools/testing/selftests/vDSO/vdso_test_clock_getres.c
index 15dcee16ff72..38d46a8bf7cb 100644
--- a/tools/testing/selftests/vDSO/vdso_test_clock_getres.c
+++ b/tools/testing/selftests/vDSO/vdso_test_clock_getres.c
@@ -84,12 +84,12 @@ static inline int vdso_test_clock(unsigned int clock_id)
 
 int main(int argc, char **argv)
 {
-	int ret;
+	int ret = 0;
 
 #if _POSIX_TIMERS > 0
 
 #ifdef CLOCK_REALTIME
-	ret = vdso_test_clock(CLOCK_REALTIME);
+	ret += vdso_test_clock(CLOCK_REALTIME);
 #endif
 
 #ifdef CLOCK_BOOTTIME
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] kselftest: vDSO: Fix accumulation of uninitialized ret when CLOCK_REALTIME is undefined
  2023-04-17 10:47 [PATCH] kselftest: vDSO: Fix accumulation of uninitialized ret when CLOCK_REALTIME is undefined Colin Ian King
@ 2023-04-18 10:10 ` Vincenzo Frascino
  2023-04-18 10:14   ` Colin King (gmail)
  0 siblings, 1 reply; 4+ messages in thread
From: Vincenzo Frascino @ 2023-04-18 10:10 UTC (permalink / raw)
  To: Colin Ian King, Shuah Khan, Thomas Gleixner, linux-kselftest
  Cc: kernel-janitors, linux-kernel

Hi Colin,

On 4/17/23 11:47, Colin Ian King wrote:
> In the unlikely case that CLOCK_REALTIME is not defined, variable ret is
> not initialized and further accumulation of return values to ret can leave
> ret in an undefined state. Fix this by initialized ret to zero and changing
> the assignment of ret to an accumulation for the CLOCK_REALTIME case.
> 

I was wondering how did you find this.

Apart that:

Reviewed-by: Vincenzo Frascino <vincenzo.frascino@arm.com>

> Fixes: 03f55c7952c9 ("kselftest: Extend vDSO selftest to clock_getres")
> Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
> ---
>  tools/testing/selftests/vDSO/vdso_test_clock_getres.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/testing/selftests/vDSO/vdso_test_clock_getres.c b/tools/testing/selftests/vDSO/vdso_test_clock_getres.c
> index 15dcee16ff72..38d46a8bf7cb 100644
> --- a/tools/testing/selftests/vDSO/vdso_test_clock_getres.c
> +++ b/tools/testing/selftests/vDSO/vdso_test_clock_getres.c
> @@ -84,12 +84,12 @@ static inline int vdso_test_clock(unsigned int clock_id)
>  
>  int main(int argc, char **argv)
>  {
> -	int ret;
> +	int ret = 0;
>  
>  #if _POSIX_TIMERS > 0
>  
>  #ifdef CLOCK_REALTIME
> -	ret = vdso_test_clock(CLOCK_REALTIME);
> +	ret += vdso_test_clock(CLOCK_REALTIME);
>  #endif
>  
>  #ifdef CLOCK_BOOTTIME

-- 
Regards,
Vincenzo

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] kselftest: vDSO: Fix accumulation of uninitialized ret when CLOCK_REALTIME is undefined
  2023-04-18 10:10 ` Vincenzo Frascino
@ 2023-04-18 10:14   ` Colin King (gmail)
  2023-05-08 17:37     ` Shuah Khan
  0 siblings, 1 reply; 4+ messages in thread
From: Colin King (gmail) @ 2023-04-18 10:14 UTC (permalink / raw)
  To: Vincenzo Frascino, Shuah Khan, Thomas Gleixner, linux-kselftest
  Cc: kernel-janitors, linux-kernel

On 18/04/2023 11:10, Vincenzo Frascino wrote:
> Hi Colin,
> 
> On 4/17/23 11:47, Colin Ian King wrote:
>> In the unlikely case that CLOCK_REALTIME is not defined, variable ret is
>> not initialized and further accumulation of return values to ret can leave
>> ret in an undefined state. Fix this by initialized ret to zero and changing
>> the assignment of ret to an accumulation for the CLOCK_REALTIME case.
>>
> 
> I was wondering how did you find this.

I used cppcheck --force --enable=all, this examines the #if defined() paths.

> 
> Apart that:
> 
> Reviewed-by: Vincenzo Frascino <vincenzo.frascino@arm.com>
> 
>> Fixes: 03f55c7952c9 ("kselftest: Extend vDSO selftest to clock_getres")
>> Signed-off-by: Colin Ian King <colin.i.king@gmail.com>
>> ---
>>   tools/testing/selftests/vDSO/vdso_test_clock_getres.c | 4 ++--
>>   1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/tools/testing/selftests/vDSO/vdso_test_clock_getres.c b/tools/testing/selftests/vDSO/vdso_test_clock_getres.c
>> index 15dcee16ff72..38d46a8bf7cb 100644
>> --- a/tools/testing/selftests/vDSO/vdso_test_clock_getres.c
>> +++ b/tools/testing/selftests/vDSO/vdso_test_clock_getres.c
>> @@ -84,12 +84,12 @@ static inline int vdso_test_clock(unsigned int clock_id)
>>   
>>   int main(int argc, char **argv)
>>   {
>> -	int ret;
>> +	int ret = 0;
>>   
>>   #if _POSIX_TIMERS > 0
>>   
>>   #ifdef CLOCK_REALTIME
>> -	ret = vdso_test_clock(CLOCK_REALTIME);
>> +	ret += vdso_test_clock(CLOCK_REALTIME);
>>   #endif
>>   
>>   #ifdef CLOCK_BOOTTIME
> 


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] kselftest: vDSO: Fix accumulation of uninitialized ret when CLOCK_REALTIME is undefined
  2023-04-18 10:14   ` Colin King (gmail)
@ 2023-05-08 17:37     ` Shuah Khan
  0 siblings, 0 replies; 4+ messages in thread
From: Shuah Khan @ 2023-05-08 17:37 UTC (permalink / raw)
  To: Colin King (gmail), Vincenzo Frascino, Shuah Khan,
	Thomas Gleixner, linux-kselftest
  Cc: kernel-janitors, linux-kernel, Shuah Khan

On 4/18/23 04:14, Colin King (gmail) wrote:
> On 18/04/2023 11:10, Vincenzo Frascino wrote:
>> Hi Colin,
>>
>> On 4/17/23 11:47, Colin Ian King wrote:
>>> In the unlikely case that CLOCK_REALTIME is not defined, variable ret is
>>> not initialized and further accumulation of return values to ret can leave
>>> ret in an undefined state. Fix this by initialized ret to zero and changing
>>> the assignment of ret to an accumulation for the CLOCK_REALTIME case.
>>>
>>
>> I was wondering how did you find this.
> 
> I used cppcheck --force --enable=all, this examines the #if defined() paths.
> 
>>
>> Apart that:
>>
>> Reviewed-by: Vincenzo Frascino <vincenzo.frascino@arm.com>
>>

Applied to linux-kselftest next

thanks,
-- Shuah


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-05-08 17:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-17 10:47 [PATCH] kselftest: vDSO: Fix accumulation of uninitialized ret when CLOCK_REALTIME is undefined Colin Ian King
2023-04-18 10:10 ` Vincenzo Frascino
2023-04-18 10:14   ` Colin King (gmail)
2023-05-08 17:37     ` Shuah Khan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox