Unverified Commit d37cd54e authored by Armin Wolf's avatar Armin Wolf Committed by Ilpo Järvinen
Browse files

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: 56f529ce ("platform/x86: samsung-galaxybook: Add samsung-galaxybook driver")
Reported-by: default avatarGianni Ceccarelli <dakkar@thenautilus.net>
Closes: https://lore.kernel.org/platform-driver-x86/20251228115556.14362d66@thenautilus.net/


Tested-by: default avatarGianni Ceccarelli <dakkar@thenautilus.net>
Signed-off-by: default avatarArmin Wolf <W_Armin@gmx.de>
Link: https://patch.msgid.link/20251228214217.35972-1-W_Armin@gmx.de


Reviewed-by: default avatarIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: default avatarIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
parent 00c22b1e
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -442,12 +442,13 @@ static int galaxybook_battery_ext_property_get(struct power_supply *psy,
					       union power_supply_propval *val)
{
	struct samsung_galaxybook *galaxybook = ext_data;
	u8 value;
	int err;

	if (psp != POWER_SUPPLY_PROP_CHARGE_CONTROL_END_THRESHOLD)
		return -EINVAL;

	err = charge_control_end_threshold_acpi_get(galaxybook, (u8 *)&val->intval);
	err = charge_control_end_threshold_acpi_get(galaxybook, &value);
	if (err)
		return err;

@@ -455,8 +456,10 @@ static int galaxybook_battery_ext_property_get(struct power_supply *psy,
	 * device stores "no end threshold" as 0 instead of 100;
	 * if device has 0, report 100
	 */
	if (val->intval == 0)
		val->intval = 100;
	if (value == 0)
		value = 100;

	val->intval = value;

	return 0;
}