drivers/power/supply/bq25980_charger.c:1115 bq25980_hw_init() error: buffer overflow 'bq25980_watchdog_time' 4 <= 4
PATCH 70/78 drivers/power/supply/bq25980_charger.c:1115 bq25980_hw_init() error: buffer overflow 'bq25980_watchdog_time' 4 <= 4
tree: https://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply.git for-next head: 411643e949f4e616f758e2c6079f333b0e704c49 commit: 5069185fc18e810715a91d80fcd075e03add600c [70/78] power: supply: bq25980: Add support for the BQ259xx family config: i386-randconfig-m021-20201009 (attached as .config) compiler: gcc-9 (Debian 9.3.0-15) 9.3.0
If you fix the issue, kindly add following tag as appropriate
Reported-by kernel test robot <[email protected]>
Reported-by Dan Carpenter <[email protected]>
smatch warnings:drivers/power/supply/bq25980_charger.c:1115 bq25980_hw_init() error: buffer overflow 'bq25980_watchdog_time' 4 <= 4 drivers/power/supply/bq25980_charger.c:1122 bq25980_hw_init() error: uninitialized symbol 'wd_reg_val'.
vim +/bq25980_watchdog_time +1115 drivers/power/supply/bq25980_charger.c
5069185fc18e810 Dan Murphy 2020-08-31 1099 static int bq25980_hw_init(struct bq25980_device *bq)
5069185fc18e810 Dan Murphy 2020-08-31 1100 {
5069185fc18e810 Dan Murphy 2020-08-31 1101 struct power_supply_battery_info bat_info = { };
5069185fc18e810 Dan Murphy 2020-08-31 1102 int wd_reg_val;
5069185fc18e810 Dan Murphy 2020-08-31 1103 int ret = 0;
5069185fc18e810 Dan Murphy 2020-08-31 1104 int curr_val;
5069185fc18e810 Dan Murphy 2020-08-31 1105 int volt_val;
5069185fc18e810 Dan Murphy 2020-08-31 1106 int i;
5069185fc18e810 Dan Murphy 2020-08-31 1107
5069185fc18e810 Dan Murphy 2020-08-31 1108 if (!bq->watchdog_timer) {
5069185fc18e810 Dan Murphy 2020-08-31 1109 ret = regmap_update_bits(bq->regmap, BQ25980_CHRGR_CTRL_3,
5069185fc18e810 Dan Murphy 2020-08-31 1110 BQ25980_WATCHDOG_DIS,
5069185fc18e810 Dan Murphy 2020-08-31 1111 BQ25980_WATCHDOG_DIS);
5069185fc18e810 Dan Murphy 2020-08-31 1112 } else {
5069185fc18e810 Dan Murphy 2020-08-31 1113 for (i = 0; i < BQ25980_NUM_WD_VAL; i++) {
5069185fc18e810 Dan Murphy 2020-08-31 1114 if (bq->watchdog_timer > bq25980_watchdog_time[i] &&
5069185fc18e810 Dan Murphy 2020-08-31 @1115 bq->watchdog_timer < bq25980_watchdog_time[i + 1]) {
^^^^^Out of bounds on last iteration.
5069185fc18e810 Dan Murphy 2020-08-31 1116 wd_reg_val = i;
5069185fc18e810 Dan Murphy 2020-08-31 1117 break;
5069185fc18e810 Dan Murphy 2020-08-31 1118 }
5069185fc18e810 Dan Murphy 2020-08-31 1119 }
5069185fc18e810 Dan Murphy 2020-08-31 1120
5069185fc18e810 Dan Murphy 2020-08-31 1121 ret = regmap_update_bits(bq->regmap, BQ25980_CHRGR_CTRL_3,
5069185fc18e810 Dan Murphy 2020-08-31 @1122 BQ25980_WATCHDOG_MASK, wd_reg_val);
^^^^^^^^^^Uninitialized if we don't break from the loop.
5069185fc18e810 Dan Murphy 2020-08-31 1123 }
5069185fc18e810 Dan Murphy 2020-08-31 1124 if (ret)
5069185fc18e810 Dan Murphy 2020-08-31 1125 return ret;
5069185fc18e810 Dan Murphy 2020-08-31 1126
5069185fc18e810 Dan Murphy 2020-08-31 1127 ret = power_supply_get_battery_info(bq->charger, &bat_info);
5069185fc18e810 Dan Murphy 2020-08-31 1128 if (ret) {
5069185fc18e810 Dan Murphy 2020-08-31 1129 dev_warn(bq->dev, "battery info missing\n");
5069185fc18e810 Dan Murphy 2020-08-31 1130 return -EINVAL;
5069185fc18e810 Dan Murphy 2020-08-31 1131 }
5069185fc18e810 Dan Murphy 2020-08-31 1132
5069185fc18e810 Dan Murphy 2020-08-31 1133 bq->init_data.ichg_max = bat_info.constant_charge_current_max_ua;
5069185fc18e810 Dan Murphy 2020-08-31 1134 bq->init_data.vreg_max = bat_info.constant_charge_voltage_max_uv;
5069185fc18e810 Dan Murphy 2020-08-31 1135
5069185fc18e810 Dan Murphy 2020-08-31 1136 if (bq->state.bypass) {
5069185fc18e810 Dan Murphy 2020-08-31 1137 ret = regmap_update_bits(bq->regmap, BQ25980_CHRGR_CTRL_2,
5069185fc18e810 Dan Murphy 2020-08-31 1138 BQ25980_EN_BYPASS, BQ25980_EN_BYPASS);
5069185fc18e810 Dan Murphy 2020-08-31 1139 if (ret)
5069185fc18e810 Dan Murphy 2020-08-31 1140 return ret;
5069185fc18e810 Dan Murphy 2020-08-31 1141
5069185fc18e810 Dan Murphy 2020-08-31 1142 curr_val = bq->init_data.bypass_ilim;
5069185fc18e810 Dan Murphy 2020-08-31 1143 volt_val = bq->init_data.bypass_vlim;
5069185fc18e810 Dan Murphy 2020-08-31 1144 } else {
5069185fc18e810 Dan Murphy 2020-08-31 1145 curr_val = bq->init_data.sc_ilim;
5069185fc18e810 Dan Murphy 2020-08-31 1146 volt_val = bq->init_data.sc_vlim;
5069185fc18e810 Dan Murphy 2020-08-31 1147 }
5069185fc18e810 Dan Murphy 2020-08-31 1148
5069185fc18e810 Dan Murphy 2020-08-31 1149 ret = bq25980_set_input_curr_lim(bq, curr_val);
5069185fc18e810 Dan Murphy 2020-08-31 1150 if (ret)
5069185fc18e810 Dan Murphy 2020-08-31 1151 return ret;
5069185fc18e810 Dan Murphy 2020-08-31 1152
5069185fc18e810 Dan Murphy 2020-08-31 1153 ret = bq25980_set_input_volt_lim(bq, volt_val);
5069185fc18e810 Dan Murphy 2020-08-31 1154 if (ret)
5069185fc18e810 Dan Murphy 2020-08-31 1155 return ret;
5069185fc18e810 Dan Murphy 2020-08-31 1156
5069185fc18e810 Dan Murphy 2020-08-31 1157 return regmap_update_bits(bq->regmap, BQ25980_ADC_CONTROL1,
5069185fc18e810 Dan Murphy 2020-08-31 1158 BQ25980_ADC_EN, BQ25980_ADC_EN);
5069185fc18e810 Dan Murphy 2020-08-31 1159 }---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org