• Guenter Roeck's avatar
    hwmon: (npcm750-pwm-fan) Fix crash observed when instantiating nuvoton,npcm750-pwm-fan · 2539b15d
    Guenter Roeck authored
    Commit 89fec128 ("hwmon: (npcm750-pwm-fan) Add NPCM8xx support")
    introduced support for PWM fans on Nuvoton's npcm845 SoC. This chip
    supports three PWM modules with four PWM channels each. The older npcm750
    only supported two PWM modules. The commit did not take into account that
    the older SoC only supported two PWM modules. This results in a crash if
    npcm750 is instantiated when the code attempts to instantiate the
    non-existing third PWM module.
    
    Unable to handle kernel paging request at virtual address e0aa2000 when write
    [e0aa2000] *pgd=04ab6811, *pte=00000000, *ppte=00000000
    Internal error: Oops: 807 [#1] SMP ARM
    Modules linked in:
    CPU: 0 PID: 1 Comm: swapper/0 Tainted: G                 N 6.7.0-next-20240112-dirty #3
    Hardware name: NPCM7XX Chip family
    PC is at npcm7xx_pwm_fan_probe+0x204/0x890
    LR is at arm_heavy_mb+0x1c/0x38
    
    Fix the problem by detecting the number of supported PWM modules in the
    probe function and only instantiating the supported modules.
    
    Fixes: 89fec128 ("hwmon: (npcm750-pwm-fan) Add NPCM8xx support")
    Cc: Tomer Maimon <tmaimon77@gmail.com>
    Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
    2539b15d
npcm750-pwm-fan.c 29.2 KB