linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: imu: st_lsm6dsx: limit variales scope reading hw FIFO
@ 2020-04-07  8:26 Lorenzo Bianconi
  2020-04-12 13:25 ` Jonathan Cameron
  0 siblings, 1 reply; 3+ messages in thread
From: Lorenzo Bianconi @ 2020-04-07  8:26 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, lorenzo.bianconi

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(-)

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)) {
-- 
2.25.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] iio: imu: st_lsm6dsx: limit variales scope reading hw FIFO
  2020-04-07  8:26 [PATCH] iio: imu: st_lsm6dsx: limit variales scope reading hw FIFO Lorenzo Bianconi
@ 2020-04-12 13:25 ` Jonathan Cameron
  2020-04-12 22:12   ` Lorenzo Bianconi
  0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Cameron @ 2020-04-12 13:25 UTC (permalink / raw)
  To: Lorenzo Bianconi; +Cc: linux-iio, lorenzo.bianconi

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)) {


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] iio: imu: st_lsm6dsx: limit variales scope reading hw FIFO
  2020-04-12 13:25 ` Jonathan Cameron
@ 2020-04-12 22:12   ` Lorenzo Bianconi
  0 siblings, 0 replies; 3+ messages in thread
From: Lorenzo Bianconi @ 2020-04-12 22:12 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: Lorenzo Bianconi, linux-iio

>
> 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)) {
>


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-04-12 22:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-07  8:26 [PATCH] iio: imu: st_lsm6dsx: limit variales scope reading hw FIFO Lorenzo Bianconi
2020-04-12 13:25 ` Jonathan Cameron
2020-04-12 22:12   ` Lorenzo Bianconi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).