Pull hwmonfix from Guenter Roeck: "Fix crash seen when instantiating npcm750-pwm-fan" * tag 'hwmon-for-v6.8-p2' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging: hwmon: (npcm750-pwm-fan) Fix crash observed when instantiating nuvoton,npcm750-pwm-fan
Unified · Split
| @@ -195,6 +195,7 @@ struct npcm7xx_cooling_device { · 194 unmodified lines | ||
| 195 | 195 | struct npcm7xx_pwm_fan_data { |
| 196 | 196 | void __iomem *pwm_base; |
| 197 | 197 | void __iomem *fan_base; |
| 198 | + int pwm_modules; | |
| 198 | 199 | unsigned long pwm_clk_freq; |
| 199 | 200 | unsigned long fan_clk_freq; |
| 200 | 201 | struct clk *pwm_clk; |
| @@ -710,7 +711,7 @@ static u32 npcm7xx_pwm_init(struct npcm7xx_pwm_fan_data *data) · 509 unmodified lines | ||
| 710 | 711 | /* Setting PWM Prescale Register value register to both modules */ |
| 711 | 712 | prescale_val |= (prescale_val << NPCM7XX_PWM_PRESCALE_SHIFT_CH01); |
| 712 | 713 | |
| 713 | − for (m = 0; m < NPCM7XX_PWM_MAX_MODULES ; m++) { | |
| 714 | + for (m = 0; m < data->pwm_modules; m++) { | |
| 714 | 715 | iowrite32(prescale_val, NPCM7XX_PWM_REG_PR(data->pwm_base, m)); |
| 715 | 716 | iowrite32(NPCM7XX_PWM_PRESCALE2_DEFAULT, |
| 716 | 717 | NPCM7XX_PWM_REG_CSR(data->pwm_base, m)); |
| @@ -946,6 +947,8 @@ static int npcm7xx_pwm_fan_probe(struct platform_device *pdev) · 229 unmodified lines | ||
| 946 | 947 | if (!data->info) |
| 947 | 948 | return -EINVAL; |
| 948 | 949 | |
| 950 | + data->pwm_modules = data->info->pwm_max_channel / NPCM7XX_PWM_MAX_CHN_NUM_IN_A_MODULE; | |
| 951 | + | |
| 949 | 952 | res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pwm"); |
| 950 | 953 | if (!res) { |
| 951 | 954 | dev_err(dev, "pwm resource not found\n"); |
| @@ -983,7 +986,7 @@ static int npcm7xx_pwm_fan_probe(struct platform_device *pdev) · 31 unmodified lines | ||
| 983 | 986 | output_freq = npcm7xx_pwm_init(data); |
| 984 | 987 | npcm7xx_fan_init(data); |
| 985 | 988 | |
| 986 | − for (cnt = 0; cnt < NPCM7XX_PWM_MAX_MODULES ; cnt++) | |
| 989 | + for (cnt = 0; cnt < data->pwm_modules; cnt++) | |
| 987 | 990 | mutex_init(&data->pwm_lock[cnt]); |
| 988 | 991 | |
| 989 | 992 | for (i = 0; i < NPCM7XX_FAN_MAX_MODULE; i++) { |