Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

asus-laptop: Fix an uninitialized variable

The value returned by acpi_evaluate_integer() is not checked,
but the result is not always successful, so it is necessary to
add a check of the returned value.

If the result remains negative during three iterations of the loop,
then the uninitialized variable 'val' will be used in the clamp_val()
macro, so it must be initialized with the current value of the 'curr'
variable.

In this case, the algorithm should be less noisy.

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>
Link: https://lore.kernel.org/r/20250403122603.18172-1-arefev@swemel.ru
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

authored by

Denis Arefev and committed by
Ilpo Järvinen
6c683c68 d8455a63

+6 -3
+6 -3
drivers/platform/x86/asus-laptop.c
··· 426 426 427 427 static int pega_acc_axis(struct asus_laptop *asus, int curr, char *method) 428 428 { 429 + unsigned long long val = (unsigned long long)curr; 430 + acpi_status status; 429 431 int i, delta; 430 - unsigned long long val; 431 - for (i = 0; i < PEGA_ACC_RETRIES; i++) { 432 - acpi_evaluate_integer(asus->handle, method, NULL, &val); 433 432 433 + for (i = 0; i < PEGA_ACC_RETRIES; i++) { 434 + status = acpi_evaluate_integer(asus->handle, method, NULL, &val); 435 + if (ACPI_FAILURE(status)) 436 + continue; 434 437 /* The output is noisy. From reading the ASL 435 438 * dissassembly, timeout errors are returned with 1's 436 439 * in the high word, and the lack of locking around