public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* samsung-galaxybook writes to a int via a u8*
@ 2025-12-28 11:55 Gianni Ceccarelli
  2025-12-28 20:16 ` Armin Wolf
  0 siblings, 1 reply; 4+ messages in thread
From: Gianni Ceccarelli @ 2025-12-28 11:55 UTC (permalink / raw)
  To: Joshua Grisham; +Cc: platform-driver-x86, linux-kernel

https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/drivers/platform/x86/samsung-galaxybook.c#n450

`val->intval` is an int (see
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/include/linux/power_supply.h#n228
), so writing to it via a `u8*` produces weird results, for example:

    $ cat /sys/class/power_supply/BAT1/charge_control_end_threshold
    78497792
    $ grep END_THRESHOLD /sys/class/power_supply/BAT1/uevent
    POWER_SUPPLY_CHARGE_CONTROL_END_THRESHOLD=-962691840

The least-significant byte of numbers values contains the expected
value:

    $ perl -E 'say 78497792 & 0xFF'
    0
    $ perl -E 'say -962691840 & 0xFF'
    0

even after changing the threshold:
    
    # echo 90 >
/sys/class/power_supply/BAT1/charge_control_end_threshold $ cat
/sys/class/power_supply/BAT1/charge_control_end_threshold 78497882
    $ grep END_THRESHOLD /sys/class/power_supply/BAT1/uevent
    POWER_SUPPLY_CHARGE_CONTROL_END_THRESHOLD=-966918822
    $ perl -E 'say 78497882 & 0xFF'
    90
    $ perl -E 'say -966918822 & 0xFF'
    90

I guess the code could be changed to:

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

Hope this helps.

-- 
	Dakkar - <Mobilis in mobile>
	GPG public key fingerprint = A071 E618 DD2C 5901 9574
	                             6FE2 40EA 9883 7519 3F88
	                    key id = 0x75193F88


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-12-28 21:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-28 11:55 samsung-galaxybook writes to a int via a u8* Gianni Ceccarelli
2025-12-28 20:16 ` Armin Wolf
2025-12-28 21:06   ` Gianni Ceccarelli
2025-12-28 21:50     ` Armin Wolf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox