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

platform/x86: samsung-galaxybook: Fix problematic pointer cast

A user reported that reading the charge threshold on his device
results in very strange values (like 78497792) being returned.
The reason for this seems to be the fact that the driver casts
the int pointer to an u8 pointer, leaving the last 3 bytes of
the destination uninitialized. Fix this by using a temporary
variable instead.

Cc: stable@vger.kernel.org
Fixes: 56f529ce4370 ("platform/x86: samsung-galaxybook: Add samsung-galaxybook driver")
Reported-by: Gianni Ceccarelli <dakkar@thenautilus.net>
Closes: https://lore.kernel.org/platform-driver-x86/20251228115556.14362d66@thenautilus.net/
Tested-by: Gianni Ceccarelli <dakkar@thenautilus.net>
Signed-off-by: Armin Wolf <W_Armin@gmx.de>
Link: https://patch.msgid.link/20251228214217.35972-1-W_Armin@gmx.de
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

authored by

Armin Wolf and committed by
Ilpo Järvinen
d37cd54e 00c22b1e

+6 -3
+6 -3
drivers/platform/x86/samsung-galaxybook.c
··· 442 442 union power_supply_propval *val) 443 443 { 444 444 struct samsung_galaxybook *galaxybook = ext_data; 445 + u8 value; 445 446 int err; 446 447 447 448 if (psp != POWER_SUPPLY_PROP_CHARGE_CONTROL_END_THRESHOLD) 448 449 return -EINVAL; 449 450 450 - err = charge_control_end_threshold_acpi_get(galaxybook, (u8 *)&val->intval); 451 + err = charge_control_end_threshold_acpi_get(galaxybook, &value); 451 452 if (err) 452 453 return err; 453 454 ··· 456 455 * device stores "no end threshold" as 0 instead of 100; 457 456 * if device has 0, report 100 458 457 */ 459 - if (val->intval == 0) 460 - val->intval = 100; 458 + if (value == 0) 459 + value = 100; 460 + 461 + val->intval = value; 461 462 462 463 return 0; 463 464 }