Message ID | d7464094f82945ae7978a18e0117570b2c71c963.1586247885.git.lorenzo@kernel.org (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | iio: imu: st_lsm6dsx: limit variales scope reading hw FIFO | expand |
On Tue, 7 Apr 2020 10:26:44 +0200 Lorenzo Bianconi <lorenzo@kernel.org> wrote: > Fix following cppcheck warnings reported by kbuild test robot > > drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c:313:15: > warning: The scope of the variable 'word_len' can be reduced. [variableScope] > ^ > drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c:314:6: > warning: The scope of the variable 'err' can be reduced. [variableScope] > ^ > drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c:341:11: > warning: The scope of the variable 'sip' can be reduced. [variableScope] > ^ > drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c:341:16: > warning: The scope of the variable 'acc_sip' can be reduced. [variableScope] > ^ > drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c:341:25: > warning: The scope of the variable 'gyro_sip' can be reduced. [variableScope] > ^ > drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c:341:35: > warning: The scope of the variable 'ts_sip' can be reduced. [variableScope] > ^ > drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c:341:43: > warning: The scope of the variable 'ext_sip' can be reduced. [variableScope] > ^ > drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c:341:62: > warning: The scope of the variable 'offset' can be reduced. [variableScope] > > Reported-by: kbuild test robot <lkp@intel.com> > Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org> I find it hard to care about these to be honest. I got the original report at chose not to fix them :) Anyhow, if you want to tidy them up that's fine of course. More interestingly this doesn't actually apply any more due to your sensor hub patches. If you want to respin on top of the testing branch of iio.git then feel free. Thanks, Jonathan > --- > drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c | 12 +++++++----- > 1 file changed, 7 insertions(+), 5 deletions(-) > > diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c > index afd00daeefb2..849f01fbe76c 100644 > --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c > +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c > @@ -310,10 +310,12 @@ static inline int st_lsm6dsx_read_block(struct st_lsm6dsx_hw *hw, u8 addr, > u8 *data, unsigned int data_len, > unsigned int max_word_len) > { > - unsigned int word_len, read_len = 0; > - int err; > + unsigned int read_len = 0; > > while (read_len < data_len) { > + unsigned int word_len; > + int err; > + > word_len = min_t(unsigned int, data_len - read_len, > max_word_len); > err = st_lsm6dsx_read_locked(hw, addr, data + read_len, > @@ -338,7 +340,6 @@ static inline int st_lsm6dsx_read_block(struct st_lsm6dsx_hw *hw, u8 addr, > int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw) > { > struct st_lsm6dsx_sensor *acc_sensor, *gyro_sensor, *ext_sensor = NULL; > - int err, sip, acc_sip, gyro_sip, ts_sip, ext_sip, read_len, offset; > u16 fifo_len, pattern_len = hw->sip * ST_LSM6DSX_SAMPLE_SIZE; > u16 fifo_diff_mask = hw->settings->fifo_ops.fifo_diff.mask; > u8 gyro_buff[ST_LSM6DSX_IIO_BUFF_SIZE]; > @@ -346,6 +347,7 @@ int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw) > u8 ext_buff[ST_LSM6DSX_IIO_BUFF_SIZE]; > bool reset_ts = false; > __le16 fifo_status; > + int err, read_len; > s64 ts = 0; > > err = st_lsm6dsx_read_locked(hw, > @@ -370,6 +372,8 @@ int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw) > ext_sensor = iio_priv(hw->iio_devs[ST_LSM6DSX_ID_EXT0]); > > for (read_len = 0; read_len < fifo_len; read_len += pattern_len) { > + int acc_sip, gyro_sip, ts_sip, ext_sip, offset = 0, sip = 0; > + > err = st_lsm6dsx_read_block(hw, ST_LSM6DSX_REG_FIFO_OUTL_ADDR, > hw->buff, pattern_len, > ST_LSM6DSX_MAX_WORD_LEN); > @@ -399,8 +403,6 @@ int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw) > gyro_sip = gyro_sensor->sip; > acc_sip = acc_sensor->sip; > ts_sip = hw->ts_sip; > - offset = 0; > - sip = 0; > > while (acc_sip > 0 || gyro_sip > 0 || ext_sip > 0) { > if (gyro_sip > 0 && !(sip % gyro_sensor->decimator)) {
> > On Tue, 7 Apr 2020 10:26:44 +0200 > Lorenzo Bianconi <lorenzo@kernel.org> wrote: > > > Fix following cppcheck warnings reported by kbuild test robot > > > > drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c:313:15: > > warning: The scope of the variable 'word_len' can be reduced. [variableScope] > > ^ > > drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c:314:6: > > warning: The scope of the variable 'err' can be reduced. [variableScope] > > ^ > > drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c:341:11: > > warning: The scope of the variable 'sip' can be reduced. [variableScope] > > ^ > > drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c:341:16: > > warning: The scope of the variable 'acc_sip' can be reduced. [variableScope] > > ^ > > drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c:341:25: > > warning: The scope of the variable 'gyro_sip' can be reduced. [variableScope] > > ^ > > drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c:341:35: > > warning: The scope of the variable 'ts_sip' can be reduced. [variableScope] > > ^ > > drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c:341:43: > > warning: The scope of the variable 'ext_sip' can be reduced. [variableScope] > > ^ > > drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c:341:62: > > warning: The scope of the variable 'offset' can be reduced. [variableScope] > > > > Reported-by: kbuild test robot <lkp@intel.com> > > Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org> > I find it hard to care about these to be honest. I got the original report > at chose not to fix them :) Anyhow, if you want to tidy them up that's fine > of course. > > More interestingly this doesn't actually apply any more due to your sensor > hub patches. If you want to respin on top of the testing branch of iio.git > then feel free. > I agree with you, there are probably other 'errors' like that one so I guess we can just drop it. Regards, Lorenzo > Thanks, > > Jonathan > > > --- > > drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c | 12 +++++++----- > > 1 file changed, 7 insertions(+), 5 deletions(-) > > > > diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c > > index afd00daeefb2..849f01fbe76c 100644 > > --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c > > +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c > > @@ -310,10 +310,12 @@ static inline int st_lsm6dsx_read_block(struct st_lsm6dsx_hw *hw, u8 addr, > > u8 *data, unsigned int data_len, > > unsigned int max_word_len) > > { > > - unsigned int word_len, read_len = 0; > > - int err; > > + unsigned int read_len = 0; > > > > while (read_len < data_len) { > > + unsigned int word_len; > > + int err; > > + > > word_len = min_t(unsigned int, data_len - read_len, > > max_word_len); > > err = st_lsm6dsx_read_locked(hw, addr, data + read_len, > > @@ -338,7 +340,6 @@ static inline int st_lsm6dsx_read_block(struct st_lsm6dsx_hw *hw, u8 addr, > > int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw) > > { > > struct st_lsm6dsx_sensor *acc_sensor, *gyro_sensor, *ext_sensor = NULL; > > - int err, sip, acc_sip, gyro_sip, ts_sip, ext_sip, read_len, offset; > > u16 fifo_len, pattern_len = hw->sip * ST_LSM6DSX_SAMPLE_SIZE; > > u16 fifo_diff_mask = hw->settings->fifo_ops.fifo_diff.mask; > > u8 gyro_buff[ST_LSM6DSX_IIO_BUFF_SIZE]; > > @@ -346,6 +347,7 @@ int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw) > > u8 ext_buff[ST_LSM6DSX_IIO_BUFF_SIZE]; > > bool reset_ts = false; > > __le16 fifo_status; > > + int err, read_len; > > s64 ts = 0; > > > > err = st_lsm6dsx_read_locked(hw, > > @@ -370,6 +372,8 @@ int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw) > > ext_sensor = iio_priv(hw->iio_devs[ST_LSM6DSX_ID_EXT0]); > > > > for (read_len = 0; read_len < fifo_len; read_len += pattern_len) { > > + int acc_sip, gyro_sip, ts_sip, ext_sip, offset = 0, sip = 0; > > + > > err = st_lsm6dsx_read_block(hw, ST_LSM6DSX_REG_FIFO_OUTL_ADDR, > > hw->buff, pattern_len, > > ST_LSM6DSX_MAX_WORD_LEN); > > @@ -399,8 +403,6 @@ int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw) > > gyro_sip = gyro_sensor->sip; > > acc_sip = acc_sensor->sip; > > ts_sip = hw->ts_sip; > > - offset = 0; > > - sip = 0; > > > > while (acc_sip > 0 || gyro_sip > 0 || ext_sip > 0) { > > if (gyro_sip > 0 && !(sip % gyro_sensor->decimator)) { >
diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c index afd00daeefb2..849f01fbe76c 100644 --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c @@ -310,10 +310,12 @@ static inline int st_lsm6dsx_read_block(struct st_lsm6dsx_hw *hw, u8 addr, u8 *data, unsigned int data_len, unsigned int max_word_len) { - unsigned int word_len, read_len = 0; - int err; + unsigned int read_len = 0; while (read_len < data_len) { + unsigned int word_len; + int err; + word_len = min_t(unsigned int, data_len - read_len, max_word_len); err = st_lsm6dsx_read_locked(hw, addr, data + read_len, @@ -338,7 +340,6 @@ static inline int st_lsm6dsx_read_block(struct st_lsm6dsx_hw *hw, u8 addr, int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw) { struct st_lsm6dsx_sensor *acc_sensor, *gyro_sensor, *ext_sensor = NULL; - int err, sip, acc_sip, gyro_sip, ts_sip, ext_sip, read_len, offset; u16 fifo_len, pattern_len = hw->sip * ST_LSM6DSX_SAMPLE_SIZE; u16 fifo_diff_mask = hw->settings->fifo_ops.fifo_diff.mask; u8 gyro_buff[ST_LSM6DSX_IIO_BUFF_SIZE]; @@ -346,6 +347,7 @@ int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw) u8 ext_buff[ST_LSM6DSX_IIO_BUFF_SIZE]; bool reset_ts = false; __le16 fifo_status; + int err, read_len; s64 ts = 0; err = st_lsm6dsx_read_locked(hw, @@ -370,6 +372,8 @@ int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw) ext_sensor = iio_priv(hw->iio_devs[ST_LSM6DSX_ID_EXT0]); for (read_len = 0; read_len < fifo_len; read_len += pattern_len) { + int acc_sip, gyro_sip, ts_sip, ext_sip, offset = 0, sip = 0; + err = st_lsm6dsx_read_block(hw, ST_LSM6DSX_REG_FIFO_OUTL_ADDR, hw->buff, pattern_len, ST_LSM6DSX_MAX_WORD_LEN); @@ -399,8 +403,6 @@ int st_lsm6dsx_read_fifo(struct st_lsm6dsx_hw *hw) gyro_sip = gyro_sensor->sip; acc_sip = acc_sensor->sip; ts_sip = hw->ts_sip; - offset = 0; - sip = 0; while (acc_sip > 0 || gyro_sip > 0 || ext_sip > 0) { if (gyro_sip > 0 && !(sip % gyro_sensor->decimator)) {
Fix following cppcheck warnings reported by kbuild test robot drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c:313:15: warning: The scope of the variable 'word_len' can be reduced. [variableScope] ^ drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c:314:6: warning: The scope of the variable 'err' can be reduced. [variableScope] ^ drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c:341:11: warning: The scope of the variable 'sip' can be reduced. [variableScope] ^ drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c:341:16: warning: The scope of the variable 'acc_sip' can be reduced. [variableScope] ^ drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c:341:25: warning: The scope of the variable 'gyro_sip' can be reduced. [variableScope] ^ drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c:341:35: warning: The scope of the variable 'ts_sip' can be reduced. [variableScope] ^ drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c:341:43: warning: The scope of the variable 'ext_sip' can be reduced. [variableScope] ^ drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c:341:62: warning: The scope of the variable 'offset' can be reduced. [variableScope] Reported-by: kbuild test robot <lkp@intel.com> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org> --- drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_buffer.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)