#define MAX_CDEV_NAME_LEN 16
 
+#define MAX_ASPEED_FAN_TACH_CHANNELS 16
+
 struct aspeed_cooling_device {
        char name[16];
        struct aspeed_pwm_tacho_data *priv;
        struct reset_control *rst;
        unsigned long clk_freq;
        bool pwm_present[8];
-       bool fan_tach_present[16];
+       bool fan_tach_present[MAX_ASPEED_FAN_TACH_CHANNELS];
        u8 type_pwm_clock_unit[3];
        u8 type_pwm_clock_division_h[3];
        u8 type_pwm_clock_division_l[3];
        u16 type_fan_tach_unit[3];
        u8 pwm_port_type[8];
        u8 pwm_port_fan_ctrl[8];
-       u8 fan_tach_ch_source[16];
+       u8 fan_tach_ch_source[MAX_ASPEED_FAN_TACH_CHANNELS];
        struct aspeed_cooling_device *cdev[8];
        const struct attribute_group *groups[3];
 };
        aspeed_set_pwm_port_fan_ctrl(priv, pwm_port, INIT_FAN_CTRL);
 }
 
-static void aspeed_create_fan_tach_channel(struct aspeed_pwm_tacho_data *priv,
-                                          u8 *fan_tach_ch,
-                                          int count,
-                                          u8 pwm_source)
+static int aspeed_create_fan_tach_channel(struct device *dev,
+                                         struct aspeed_pwm_tacho_data *priv,
+                                         u8 *fan_tach_ch,
+                                         int count,
+                                         u8 pwm_source)
 {
        u8 val, index;
 
        for (val = 0; val < count; val++) {
                index = fan_tach_ch[val];
+               if (index >= MAX_ASPEED_FAN_TACH_CHANNELS) {
+                       dev_err(dev, "Invalid Fan Tach input channel %u\n.", index);
+                       return -EINVAL;
+               }
                aspeed_set_fan_tach_ch_enable(priv->regmap, index, true);
                priv->fan_tach_present[index] = true;
                priv->fan_tach_ch_source[index] = pwm_source;
                aspeed_set_fan_tach_ch_source(priv->regmap, index, pwm_source);
        }
+
+       return 0;
 }
 
 static int
                                        fan_tach_ch, count);
        if (ret)
                return ret;
-       aspeed_create_fan_tach_channel(priv, fan_tach_ch, count, pwm_port);
+
+       ret = aspeed_create_fan_tach_channel(dev, priv, fan_tach_ch, count, pwm_port);
+       if (ret)
+               return ret;
 
        return 0;
 }