* [PATCH] asus-laptop: Fix an uninitialized variable
@ 2025-03-25 9:57 Denis Arefev
2025-03-25 11:18 ` Ilpo Järvinen
0 siblings, 1 reply; 5+ messages in thread
From: Denis Arefev @ 2025-03-25 9:57 UTC (permalink / raw)
To: Corentin Chary
Cc: Luke D. Jones, Hans de Goede, Ilpo Järvinen,
platform-driver-x86, linux-kernel, lvc-project, stable
The value returned by the acpi_evaluate_integer() function is not
checked, but the result is not always successful, so an uninitialized
'val' variable may be used in calculations.
Found by Linux Verification Center (linuxtesting.org) with SVACE.
Fixes: b23910c2194e ("asus-laptop: Pegatron Lucid accelerometer")
Cc: stable@vger.kernel.org
Signed-off-by: Denis Arefev <arefev@swemel.ru>
---
drivers/platform/x86/asus-laptop.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/platform/x86/asus-laptop.c b/drivers/platform/x86/asus-laptop.c
index d460dd194f19..b74b7d0eb6c2 100644
--- a/drivers/platform/x86/asus-laptop.c
+++ b/drivers/platform/x86/asus-laptop.c
@@ -427,7 +427,7 @@ static int asus_pega_lucid_set(struct asus_laptop *asus, int unit, bool enable)
static int pega_acc_axis(struct asus_laptop *asus, int curr, char *method)
{
int i, delta;
- unsigned long long val;
+ unsigned long long val = PEGA_ACC_CLAMP;
for (i = 0; i < PEGA_ACC_RETRIES; i++) {
acpi_evaluate_integer(asus->handle, method, NULL, &val);
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] asus-laptop: Fix an uninitialized variable
2025-03-25 9:57 [PATCH] asus-laptop: Fix an uninitialized variable Denis Arefev
@ 2025-03-25 11:18 ` Ilpo Järvinen
2025-03-26 12:07 ` Arefev
0 siblings, 1 reply; 5+ messages in thread
From: Ilpo Järvinen @ 2025-03-25 11:18 UTC (permalink / raw)
To: Denis Arefev
Cc: Corentin Chary, Luke D. Jones, Hans de Goede, platform-driver-x86,
LKML, lvc-project, stable
On Tue, 25 Mar 2025, Denis Arefev wrote:
> The value returned by the acpi_evaluate_integer() function is not
> checked, but the result is not always successful, so an uninitialized
> 'val' variable may be used in calculations.
>
> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>
> Fixes: b23910c2194e ("asus-laptop: Pegatron Lucid accelerometer")
> Cc: stable@vger.kernel.org
> Signed-off-by: Denis Arefev <arefev@swemel.ru>
> ---
> drivers/platform/x86/asus-laptop.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/platform/x86/asus-laptop.c b/drivers/platform/x86/asus-laptop.c
> index d460dd194f19..b74b7d0eb6c2 100644
> --- a/drivers/platform/x86/asus-laptop.c
> +++ b/drivers/platform/x86/asus-laptop.c
> @@ -427,7 +427,7 @@ static int asus_pega_lucid_set(struct asus_laptop *asus, int unit, bool enable)
> static int pega_acc_axis(struct asus_laptop *asus, int curr, char *method)
> {
> int i, delta;
> - unsigned long long val;
> + unsigned long long val = PEGA_ACC_CLAMP;
> for (i = 0; i < PEGA_ACC_RETRIES; i++) {
> acpi_evaluate_integer(asus->handle, method, NULL, &val);
Shouldn't you handle the error from acpi_evaluate_integer() properly
instead?
--
i.
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] asus-laptop: Fix an uninitialized variable
2025-03-25 11:18 ` Ilpo Järvinen
@ 2025-03-26 12:07 ` Arefev
2025-03-28 13:53 ` Ilpo Järvinen
0 siblings, 1 reply; 5+ messages in thread
From: Arefev @ 2025-03-26 12:07 UTC (permalink / raw)
To: Ilpo Järvinen
Cc: Corentin Chary, Luke D. Jones, Hans de Goede, platform-driver-x86,
linux-kernel, lvc-project
25.03.2025 14:18, Ilpo Järvinen пишет:
> On Tue, 25 Mar 2025, Denis Arefev wrote:
>
>> The value returned by the acpi_evaluate_integer() function is not
>> checked, but the result is not always successful, so an uninitialized
>> 'val' variable may be used in calculations.
>>
>> Found by Linux Verification Center (linuxtesting.org) with SVACE.
>>
>> Fixes: b23910c2194e ("asus-laptop: Pegatron Lucid accelerometer")
>> Cc: stable@vger.kernel.org
>> Signed-off-by: Denis Arefev <arefev@swemel.ru>
>> ---
>> drivers/platform/x86/asus-laptop.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/platform/x86/asus-laptop.c b/drivers/platform/x86/asus-laptop.c
>> index d460dd194f19..b74b7d0eb6c2 100644
>> --- a/drivers/platform/x86/asus-laptop.c
>> +++ b/drivers/platform/x86/asus-laptop.c
>> @@ -427,7 +427,7 @@ static int asus_pega_lucid_set(struct asus_laptop *asus, int unit, bool enable)
>> static int pega_acc_axis(struct asus_laptop *asus, int curr, char *method)
>> {
>> int i, delta;
>> - unsigned long long val;
>> + unsigned long long val = PEGA_ACC_CLAMP;
>> for (i = 0; i < PEGA_ACC_RETRIES; i++) {
>> acpi_evaluate_integer(asus->handle, method, NULL, &val);
> Shouldn't you handle the error from acpi_evaluate_integer() properly
> instead?
>
Apparently, the developer realized that the output is very noisy and
therefore created an algorithm that will surely return a good result.
I did not check the return value, because if acpi_evaluate_integer()
cannot read the values of accelerometers, 'val' will remain
uninitialized and will be used in further calculations.
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] asus-laptop: Fix an uninitialized variable
2025-03-26 12:07 ` Arefev
@ 2025-03-28 13:53 ` Ilpo Järvinen
2025-04-03 12:23 ` Denis Arefev
0 siblings, 1 reply; 5+ messages in thread
From: Ilpo Järvinen @ 2025-03-28 13:53 UTC (permalink / raw)
To: Arefev
Cc: Corentin Chary, Luke D. Jones, Hans de Goede, platform-driver-x86,
LKML, lvc-project
[-- Attachment #1: Type: text/plain, Size: 2229 bytes --]
On Wed, 26 Mar 2025, Arefev wrote:
> 25.03.2025 14:18, Ilpo Järvinen пишет:
> > On Tue, 25 Mar 2025, Denis Arefev wrote:
> >
> > > The value returned by the acpi_evaluate_integer() function is not
> > > checked, but the result is not always successful, so an uninitialized
> > > 'val' variable may be used in calculations.
> > >
> > > Found by Linux Verification Center (linuxtesting.org) with SVACE.
> > >
> > > Fixes: b23910c2194e ("asus-laptop: Pegatron Lucid accelerometer")
> > > Cc: stable@vger.kernel.org
> > > Signed-off-by: Denis Arefev <arefev@swemel.ru>
> > > ---
> > > drivers/platform/x86/asus-laptop.c | 2 +-
> > > 1 file changed, 1 insertion(+), 1 deletion(-)
> > >
> > > diff --git a/drivers/platform/x86/asus-laptop.c
> > > b/drivers/platform/x86/asus-laptop.c
> > > index d460dd194f19..b74b7d0eb6c2 100644
> > > --- a/drivers/platform/x86/asus-laptop.c
> > > +++ b/drivers/platform/x86/asus-laptop.c
> > > @@ -427,7 +427,7 @@ static int asus_pega_lucid_set(struct asus_laptop
> > > *asus, int unit, bool enable)
> > > static int pega_acc_axis(struct asus_laptop *asus, int curr, char
> > > *method)
> > > {
> > > int i, delta;
> > > - unsigned long long val;
> > > + unsigned long long val = PEGA_ACC_CLAMP;
> > > for (i = 0; i < PEGA_ACC_RETRIES; i++) {
> > > acpi_evaluate_integer(asus->handle, method, NULL, &val);
> > Shouldn't you handle the error from acpi_evaluate_integer() properly
> > instead?
> >
> Apparently, the developer realized that the output is very noisy and
> therefore created an algorithm that will surely return a good result.
>
> I did not check the return value, because if acpi_evaluate_integer()
> cannot read the values of accelerometers, 'val' will remain
> uninitialized and will be used in further calculations.
But if ACPI doesn't provide a value, why should that clamp value be used
instead? I'd tend to think curr would be more suitable "default".
But shouldn't the loop either use continue to retry or the function
return curr right away if acpi_evaluate_integer() returns an error?
I just don't see how your patch improves situation here despite silencing
the checker tool.
--
i.
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: [PATCH] asus-laptop: Fix an uninitialized variable
2025-03-28 13:53 ` Ilpo Järvinen
@ 2025-04-03 12:23 ` Denis Arefev
0 siblings, 0 replies; 5+ messages in thread
From: Denis Arefev @ 2025-04-03 12:23 UTC (permalink / raw)
To: ilpo.jarvinen
Cc: arefev, corentin.chary, hdegoede, linux-kernel, luke, lvc-project,
platform-driver-x86
> But if ACPI doesn't provide a value, why should that clamp value be used
> instead? I'd tend to think curr would be more suitable "default".
> But shouldn't the loop either use continue to retry or the function
> return curr right away if acpi_evaluate_integer() returns an error?
Hi Ilpo.
I'm sorry it took me so long to respond.
Yes, your comments are correct.
I hope the new patch will help to make the algorithm less noisy.
Regards Denis.
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-04-03 12:23 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-25 9:57 [PATCH] asus-laptop: Fix an uninitialized variable Denis Arefev
2025-03-25 11:18 ` Ilpo Järvinen
2025-03-26 12:07 ` Arefev
2025-03-28 13:53 ` Ilpo Järvinen
2025-04-03 12:23 ` Denis Arefev
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox