Add support for Lenovo Legion Slim 5 16AHP9 (NRCN) and fix legiond segfault#377
Merged
st0nie merged 2 commits intojohnfanv2:mainfrom Dec 19, 2025
Merged
Conversation
- Added model_nrcn configuration for Legion Slim 5 16AHP9 - Model: 83DH with BIOS NRCN17WW - CPU: AMD Ryzen 7 8845HS - EC Chip ID: 0x8227, Version: 0x2a4 - Tested and confirmed working: * Temperature monitoring (CPU, GPU via WMI3) * Fan speed monitoring (1900-3500+ RPM observed) * Automatic BIOS fan control * Power mode switching * All toggle features (G-Sync, Overdrive, keyboard backlight) - Known limitations: * Manual fan control not supported (BIOS-locked by design) * Fan curve reading/writing not available * This is expected hardware behavior for this model Closes johnfanv2#218
- Added NULL check after fopen() for AC power status paths - Added NULL check after fopen() for power profile path - Prevents segfault when sysfs files don't exist or can't be opened - Fixes crash on startup when timer_handler calls get_powerstate() The daemon was crashing because fscanf() was being called on NULL file pointers when both /sys/class/power_supply/ADP0/online and /sys/class/power_supply/ACAD/online didn't exist.
|
Hi Hashim, and thanks for the patch! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds support for the Lenovo Legion Slim 5 16AHP9 (BIOS: NRCN) and fixes a critical segmentation fault in the
legionddaemon caused by NULL pointer dereference when reading power supply status.Changes
1. Add Legion Slim 5 16AHP9 Support
Commit:
46939a7File:
kernel_module/legion-laptop.cAdds
model_nrcnconfiguration for Legion Slim 5 16AHP9 (Model 83DH).Hardware Details:
Features Verified Working:
Known Hardware Limitations:
Closes: #218
2. Fix legiond Segmentation Fault
Commit:
66c1ba3File:
extra/service/legiond/modules/powerstate.cFixed NULL pointer dereference in
get_powerstate()causing immediate daemon crash on startup.Problem:
The function called
fscanf()on NULL file pointers when AC power supply paths failed to open. This occurred when both/sys/class/power_supply/ADP0/onlineand/sys/class/power_supply/ACAD/onlinedon't exist on the system.Stack trace of crash:
Process legiond (PID 101198) dumped core
#0 0x00007fad7a4423fb __vfscanf_internal (libc.so.6 + 0x423fb)
#1 0x00007fad7a435d3f __isoc99_fscanf (libc.so.6 + 0x35d3f)
#2 0x0000000000401f86 get_powerstate (/usr/bin/legiond + 0x1f86)
#3 0x00000000004025eb timer_handler (/usr/bin/legiond + 0x25eb)
Solution:
// Added NULL check after fopen attempts
fp = fopen(ac_path, "r");
if (fp == NULL)
fp = fopen(ac_path_alt, "r");
+if (fp == NULL) {
printf("failed to open AC power status file\n");
return P_ERROR_AC;
+}
// Similar checks added for platform_profile path