Skip to content

Commit d37cd54

Browse files
Wer-Wolfij-intel
authored andcommitted
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: 56f529c ("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>
1 parent 00c22b1 commit d37cd54

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

drivers/platform/x86/samsung-galaxybook.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -442,21 +442,24 @@ static int galaxybook_battery_ext_property_get(struct power_supply *psy,
442442
union power_supply_propval *val)
443443
{
444444
struct samsung_galaxybook *galaxybook = ext_data;
445+
u8 value;
445446
int err;
446447

447448
if (psp != POWER_SUPPLY_PROP_CHARGE_CONTROL_END_THRESHOLD)
448449
return -EINVAL;
449450

450-
err = charge_control_end_threshold_acpi_get(galaxybook, (u8 *)&val->intval);
451+
err = charge_control_end_threshold_acpi_get(galaxybook, &value);
451452
if (err)
452453
return err;
453454

454455
/*
455456
* device stores "no end threshold" as 0 instead of 100;
456457
* if device has 0, report 100
457458
*/
458-
if (val->intval == 0)
459-
val->intval = 100;
459+
if (value == 0)
460+
value = 100;
461+
462+
val->intval = value;
460463

461464
return 0;
462465
}

0 commit comments

Comments
 (0)