lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20210604093243.fxyia23i5eq4y5c7@pengutronix.de>
Date:   Fri, 4 Jun 2021 11:32:43 +0200
From:   Uwe Kleine-König <u.kleine-koenig@...gutronix.de>
To:     "Li, Meng" <Meng.Li@...driver.com>
Cc:     Jonathan Cameron <jic23@...nel.org>,
        "lars@...afoo.de" <lars@...afoo.de>,
        "Michael.Hennerich@...log.com" <Michael.Hennerich@...log.com>,
        "pmeerw@...erw.net" <pmeerw@...erw.net>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        "linux-iio@...r.kernel.org" <linux-iio@...r.kernel.org>
Subject: Re: [PATCH] driver: adc: ltc2497: return directly after reading the
 adc conversion value

On Fri, Jun 04, 2021 at 09:04:48AM +0000, Li, Meng wrote:
> > On Fri, Jun 04, 2021 at 09:20:43AM +0100, Jonathan Cameron wrote:
> > > On Fri, 4 Jun 2021 06:43:20 +0000
> > > "Li, Meng" <Meng.Li@...driver.com> wrote:
> > > > > On Fri, Jun 04, 2021 at 02:16:39AM +0000, Li, Meng wrote:
> > > > > > I think the ret is essential.
> > > > >
> > > > > I'd like to understand why. Currently ltc2497core_read() looks as
> > > > > follows (simplified by dropping error handling, and unrolling the
> > > > > result_and_measure callback for the i2c case):
> > > > >
> > > > > 	ltc2497core_wait_conv()
> > > > >
> > > > > 	// result_and_measure(address, NULL)
> > > > > 	i2c_smbus_write_byte(client, LTC2497_ENABLE | address);
> > > > >
> > > > > 	msleep_interruptible(LTC2497_CONVERSION_TIME_MS)
> > > > >
> > > > > 	// result_and_measure(address, val);
> > > > > 	i2c_master_recv(client, &buf, 3);
> > > > > 	i2c_smbus_write_byte(client, LTC2497_ENABLE | address);
> > > > >
> > > > >
> > > > > With the early return you suggest to introduce with your patch you
> > > > > save the last i2c_smbus_write_byte call. The data sheet indeed
> > > > > claims to start a new conversion at the stop condition.
> > > > >
> > > > > So either the reading of the conversion result and programming of
> > > > > the
> > > > > (maybe) new address has to be done in a single i2c transfer, or we
> > > > > have to do something like your patch.
> > > > >
> > > > > What I don't like about your approach is that it changes the
> > > > > semantic of the callback to result_*or*_measure which is something
> > > > > the spi variant cannot implement. With the current use of the
> > > > > function this is fine, however if at some time in the future we
> > > > > implement a bulk conversion shortcut this hurts.
> > > > >
> > > > > So I suggest to do:
> > > > >
> > > > > ---->8----
> > > > > From: Uwe Kleine-König <u.kleine-koenig@...gutronix.de>
> > > > > Date: Fri, 4 Jun 2021 08:02:44 +0200
> > > > > Subject: [PATCH] iio: ltc2497: Fix reading conversion results
> > > > >
> > > > > After the result of the previous conversion is read the chip
> > > > > automatically starts a new conversion and doesn't accept new i2c
> > > > > transfers until this conversion is completed which makes the function return failure.
> > > > >
> > > > > So add an early return iff the programming of the new address isn't needed.
> > > > > Note this will not fix the problem in general, but all cases that
> > > > > are currently used. Once this changes we get the failure back, but
> > > > > this can be addressed when the need arises.
> > > > >
> > > > > Fixes: 69548b7c2c4f ("iio: adc: ltc2497: split protocol
> > > > > independent part in a separate module ")
> > > > > Reported-by: Meng Li <Meng.Li@...driver.com>
> > > > > Signed-off-by: Uwe Kleine-König <u.kleine-koenig@...gutronix.de>
> > > > > ---
> > > > >  drivers/iio/adc/ltc2497.c | 13 +++++++++++++
> > > > >  1 file changed, 13 insertions(+)
> > > > >
> > > > > diff --git a/drivers/iio/adc/ltc2497.c b/drivers/iio/adc/ltc2497.c
> > > > > --- a/drivers/iio/adc/ltc2497.c
> > > > > +++ b/drivers/iio/adc/ltc2497.c
> > > > > @@ -41,6 +41,19 @@ static int ltc2497_result_and_measure(struct
> > > > > ltc2497core_driverdata *ddata,
> > > > >  		}
> > > > >
> > > > >  		*val = (be32_to_cpu(st->buf) >> 14) - (1 << 17);
> > > > > +
> > > > > +		/*
> > > > > +		 * The part started a new conversion at the end of the above i2c
> > > > > +		 * transfer, so if the address didn't change since the last call
> > > > > +		 * everything is fine and we can return early.
> > > > > +		 * If not (which should only happen when some sort of bulk
> > > > > +		 * conversion is implemented) we have to program the new
> > > > > +		 * address. Note that this probably fails as the conversion that
> > > > > +		 * was triggered above is like not complete yet and the two
> > > > > +		 * operations have to be done in a single transfer.
> > > > > +		 */
> > >
> > > I'm a little confused by this comment.  It seems to say it will fail
> > > if we ever do have a different address?  That doesn't seem very helpful...
> > 
> > It's not a real problem in the sense that it triggers today. If you want to read
> > out (say) the channels 1, 5, 6 and 7, you could do:
> > 
> > 	start conversion for channel 1
> > 	wait for the conversion to complete
> > 	read out conversion for channel 1 and start channel 5
> > 	wait for the conversion to complete
> > 	read out conversion for channel 5 and start channel 6
> > 	wait for the conversion to complete
> > 	read out conversion for channel 6 and start channel 7
> > 	wait for the conversion to complete
> > 	read out conversion for channel 7
> 
> Have you tested above case on real hardware? Or only a inference based on data sheet?

I never had the ltc2497 in my hands, but the customer I created my
patches for uses the ltc2496 (i.e. its spi variant) and did the above
from userspace using spidev.

And I'm confident enough to claim that if your patch fixes your problem,
then mine does it, too.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

Download attachment "signature.asc" of type "application/pgp-signature" (489 bytes)

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ