[<prev] [next>] [day] [month] [year] [list]
Message-ID: <202209261001.a8hOrx3A-lkp@intel.com>
Date: Mon, 26 Sep 2022 13:09:02 +0300
From: Dan Carpenter <dan.carpenter@...cle.com>
To: kbuild@...ts.01.org, Andrea Merello <andrea.merello@....it>
Cc: lkp@...el.com, kbuild-all@...ts.01.org,
linux-kernel@...r.kernel.org,
Jonathan Cameron <Jonathan.Cameron@...wei.com>,
Andy Shevchenko <andy.shevchenko@...il.com>
Subject: [jic23-iio:testing 44/63] drivers/iio/imu/bno055/bno055.c:635
bno055_set_regmask() error: uninitialized symbol 'best_delta'.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git testing
head: df957373c1649c74b78bf2fcfd144f0c3baa68a5
commit: 50fe984f376abb4a00f80e13f51465ef09c2bde7 [44/63] iio: imu: add BNO055 I2C driver
config: s390-randconfig-m031-20220925
compiler: s390-linux-gcc (GCC) 12.1.0
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@...el.com>
| Reported-by: Dan Carpenter <dan.carpenter@...cle.com>
New smatch warnings:
drivers/iio/imu/bno055/bno055.c:635 bno055_set_regmask() error: uninitialized symbol 'best_delta'.
drivers/iio/imu/bno055/bno055.c:643 bno055_set_regmask() error: uninitialized symbol 'hwval'.
drivers/iio/imu/bno055/bno055.c:1511 bno055_trigger_handler() error: uninitialized symbol 'xfer_start'.
drivers/iio/imu/bno055/bno055.c:1513 bno055_trigger_handler() error: uninitialized symbol 'prev_end'.
Old smatch warnings:
drivers/iio/imu/bno055/bno055.c:649 bno055_set_regmask() error: uninitialized symbol 'hwval'.
vim +/best_delta +635 drivers/iio/imu/bno055/bno055.c
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 579 static int bno055_set_regmask(struct bno055_priv *priv, int val, int val2,
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 580 int reg, int mask, struct bno055_sysfs_attr *attr)
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 581 {
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 582 const int shift = __ffs(mask);
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 583 int best_delta;
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 584 int req_val;
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 585 int tbl_val;
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 586 bool first;
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 587 int delta;
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 588 int hwval;
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 589 int ret;
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 590 int len;
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 591 int i;
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 592
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 593 /*
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 594 * The closest value the HW supports is only one in fusion mode,
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 595 * and it is autoselected, so don't do anything, just return OK,
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 596 * as the closest possible value has been (virtually) selected
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 597 */
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 598 if (priv->operation_mode != BNO055_OPR_MODE_AMG)
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 599 return 0;
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 600
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 601 len = attr->len;
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 602
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 603 /*
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 604 * We always get a request in INT_PLUS_MICRO, but we
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 605 * take care of the micro part only when we really have
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 606 * non-integer tables. This prevents 32-bit overflow with
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 607 * larger integers contained in integer tables.
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 608 */
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 609 req_val = val;
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 610 if (attr->type != IIO_VAL_INT) {
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 611 len /= 2;
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 612 req_val = min(val, 2147) * 1000000 + val2;
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 613 }
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 614
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 615 first = true;
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 616 for (i = 0; i < len; i++) {
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 617 switch (attr->type) {
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 618 case IIO_VAL_INT:
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 619 tbl_val = attr->vals[i];
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 620 break;
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 621 case IIO_VAL_INT_PLUS_MICRO:
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 622 WARN_ON(attr->vals[i * 2] > 2147);
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 623 tbl_val = attr->vals[i * 2] * 1000000 +
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 624 attr->vals[i * 2 + 1];
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 625 break;
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 626 case IIO_VAL_FRACTIONAL:
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 627 WARN_ON(attr->vals[i * 2] > 4294);
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 628 tbl_val = attr->vals[i * 2] * 1000000 /
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 629 attr->vals[i * 2 + 1];
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 630 break;
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 631 default:
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 632 return -EINVAL;
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 633 }
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 634 delta = abs(tbl_val - req_val);
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 @635 if (delta < best_delta || first) {
These tests need to be reversed to prevent reading uninitialized data.
if (first || delta < best_delta) {
It's the correct thing to do. KMsan will detect this at run time. It's
undefined to read uninitialized data.
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 636 best_delta = delta;
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 637 hwval = i;
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 638 first = false;
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 639 }
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 640 }
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 641
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 642 if (attr->hw_xlate)
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 @643 hwval = attr->hw_xlate[hwval];
This one is likely a false positive but it's not feasible for the
kbuild bot to use cross function data so it does not know that
attr->len must be greater than zero.
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 644
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 645 ret = bno055_operation_mode_do_set(priv, BNO055_OPR_MODE_CONFIG);
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 646 if (ret)
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 647 return ret;
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 648
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 649 ret = regmap_update_bits(priv->regmap, reg, mask, hwval << shift);
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 650 if (ret)
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 651 return ret;
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 652
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 653 return bno055_operation_mode_do_set(priv, BNO055_OPR_MODE_AMG);
4aefe1c2bd0cb0 Andrea Merello 2022-09-07 654 }
Powered by blists - more mailing lists