Re: [PATCH 2/2] hwmon: Driver for Texas Instruments INA238

Dan Carpenter
2021-11-03T14:53:20Z

Hi Nathan,

url: https://github.com/0day-ci/linux/commits/Nathan-Rossi/Driver-for-TI-INA238-I2C-Power-Monitor/20211025-105911
base: https://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging.git hwmon-next
config: x86_64-randconfig-m001-20211027 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>

smatch warnings:
drivers/hwmon/ina238.c:304 ina238_alert_store() error: uninitialized symbol 'regval'.

vim +/regval +304 drivers/hwmon/ina238.c

aafb1ad1e44aa2 Nathan Rossi 2021-10-25 243 static ssize_t ina238_alert_store(struct device *dev,
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 244 struct device_attribute *da,
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 245 const char *buf, size_t count)
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 246 {
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 247 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 248 struct ina238_data *data = dev_get_drvdata(dev);
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 249 long long val;
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 250 int regval;
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 251 int ret;
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 252
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 253 ret = kstrtoll(buf, 10, &val);
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 254 if (ret < 0)
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 255 return ret;
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 256
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 257 /* convert decimal to register value */
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 258 switch (attr->index) {
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 259 case INA238_SHUNT_OVER_VOLTAGE:
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 260 case INA238_SHUNT_UNDER_VOLTAGE:
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 261 /* signed */
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 262 regval = div_s64((val * 1000), INA238_SHUNT_VOLTAGE_LSB);
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 263 if (regval > S16_MAX || regval < S16_MIN) {
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 264 ret = -EINVAL;
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 265 goto abort;
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 266 }
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 267 break;
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 268 case INA238_BUS_OVER_VOLTAGE:
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 269 case INA238_BUS_UNDER_VOLTAGE:
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 270 regval = div_u64((val * 1000), INA238_BUS_VOLTAGE_LSB);
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 271 if (regval > U16_MAX || regval < 0) {
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 272 ret = -EINVAL;
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 273 goto abort;
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 274 }
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 275 break;
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 276 case INA238_POWER_LIMIT:
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 277 /*
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 278 * Compared against the 24-bit power register, lower 8-bits are
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 279 * truncated. Same conversion to/from uW as POWER register.
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 280 */
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 281 regval = div_u64(val * 5 * data->rshunt,
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 282 1000 * INA238_FIXED_SHUNT) >> 8;
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 283 if (regval > U16_MAX || regval < 0) {
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 284 ret = -EINVAL;
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 285 goto abort;
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 286 }
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 287 break;
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 288 case INA238_TEMP_LIMIT:
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 289 /* Bits 15-4 of register */
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 290 regval = (div_s64(val, INA238_DIE_TEMP_LSB) << 4);
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 291 if (regval > S16_MAX || regval < S16_MIN) {
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 292 ret = -EINVAL;
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 293 goto abort;
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 294 }
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 295 regval = regval & 0xfff0;
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 296 break;
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 297 default:
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 298 WARN_ON_ONCE(1);

regval isn't set on this path.

aafb1ad1e44aa2 Nathan Rossi 2021-10-25 299 break;
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 300 }
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 301
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 302 mutex_lock(&data->config_lock);
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 303
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 @304 ret = regmap_write(data->regmap, attr->index, regval);
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 305 if (ret < 0)
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 306 goto abort;
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 307
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 308 ret = count;
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 309 abort:
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 310 mutex_unlock(&data->config_lock);
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 311 return ret;
aafb1ad1e44aa2 Nathan Rossi 2021-10-25 312 }

---
0-DAY CI Kernel Test Service, Intel Corporation