Linux IIO development
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Lars-Peter Clausen <lars@metafoo.de>
Cc: Gwendal Grignou <gwendal@chromium.org>,
	swboyd@chromium.org, andy.shevchenko@gmail.com,
	linux-iio@vger.kernel.org
Subject: Re: [PATCH 1/5] iio: Use .realbits to extend a small signed integer
Date: Sat, 30 Oct 2021 17:09:03 +0100	[thread overview]
Message-ID: <20211030170903.68b7e561@jic23-huawei> (raw)
In-Reply-To: <c71a2781-f5f6-0725-dbdf-aaa823883be1@metafoo.de>

On Sat, 30 Oct 2021 13:35:19 +0200
Lars-Peter Clausen <lars@metafoo.de> wrote:

> On 10/30/21 1:18 PM, Gwendal Grignou wrote:
> > When calling sign_extend32() on a channel, use its .realbit information
> > to limit the number of bits to process, instead of a constant.
> >
> > Changed only simple sign_extend32() calls, when .realbits was defined in
> > the same file. Use 'grep -r sign_extend32 $(grep -lr realbits drivers/iio/)'
> > to locate the files.
> >
> > Some files were not processed:
> > gyro/fxas21002c_core.c : function parameter changes needed.
> > health/max30102.c: Incomplete channel definition.
> > health/max30100.c  
> 
> I think this is good work, but it seems a bit out of place in this 
> series. I think it will be easier to get this reviewed and merged if it 
> is submitted independently. It might make sense to only have the sx9310 
> changes as part of this series and send the other ones as a separate patch.
> 
> What's also missing in the commit description is the motivation for 
> this. The generated code will be a bit more complex, so there needs to 
> be a good justification. E.g. having a single source of truth for this 
> data and avoiding accidental mistakes.
> 
> The patch also uses `shift` were applicable, which is not mentioned in 
> the commit dscription.

Be careful.  I have seen devices (with FIFOs) where the realbits doesn't
necessarily match with a separate read path used for polled reads.

It is an option for the sca3000 for example but that's carrying a hack where
ignore that and rely on some coincidental data alignment to pretend realbits
is 13 when it's actually 11.

Still in general it's a reasonable change but agree with Lars, separate series
please.
 
> 
> 
> > [...]
> > diff --git a/drivers/iio/pressure/mpl3115.c b/drivers/iio/pressure/mpl3115.c
> > index 1eb9e7b29e050..355854f0f59d2 100644
> > --- a/drivers/iio/pressure/mpl3115.c
> > +++ b/drivers/iio/pressure/mpl3115.c
> > @@ -74,7 +74,7 @@ static int mpl3115_read_raw(struct iio_dev *indio_dev,
> >   			    int *val, int *val2, long mask)
> >   {
> >   	struct mpl3115_data *data = iio_priv(indio_dev);
> > -	__be32 tmp = 0;
> > +	__be16 tmp = 0;
> >   	int ret;  
> The be32 to be16 change might warrant its own patch. This is definitely 
> changing the behavior of the driver. And I don't think it is correct the 
> way its done. For the pressure data it is reading 3 bytes, which will 
> cause a stack overflow.
> >   
> >   	switch (mask) {
> > @@ -96,7 +96,7 @@ static int mpl3115_read_raw(struct iio_dev *indio_dev,
> >   			mutex_unlock(&data->lock);
> >   			if (ret < 0)
> >   				break;
> > -			*val = be32_to_cpu(tmp) >> 12;
> > +			*val = be32_to_cpu(tmp) >> chan->scan_type.shift;
> >   			ret = IIO_VAL_INT;
> >   			break;
> >   		case IIO_TEMP: /* in 0.0625 celsius / LSB */
> > @@ -111,7 +111,8 @@ static int mpl3115_read_raw(struct iio_dev *indio_dev,
> >   			mutex_unlock(&data->lock);
> >   			if (ret < 0)
> >   				break;
> > -			*val = sign_extend32(be32_to_cpu(tmp) >> 20, 11);
> > +			*val = sign_extend32(be16_to_cpu(tmp) >> chan->scan_type.shift,
> > +					     chan->scan_type.realbits - 1);
> >   			ret = IIO_VAL_INT;
> >   			break;
> >   		default:  
> 


  reply	other threads:[~2021-10-30 16:04 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-30 11:18 [PATCH 0/5] Expand Semtech SAR Sensors support Gwendal Grignou
2021-10-30 11:18 ` [PATCH 1/5] iio: Use .realbits to extend a small signed integer Gwendal Grignou
2021-10-30 11:35   ` Lars-Peter Clausen
2021-10-30 16:09     ` Jonathan Cameron [this message]
2021-11-01  7:30       ` Gwendal Grignou
2021-10-30 11:18 ` [PATCH 2/5] iio: sx9310: Extract common Semtech sensor logic Gwendal Grignou
2021-10-30 11:40   ` Lars-Peter Clausen
2021-10-30 16:42   ` Jonathan Cameron
2021-10-30 11:18 ` [PATCH 3/5] iio: proximity: Add SX9324 support Gwendal Grignou
2021-10-30 11:56   ` Lars-Peter Clausen
2021-10-30 17:04   ` Jonathan Cameron
2021-11-04  7:15     ` Gwendal Grignou
2021-11-04 18:15       ` Jonathan Cameron
2021-10-30 11:18 ` [PATCH 4/5] dt-bindings: iio: Add sx9324 binding Gwendal Grignou
2021-10-30 17:24   ` Jonathan Cameron
2021-11-04  7:16     ` Gwendal Grignou
2021-11-04 18:13       ` Jonathan Cameron
2021-10-30 11:18 ` [PATCH 5/5] iio: sx9324: Add dt_bidding support Gwendal Grignou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211030170903.68b7e561@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=andy.shevchenko@gmail.com \
    --cc=gwendal@chromium.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=swboyd@chromium.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox