iio: imu: bmi160: bmi160_core: Fix sparse warning
PATCH 1/1 iio: imu: bmi160: bmi160_core: Fix sparse warning
Fix the following sparse warning due to incorrect type in assignment:drivers/iio/imu/bmi160/bmi160_core.c:411:26: warning: incorrect type in assignment (different base types)
drivers/iio/imu/bmi160/bmi160_core.c:411:26: expected signed short [signed] [short] [explicitly-signed] <noident> drivers/iio/imu/bmi160/bmi160_core.c:411:26: got restricted __le16 [addressable] [usertype] sample
--- drivers/iio/imu/bmi160/bmi160_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/iio/imu/bmi160/bmi160_core.c +2 -1
@@ -398,7 +398,8 @@ static irqreturn_t bmi160_trigger_handler(int irq, void *p)struct iio_poll_func *pf = p;struct iio_dev *indio_dev = pf->indio_dev;struct bmi160_data *data =iio_priv (indio_dev); -s16 buf[16 ];/* 3 sens x 3 axis x s16 + 3 x s16 pad + 4 x s16 tstamp */ +__le16 buf[16 ]; +/* 3 sens x 3 axis x __le16 + 3 x __le16 pad + 4 x __le16 tstamp */ int i, ret, j =0 , base =BMI160_REG_DATA_MAGN_XOUT_L ;__le16 sample;
Signature · 1 line
2.7.4
Quoted 10 lines · sayli karnik
Fix the following sparse warning due to incorrect type in assignment:
drivers/iio/imu/bmi160/bmi160_core.c:411:26: warning: incorrect type in assignment (different base types)
drivers/iio/imu/bmi160/bmi160_core.c:411:26: expected signed short [signed] [short] [explicitly-signed] <noident>drivers/iio/imu/bmi160/bmi160_core.c:411:26: got restricted__le16[addressable] [usertype] sampleSigned-off-by sayli karnik <[email protected]>
Hi Sayli,
Please claim this via the outreachy task page - section endianness coding task. Perhaps you can update the commit msg & changelog with the cosmetic vs bug impact statement as in your earlier patch.
question inline below
Quoted 9 lines
--- drivers/iio/imu/bmi160/bmi160_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/iio/imu/bmi160/bmi160_core.c +0
-0
drivers/iio/imu/bmi160/bmi160_core.c static irqreturn_t bmi160_trigger_handler(int irq, void *p) · line 404
Quoted 8 lines
drivers/iio/imu/bmi160/bmi160_core.c +2
-1@@ -398,7 +398,8 @@ static irqreturn_t bmi160_trigger_handler(int irq, void *p)struct iio_poll_func *pf = p;struct iio_dev *indio_dev = pf->indio_dev;struct bmi160_data *data =iio_priv (indio_dev); -s16 buf[16 ];/* 3 sens x 3 axis x s16 + 3 x s16 pad + 4 x s16 tstamp */ +__le16 buf[16 ]; +/* 3 sens x 3 axis x __le16 + 3 x __le16 pad + 4 x __le16 tstamp */ int i, ret, j =0 , base =BMI160_REG_DATA_MAGN_XOUT_L ;__le16 sample;
Wondering about this option below. Data was read into an __le16, so that was good diligence on drivers part. Seems we can use le16_to_cpu() for the conversion into the buf.
drivers/iio/imu/bmi160/bmi160_core.c +1 -1
@@ -408,7 +408,7 @@ static irqreturn_t bmi160_trigger_handler(int irq, void *p) &sample, sizeof(__le16));if (ret <0 ) goto done; - buf[j++] = sample; + buf[j++] =le16_to_cpu (sample); } iio_push_to_buffers_with_timestamp(indio_dev, buf,
alisons
Quoted 10 lines
Signature · 9 lines
-- 2.7.4 -- You received this message because you are subscribed to the Google Groups "outreachy-kernel" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20161001110418.GA25515%40sayli-HP-15-Notebook-PC. For more options, visit https://groups.google.com/d/optout.
On 10/02/2016 07:00 AM, Alison Schofield wrote:
[...]
Quoted 25 lines
Quoted 9 lines
--- drivers/iio/imu/bmi160/bmi160_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/iio/imu/bmi160/bmi160_core.c +0
-0drivers/iio/imu/bmi160/bmi160_core.c static irqreturn_t bmi160_trigger_handler(int irq, void *p) · line 404
Quoted 8 lines
drivers/iio/imu/bmi160/bmi160_core.c +2
-1@@ -398,7 +398,8 @@ static irqreturn_t bmi160_trigger_handler(int irq, void *p)struct iio_poll_func *pf = p;struct iio_dev *indio_dev = pf->indio_dev;struct bmi160_data *data =iio_priv (indio_dev); -s16 buf[16 ];/* 3 sens x 3 axis x s16 + 3 x s16 pad + 4 x s16 tstamp */ +__le16 buf[16 ]; +/* 3 sens x 3 axis x __le16 + 3 x __le16 pad + 4 x __le16 tstamp */ int i, ret, j =0 , base =BMI160_REG_DATA_MAGN_XOUT_L ;__le16 sample;Wondering about this option below. Data was read into an
__le16, so that was good diligence on drivers part. Seems we can usele16_to_cpu()for the conversion into the buf.
drivers/iio/imu/bmi160/bmi160_core.c static irqreturn_t bmi160_trigger_handler(int irq, void *p) · line 412
Quoted 6 lines
drivers/iio/imu/bmi160/bmi160_core.c +1
-1@@ -408,7 +408,7 @@ static irqreturn_t bmi160_trigger_handler(int irq, void *p) &sample, sizeof(__le16));if (ret <0 ) goto done; - buf[j++] = sample; + buf[j++] =le16_to_cpu (sample); }
This conversion is usually skipped on purpose and delayed until it is actually needed by the user. The IIO channel is accordingly marked that it will produce LE data.
Quoted 24 lines · Lars-Peter Clausen
On 10/02/2016 07:00 AM, Alison Schofield wrote:
[...]Quoted 22 lines
Quoted 9 lines
--- drivers/iio/imu/bmi160/bmi160_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/iio/imu/bmi160/bmi160_core.c +0
-0drivers/iio/imu/bmi160/bmi160_core.c static irqreturn_t bmi160_trigger_handler(int irq, void *p) · line 404
Quoted 8 lines
drivers/iio/imu/bmi160/bmi160_core.c +2
-1@@ -398,7 +398,8 @@ static irqreturn_t bmi160_trigger_handler(int irq, void *p)struct iio_poll_func *pf = p;struct iio_dev *indio_dev = pf->indio_dev;struct bmi160_data *data =iio_priv (indio_dev); -s16 buf[16 ];/* 3 sens x 3 axis x s16 + 3 x s16 pad + 4 x s16 tstamp */ +__le16 buf[16 ]; +/* 3 sens x 3 axis x __le16 + 3 x __le16 pad + 4 x __le16 tstamp */ int i, ret, j =0 , base =BMI160_REG_DATA_MAGN_XOUT_L ;__le16 sample;Wondering about this option below. Data was read into an
__le16, so that was good diligence on drivers part. Seems we can usele16_to_cpu()for the conversion into the buf.
Quoted 13 lines
drivers/iio/imu/bmi160/bmi160_core.c static irqreturn_t bmi160_trigger_handler(int irq, void *p) · line 412
Quoted 9 lines
drivers/iio/imu/bmi160/bmi160_core.c +1
-1@@ -408,7 +408,7 @@ static irqreturn_t bmi160_trigger_handler(int irq, void *p) &sample, sizeof(__le16));if (ret <0 ) goto done; - buf[j++] = sample; + buf[j++] =le16_to_cpu (sample); }This conversion is usually skipped on purpose and delayed until it is actually needed by the user. The IIO channel is accordingly marked that it will produce LE data.
Thanks Lars. I knew that for buffers, overlooked it, now I'll know it better!
So, Sayli, you probably got this from the analysis of the last patch. In buffered mode, we'll go ahead and return the data in it's 'native' order. So, my suggestion to convert it here, is wrong. Ignore ;)
alisons
Quoted 1 line
Quoted 38 lines · Alison Schofield
Quoted 24 lines · Lars-Peter Clausen
On 10/02/2016 07:00 AM, Alison Schofield wrote:
[...]Quoted 22 lines
Quoted 9 lines
--- drivers/iio/imu/bmi160/bmi160_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/iio/imu/bmi160/bmi160_core.c +0
-0drivers/iio/imu/bmi160/bmi160_core.c static irqreturn_t bmi160_trigger_handler(int irq, void *p) · line 404
Quoted 8 lines
drivers/iio/imu/bmi160/bmi160_core.c +2
-1@@ -398,7 +398,8 @@ static irqreturn_t bmi160_trigger_handler(int irq, void *p)struct iio_poll_func *pf = p;struct iio_dev *indio_dev = pf->indio_dev;struct bmi160_data *data =iio_priv (indio_dev); -s16 buf[16 ];/* 3 sens x 3 axis x s16 + 3 x s16 pad + 4 x s16 tstamp */ +__le16 buf[16 ]; +/* 3 sens x 3 axis x __le16 + 3 x __le16 pad + 4 x __le16 tstamp */ int i, ret, j =0 , base =BMI160_REG_DATA_MAGN_XOUT_L ;__le16 sample;Wondering about this option below. Data was read into an
__le16, so that was good diligence on drivers part. Seems we can usele16_to_cpu()for the conversion into the buf.Quoted 13 lines
drivers/iio/imu/bmi160/bmi160_core.c static irqreturn_t bmi160_trigger_handler(int irq, void *p) · line 412
Quoted 9 lines
drivers/iio/imu/bmi160/bmi160_core.c +1
-1@@ -408,7 +408,7 @@ static irqreturn_t bmi160_trigger_handler(int irq, void *p) &sample, sizeof(__le16));if (ret <0 ) goto done; - buf[j++] = sample; + buf[j++] =le16_to_cpu (sample); }This conversion is usually skipped on purpose and delayed until it is actually needed by the user. The IIO channel is accordingly marked that it will produce LE data.
Quoted 7 lines
Thanks Lars. I knew that for buffers, overlooked it, now I'll know it better!
So, Sayli, you probably got this from the analysis of the last patch. In buffered mode, we'll go ahead and return the data in it's 'native' order. So, my suggestion to convert it here, is wrong. Ignore ;)
Oh I see! So should I resend the patch with an updated description?(cosmetic/bug fix)
thanks,
sayli
Quoted 3 lines
alisons
Quoted 1 line
Quoted 42 lines · sayli karnik
Quoted 41 lines · Alison Schofield
Quoted 24 lines · Lars-Peter Clausen
On 10/02/2016 07:00 AM, Alison Schofield wrote:
[...]Quoted 22 lines
Quoted 9 lines
--- drivers/iio/imu/bmi160/bmi160_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/iio/imu/bmi160/bmi160_core.c +0
-0drivers/iio/imu/bmi160/bmi160_core.c static irqreturn_t bmi160_trigger_handler(int irq, void *p) · line 404
Quoted 8 lines
drivers/iio/imu/bmi160/bmi160_core.c +2
-1@@ -398,7 +398,8 @@ static irqreturn_t bmi160_trigger_handler(int irq, void *p)struct iio_poll_func *pf = p;struct iio_dev *indio_dev = pf->indio_dev;struct bmi160_data *data =iio_priv (indio_dev); -s16 buf[16 ];/* 3 sens x 3 axis x s16 + 3 x s16 pad + 4 x s16 tstamp */ +__le16 buf[16 ]; +/* 3 sens x 3 axis x __le16 + 3 x __le16 pad + 4 x __le16 tstamp */ int i, ret, j =0 , base =BMI160_REG_DATA_MAGN_XOUT_L ;__le16 sample;Wondering about this option below. Data was read into an
__le16, so that was good diligence on drivers part. Seems we can usele16_to_cpu()for the conversion into the buf.Quoted 13 lines
drivers/iio/imu/bmi160/bmi160_core.c static irqreturn_t bmi160_trigger_handler(int irq, void *p) · line 412
Quoted 9 lines
drivers/iio/imu/bmi160/bmi160_core.c +1
-1@@ -408,7 +408,7 @@ static irqreturn_t bmi160_trigger_handler(int irq, void *p) &sample, sizeof(__le16));if (ret <0 ) goto done; - buf[j++] = sample; + buf[j++] =le16_to_cpu (sample); }This conversion is usually skipped on purpose and delayed until it is actually needed by the user. The IIO channel is accordingly marked that it will produce LE data.
Thanks Lars. I knew that for buffers, overlooked it, now I'll know it better!
Quoted 6 lines
Quoted 4 lines
So, Sayli, you probably got this from the analysis of the last patch. In buffered mode, we'll go ahead and return the data in it's 'native' order. So, my suggestion to convert it here, is wrong. Ignore ;)
Oh I see! So should I resend the patch with an updated description?(cosmetic/bug fix)
Yes. In the commit message, you can leave out the subdirs (imu: bmc160:) so that you have more space for a descriptive message of the change. alisons
Quoted 7 lines
thanks,
sayliQuoted 3 lines
alisons
Quoted 1 line
Quoted 47 lines · Alison Schofield
Quoted 46 lines · sayli karnik
Quoted 45 lines · Alison Schofield
Quoted 24 lines · Lars-Peter Clausen
On 10/02/2016 07:00 AM, Alison Schofield wrote:
[...]Quoted 22 lines
Quoted 9 lines
--- drivers/iio/imu/bmi160/bmi160_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/iio/imu/bmi160/bmi160_core.c +0
-0drivers/iio/imu/bmi160/bmi160_core.c static irqreturn_t bmi160_trigger_handler(int irq, void *p) · line 404
Quoted 8 lines
drivers/iio/imu/bmi160/bmi160_core.c +2
-1@@ -398,7 +398,8 @@ static irqreturn_t bmi160_trigger_handler(int irq, void *p)struct iio_poll_func *pf = p;struct iio_dev *indio_dev = pf->indio_dev;struct bmi160_data *data =iio_priv (indio_dev); -s16 buf[16 ];/* 3 sens x 3 axis x s16 + 3 x s16 pad + 4 x s16 tstamp */ +__le16 buf[16 ]; +/* 3 sens x 3 axis x __le16 + 3 x __le16 pad + 4 x __le16 tstamp */ int i, ret, j =0 , base =BMI160_REG_DATA_MAGN_XOUT_L ;__le16 sample;Wondering about this option below. Data was read into an
__le16, so that was good diligence on drivers part. Seems we can usele16_to_cpu()for the conversion into the buf.Quoted 13 lines
drivers/iio/imu/bmi160/bmi160_core.c static irqreturn_t bmi160_trigger_handler(int irq, void *p) · line 412
Quoted 9 lines
drivers/iio/imu/bmi160/bmi160_core.c +1
-1@@ -408,7 +408,7 @@ static irqreturn_t bmi160_trigger_handler(int irq, void *p) &sample, sizeof(__le16));if (ret <0 ) goto done; - buf[j++] = sample; + buf[j++] =le16_to_cpu (sample); }This conversion is usually skipped on purpose and delayed until it is actually needed by the user. The IIO channel is accordingly marked that it will produce LE data.
Thanks Lars. I knew that for buffers, overlooked it, now I'll know it better!
So, Sayli, you probably got this from the analysis of the last patch. In buffered mode, we'll go ahead and return the data in it's 'native' order. So, my suggestion to convert it here, is wrong. Ignore ;)
Quoted 5 lines
Quoted 2 lines
Oh I see! So should I resend the patch with an updated description?(cosmetic/bug fix)
Yes. In the commit message, you can leave out the subdirs (imu: bmc160:) so that you have more space for a descriptive message of the change.
A quick question about this being a bug fix or not. This would have worked fine on little endian systems. But wouldn't the byte order have changed in case of a big endian buffer, when the little endian samples are stored in it?
If not, then this will be a cosmetic patch.
thanks,
sayli
Quoted 16 lines
alisons
Quoted 7 lines
thanks,
sayliQuoted 3 lines
alisons
Quoted 1 line
--
You received this message because you are subscribed to the Google Groups "outreachy-kernel" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/outreachy-kernel/20161003171601.GC3132%40d830.WORKGROUP.
For more options, visit https://groups.google.com/d/optout.
Quoted 54 lines · sayli karnik
Quoted 47 lines · Alison Schofield
Quoted 46 lines · sayli karnik
Quoted 45 lines · Alison Schofield
Quoted 24 lines · Lars-Peter Clausen
On 10/02/2016 07:00 AM, Alison Schofield wrote:
[...]Quoted 22 lines
Quoted 9 lines
--- drivers/iio/imu/bmi160/bmi160_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/iio/imu/bmi160/bmi160_core.c +0
-0drivers/iio/imu/bmi160/bmi160_core.c static irqreturn_t bmi160_trigger_handler(int irq, void *p) · line 404
Quoted 8 lines
drivers/iio/imu/bmi160/bmi160_core.c +2
-1@@ -398,7 +398,8 @@ static irqreturn_t bmi160_trigger_handler(int irq, void *p)struct iio_poll_func *pf = p;struct iio_dev *indio_dev = pf->indio_dev;struct bmi160_data *data =iio_priv (indio_dev); -s16 buf[16 ];/* 3 sens x 3 axis x s16 + 3 x s16 pad + 4 x s16 tstamp */ +__le16 buf[16 ]; +/* 3 sens x 3 axis x __le16 + 3 x __le16 pad + 4 x __le16 tstamp */ int i, ret, j =0 , base =BMI160_REG_DATA_MAGN_XOUT_L ;__le16 sample;Wondering about this option below. Data was read into an
__le16, so that was good diligence on drivers part. Seems we can usele16_to_cpu()for the conversion into the buf.Quoted 13 lines
drivers/iio/imu/bmi160/bmi160_core.c static irqreturn_t bmi160_trigger_handler(int irq, void *p) · line 412
Quoted 9 lines
drivers/iio/imu/bmi160/bmi160_core.c +1
-1@@ -408,7 +408,7 @@ static irqreturn_t bmi160_trigger_handler(int irq, void *p) &sample, sizeof(__le16));if (ret <0 ) goto done; - buf[j++] = sample; + buf[j++] =le16_to_cpu (sample); }This conversion is usually skipped on purpose and delayed until it is actually needed by the user. The IIO channel is accordingly marked that it will produce LE data.
Thanks Lars. I knew that for buffers, overlooked it, now I'll know it better!
So, Sayli, you probably got this from the analysis of the last patch. In buffered mode, we'll go ahead and return the data in it's 'native' order. So, my suggestion to convert it here, is wrong. Ignore ;)
Quoted 5 lines
Quoted 2 lines
Oh I see! So should I resend the patch with an updated description?(cosmetic/bug fix)
Yes. In the commit message, you can leave out the subdirs (imu: bmc160:) so that you have more space for a descriptive message of the change.
Quoted 8 lines
A quick question about this being a bug fix or not. This would have worked fine on little endian systems. But wouldn't the byte order have changed in case of a big endian buffer, when the little endian samples are stored in it?
If not, then this will be a cosmetic patch.thanks,
sayli
Hi Sayli,
Pulling linux-iio back in. Once we've started group thread, we need to keep replying to 'all'. It helps those invested in this particular patch, and also helps those who search in the future with similar issues.
To answer your question. I say cosmetic, because the le16 is going into a 16bit buf element, and is labelled as IIO_LE in the channel buffer definition. That's why Lars was saying we don't need to do any conversion. We'll pass the bits as they came in, and tell the readers of the buf that they are in little endian format. (And, also note we weren't truncating any as was the case in your first endian fix.)
OK - having said that, I stare at this code more, and wonder why we are even bothering to label the sample as __le16, and whether we should just label it as s16. Also, I'm wondering about the use of sizeof(). Shouldn't we be saying sizeof(sample) not sizeof(__le16)? It's not a checkpatch error, but I feel like I've seen coccichecks or coccinelle script patches repairing these misuses of sizeof
See what you think, group reply with questions, and we'll get to the bottom of this one soon!
Thanks,
alisons
Quoted 70 lines · Alison Schofield
Quoted 54 lines · sayli karnik
Quoted 47 lines · Alison Schofield
Quoted 46 lines · sayli karnik
Quoted 45 lines · Alison Schofield
Quoted 24 lines · Lars-Peter Clausen
On 10/02/2016 07:00 AM, Alison Schofield wrote:
[...]Quoted 22 lines
Quoted 9 lines
--- drivers/iio/imu/bmi160/bmi160_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/iio/imu/bmi160/bmi160_core.c +0
-0drivers/iio/imu/bmi160/bmi160_core.c static irqreturn_t bmi160_trigger_handler(int irq, void *p) · line 404
Quoted 8 lines
drivers/iio/imu/bmi160/bmi160_core.c +2
-1@@ -398,7 +398,8 @@ static irqreturn_t bmi160_trigger_handler(int irq, void *p)struct iio_poll_func *pf = p;struct iio_dev *indio_dev = pf->indio_dev;struct bmi160_data *data =iio_priv (indio_dev); -s16 buf[16 ];/* 3 sens x 3 axis x s16 + 3 x s16 pad + 4 x s16 tstamp */ +__le16 buf[16 ]; +/* 3 sens x 3 axis x __le16 + 3 x __le16 pad + 4 x __le16 tstamp */ int i, ret, j =0 , base =BMI160_REG_DATA_MAGN_XOUT_L ;__le16 sample;Wondering about this option below. Data was read into an
__le16, so that was good diligence on drivers part. Seems we can usele16_to_cpu()for the conversion into the buf.Quoted 13 lines
drivers/iio/imu/bmi160/bmi160_core.c static irqreturn_t bmi160_trigger_handler(int irq, void *p) · line 412
Quoted 9 lines
drivers/iio/imu/bmi160/bmi160_core.c +1
-1@@ -408,7 +408,7 @@ static irqreturn_t bmi160_trigger_handler(int irq, void *p) &sample, sizeof(__le16));if (ret <0 ) goto done; - buf[j++] = sample; + buf[j++] =le16_to_cpu (sample); }This conversion is usually skipped on purpose and delayed until it is actually needed by the user. The IIO channel is accordingly marked that it will produce LE data.
Thanks Lars. I knew that for buffers, overlooked it, now I'll know it better!
So, Sayli, you probably got this from the analysis of the last patch. In buffered mode, we'll go ahead and return the data in it's 'native' order. So, my suggestion to convert it here, is wrong. Ignore ;)
Quoted 5 lines
Quoted 2 lines
Oh I see! So should I resend the patch with an updated description?(cosmetic/bug fix)
Yes. In the commit message, you can leave out the subdirs (imu: bmc160:) so that you have more space for a descriptive message of the change.
Quoted 8 lines
A quick question about this being a bug fix or not. This would have worked fine on little endian systems. But wouldn't the byte order have changed in case of a big endian buffer, when the little endian samples are stored in it?
If not, then this will be a cosmetic patch.thanks,
sayliHi Sayli,
Pulling linux-iio back in. Once we've started group thread, we need to keep replying to 'all'. It helps those invested in this particular patch, and also helps those who search in the future with similar issues.
Quoted 7 lines
To answer your question. I say cosmetic, because the le16 is going into a 16bit buf element, and is labelled as
IIO_LEin the channel buffer definition. That's why Lars was saying we don't need to do any conversion. We'll pass the bits as they came in, and tell the readers of the buf that they are in little endian format. (And, also note we weren't truncating any as was the case in your first endian fix.)
Noted!
Quoted 3 lines
OK - having said that, I stare at this code more, and wonder why we are even bothering to label the sample as
__le16, and whether we should just label it as s16.
Oh, in that case we could make both buf and sample s16.
Also, I'm wondering about the use
Quoted 4 lines
of
sizeof(). Shouldn't we be saying sizeof(sample) notsizeof(__le16)? It's not a checkpatch error, but I feel like I've seen coccichecks or coccinelle script patches repairing these misuses of sizeof
Yes sizeof(variable) instead of sizeof(type) makes code resistant to future type changes.
Quoted 6 lines
See what you think, group reply with questions, and we'll get to the bottom of this one soon!
Thanks,
alisons
Jonathan Cameron
maintainerQuoted 78 lines · sayli karnik
Quoted 70 lines · Alison Schofield
Quoted 54 lines · sayli karnik
Quoted 47 lines · Alison Schofield
Quoted 46 lines · sayli karnik
Quoted 45 lines · Alison Schofield
Quoted 24 lines · Lars-Peter Clausen
On 10/02/2016 07:00 AM, Alison Schofield wrote:
[...]Quoted 22 lines
Quoted 9 lines
--- drivers/iio/imu/bmi160/bmi160_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/iio/imu/bmi160/bmi160_core.c +0
-0drivers/iio/imu/bmi160/bmi160_core.c static irqreturn_t bmi160_trigger_handler(int irq, void *p) · line 404
Quoted 8 lines
drivers/iio/imu/bmi160/bmi160_core.c +2
-1@@ -398,7 +398,8 @@ static irqreturn_t bmi160_trigger_handler(int irq, void *p)struct iio_poll_func *pf = p;struct iio_dev *indio_dev = pf->indio_dev;struct bmi160_data *data =iio_priv (indio_dev); -s16 buf[16 ];/* 3 sens x 3 axis x s16 + 3 x s16 pad + 4 x s16 tstamp */ +__le16 buf[16 ]; +/* 3 sens x 3 axis x __le16 + 3 x __le16 pad + 4 x __le16 tstamp */ int i, ret, j =0 , base =BMI160_REG_DATA_MAGN_XOUT_L ;__le16 sample;Wondering about this option below. Data was read into an
__le16, so that was good diligence on drivers part. Seems we can usele16_to_cpu()for the conversion into the buf.Quoted 13 lines
drivers/iio/imu/bmi160/bmi160_core.c static irqreturn_t bmi160_trigger_handler(int irq, void *p) · line 412
Quoted 9 lines
drivers/iio/imu/bmi160/bmi160_core.c +1
-1@@ -408,7 +408,7 @@ static irqreturn_t bmi160_trigger_handler(int irq, void *p) &sample, sizeof(__le16));if (ret <0 ) goto done; - buf[j++] = sample; + buf[j++] =le16_to_cpu (sample); }This conversion is usually skipped on purpose and delayed until it is actually needed by the user. The IIO channel is accordingly marked that it will produce LE data.
Thanks Lars. I knew that for buffers, overlooked it, now I'll know it better!
So, Sayli, you probably got this from the analysis of the last patch. In buffered mode, we'll go ahead and return the data in it's 'native' order. So, my suggestion to convert it here, is wrong. Ignore ;)
Quoted 5 lines
Quoted 2 lines
Oh I see! So should I resend the patch with an updated description?(cosmetic/bug fix)
Yes. In the commit message, you can leave out the subdirs (imu: bmc160:) so that you have more space for a descriptive message of the change.
Quoted 8 lines
A quick question about this being a bug fix or not. This would have worked fine on little endian systems. But wouldn't the byte order have changed in case of a big endian buffer, when the little endian samples are stored in it?
If not, then this will be a cosmetic patch.thanks,
sayliHi Sayli,
Pulling linux-iio back in. Once we've started group thread, we need to keep replying to 'all'. It helps those invested in this particular patch, and also helps those who search in the future with similar issues.Quoted 7 lines
To answer your question. I say cosmetic, because the le16 is going into a 16bit buf element, and is labelled as
IIO_LEin the channel buffer definition. That's why Lars was saying we don't need to do any conversion. We'll pass the bits as they came in, and tell the readers of the buf that they are in little endian format. (And, also note we weren't truncating any as was the case in your first endian fix.)
Quoted 7 lines
Noted!
Quoted 3 lines
OK - having said that, I stare at this code more, and wonder why we are even bothering to label the sample as
__le16, and whether we should just label it as s16.Oh, in that case we could make both buf and sample s16.
I actually fall just the other way. They are little endian so we should mark them as such, whether or not we are going to do any conversions on them in kernel. It acts as a form of documentation and makes it a little more obvious what the code is doing. It gets vaguer with buffer as that is a mixed endian beast. If you really want that one right you could use a structure, but honestly it's not worth the hassle.
Quoted 8 lines
Also, I'm wondering about the use
Quoted 4 lines
of
sizeof(). Shouldn't we be saying sizeof(sample) notsizeof(__le16)? It's not a checkpatch error, but I feel like I've seen coccichecks or coccinelle script patches repairing these misuses of sizeofYes sizeof(variable) instead of sizeof(type) makes code resistant to future type changes.
Absolutely (I missed that in the original reviews!)
Jonathan
Quoted 12 lines
Quoted 7 lines
See what you think, group reply with questions, and we'll get to the bottom of this one soon!
Thanks,
alisons--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 95 lines · Jonathan Cameron
Quoted 78 lines · sayli karnik
Quoted 70 lines · Alison Schofield
Quoted 54 lines · sayli karnik
Quoted 47 lines · Alison Schofield
Quoted 46 lines · sayli karnik
Quoted 45 lines · Alison Schofield
Quoted 24 lines · Lars-Peter Clausen
On 10/02/2016 07:00 AM, Alison Schofield wrote:
[...]Quoted 22 lines
Quoted 9 lines
--- drivers/iio/imu/bmi160/bmi160_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/iio/imu/bmi160/bmi160_core.c +0
-0drivers/iio/imu/bmi160/bmi160_core.c static irqreturn_t bmi160_trigger_handler(int irq, void *p) · line 404
Quoted 8 lines
drivers/iio/imu/bmi160/bmi160_core.c +2
-1@@ -398,7 +398,8 @@ static irqreturn_t bmi160_trigger_handler(int irq, void *p)struct iio_poll_func *pf = p;struct iio_dev *indio_dev = pf->indio_dev;struct bmi160_data *data =iio_priv (indio_dev); -s16 buf[16 ];/* 3 sens x 3 axis x s16 + 3 x s16 pad + 4 x s16 tstamp */ +__le16 buf[16 ]; +/* 3 sens x 3 axis x __le16 + 3 x __le16 pad + 4 x __le16 tstamp */ int i, ret, j =0 , base =BMI160_REG_DATA_MAGN_XOUT_L ;__le16 sample;Wondering about this option below. Data was read into an
__le16, so that was good diligence on drivers part. Seems we can usele16_to_cpu()for the conversion into the buf.Quoted 13 lines
drivers/iio/imu/bmi160/bmi160_core.c static irqreturn_t bmi160_trigger_handler(int irq, void *p) · line 412
Quoted 9 lines
drivers/iio/imu/bmi160/bmi160_core.c +1
-1@@ -408,7 +408,7 @@ static irqreturn_t bmi160_trigger_handler(int irq, void *p) &sample, sizeof(__le16));if (ret <0 ) goto done; - buf[j++] = sample; + buf[j++] =le16_to_cpu (sample); }This conversion is usually skipped on purpose and delayed until it is actually needed by the user. The IIO channel is accordingly marked that it will produce LE data.
Thanks Lars. I knew that for buffers, overlooked it, now I'll know it better!
So, Sayli, you probably got this from the analysis of the last patch. In buffered mode, we'll go ahead and return the data in it's 'native' order. So, my suggestion to convert it here, is wrong. Ignore ;)
Quoted 5 lines
Quoted 2 lines
Oh I see! So should I resend the patch with an updated description?(cosmetic/bug fix)
Yes. In the commit message, you can leave out the subdirs (imu: bmc160:) so that you have more space for a descriptive message of the change.
Quoted 8 lines
A quick question about this being a bug fix or not. This would have worked fine on little endian systems. But wouldn't the byte order have changed in case of a big endian buffer, when the little endian samples are stored in it?
If not, then this will be a cosmetic patch.thanks,
sayliHi Sayli,
Pulling linux-iio back in. Once we've started group thread, we need to keep replying to 'all'. It helps those invested in this particular patch, and also helps those who search in the future with similar issues.Quoted 7 lines
To answer your question. I say cosmetic, because the le16 is going into a 16bit buf element, and is labelled as
IIO_LEin the channel buffer definition. That's why Lars was saying we don't need to do any conversion. We'll pass the bits as they came in, and tell the readers of the buf that they are in little endian format. (And, also note we weren't truncating any as was the case in your first endian fix.)Quoted 7 lines
Noted!
Quoted 3 lines
OK - having said that, I stare at this code more, and wonder why we are even bothering to label the sample as
__le16, and whether we should just label it as s16.Oh, in that case we could make both buf and sample s16.
I actually fall just the other way. They are little endian so we should mark them as such, whether or not we are going to do any conversions on them in kernel. It acts as a form of documentation and makes it a little more obvious what the code is doing. It gets vaguer with buffer as that is a mixed endian beast. If you really want that one right you could use a structure, but honestly it's not worth the hassle.
Quoted 1 line
Quoted 9 lines
Quoted 7 lines
Also, I'm wondering about the use
Quoted 4 lines
of
sizeof(). Shouldn't we be saying sizeof(sample) notsizeof(__le16)? It's not a checkpatch error, but I feel like I've seen coccichecks or coccinelle script patches repairing these misuses of sizeofYes sizeof(variable) instead of sizeof(type) makes code resistant to future type changes.
Absolutely (I missed that in the original reviews!)
I have sent an updated patch, but forgot to mention the version. Does this comment make sense with __le16 instead of s16? /* 3 sens x 3 axis x __le16 + 3 x __le16 pad + 4 x __le16 tstamp */
thanks,
sayli
Quoted 14 lines
Jonathan
Quoted 12 lines
Quoted 7 lines
See what you think, group reply with questions, and we'll get to the bottom of this one soon!
Thanks,
alisons--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 101 lines · sayli karnik
Quoted 100 lines · Jonathan Cameron
Quoted 78 lines · sayli karnik
Quoted 70 lines · Alison Schofield
Quoted 54 lines · sayli karnik
Quoted 47 lines · Alison Schofield
Quoted 46 lines · sayli karnik
Quoted 45 lines · Alison Schofield
Quoted 24 lines · Lars-Peter Clausen
On 10/02/2016 07:00 AM, Alison Schofield wrote:
[...]Quoted 22 lines
Quoted 9 lines
--- drivers/iio/imu/bmi160/bmi160_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/iio/imu/bmi160/bmi160_core.c +0
-0drivers/iio/imu/bmi160/bmi160_core.c static irqreturn_t bmi160_trigger_handler(int irq, void *p) · line 404
Quoted 8 lines
drivers/iio/imu/bmi160/bmi160_core.c +2
-1@@ -398,7 +398,8 @@ static irqreturn_t bmi160_trigger_handler(int irq, void *p)struct iio_poll_func *pf = p;struct iio_dev *indio_dev = pf->indio_dev;struct bmi160_data *data =iio_priv (indio_dev); -s16 buf[16 ];/* 3 sens x 3 axis x s16 + 3 x s16 pad + 4 x s16 tstamp */ +__le16 buf[16 ]; +/* 3 sens x 3 axis x __le16 + 3 x __le16 pad + 4 x __le16 tstamp */ int i, ret, j =0 , base =BMI160_REG_DATA_MAGN_XOUT_L ;__le16 sample;Wondering about this option below. Data was read into an
__le16, so that was good diligence on drivers part. Seems we can usele16_to_cpu()for the conversion into the buf.Quoted 13 lines
drivers/iio/imu/bmi160/bmi160_core.c static irqreturn_t bmi160_trigger_handler(int irq, void *p) · line 412
Quoted 9 lines
drivers/iio/imu/bmi160/bmi160_core.c +1
-1@@ -408,7 +408,7 @@ static irqreturn_t bmi160_trigger_handler(int irq, void *p) &sample, sizeof(__le16));if (ret <0 ) goto done; - buf[j++] = sample; + buf[j++] =le16_to_cpu (sample); }This conversion is usually skipped on purpose and delayed until it is actually needed by the user. The IIO channel is accordingly marked that it will produce LE data.
Thanks Lars. I knew that for buffers, overlooked it, now I'll know it better!
So, Sayli, you probably got this from the analysis of the last patch. In buffered mode, we'll go ahead and return the data in it's 'native' order. So, my suggestion to convert it here, is wrong. Ignore ;)
Quoted 5 lines
Quoted 2 lines
Oh I see! So should I resend the patch with an updated description?(cosmetic/bug fix)
Yes. In the commit message, you can leave out the subdirs (imu: bmc160:) so that you have more space for a descriptive message of the change.
Quoted 8 lines
A quick question about this being a bug fix or not. This would have worked fine on little endian systems. But wouldn't the byte order have changed in case of a big endian buffer, when the little endian samples are stored in it?
If not, then this will be a cosmetic patch.thanks,
sayliHi Sayli,
Pulling linux-iio back in. Once we've started group thread, we need to keep replying to 'all'. It helps those invested in this particular patch, and also helps those who search in the future with similar issues.Quoted 7 lines
To answer your question. I say cosmetic, because the le16 is going into a 16bit buf element, and is labelled as
IIO_LEin the channel buffer definition. That's why Lars was saying we don't need to do any conversion. We'll pass the bits as they came in, and tell the readers of the buf that they are in little endian format. (And, also note we weren't truncating any as was the case in your first endian fix.)Quoted 7 lines
Noted!
Quoted 3 lines
OK - having said that, I stare at this code more, and wonder why we are even bothering to label the sample as
__le16, and whether we should just label it as s16.Oh, in that case we could make both buf and sample s16.
I actually fall just the other way. They are little endian so we should mark them as such, whether or not we are going to do any conversions on them in kernel. It acts as a form of documentation and makes it a little more obvious what the code is doing. It gets vaguer with buffer as that is a mixed endian beast. If you really want that one right you could use a structure, but honestly it's not worth the hassle.
Quoted 6 lines
Also, I'm wondering about the use
Quoted 4 lines
of
sizeof(). Shouldn't we be saying sizeof(sample) notsizeof(__le16)? It's not a checkpatch error, but I feel like I've seen coccichecks or coccinelle script patches repairing these misuses of sizeof
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Yes sizeof(variable) instead of sizeof(type) makes code resistant to future type changes.
Absolutely (I missed that in the original reviews!)
I have sent an updated patch, but forgot to mention the version. Does this comment make sense with
__le16instead of s16? /* 3 sens x 3 axis x__le16+ 3 x__le16pad + 4 x__le16tstamp */
Yup, it makes sense if you change to type of the buf. Anyhow, place put it above the declaration of buf.
Daniel.