mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Michael Hennerich <michael.hennerich@analog.com>
To: Lars-Peter Clausen <lars@metafoo.de>, <jic23@kernel.org>,
	<knaack.h@gmx.de>, <pmeerw@pmeerw.net>, <robh+dt@kernel.org>,
	<mark.rutland@arm.com>
Cc: <linux-iio@vger.kernel.org>, <devicetree@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] iio/adc/ltc2497: Driver for Linear Technology LTC2497 ADC
Date: Wed, 29 Mar 2017 10:51:57 +0200	[thread overview]
Message-ID: <025f8461-c823-1f07-5742-e488c3e34f9f@analog.com> (raw)
In-Reply-To: <6774c073-7fe4-e259-306e-3cf4621f7c69@metafoo.de>

On 23.03.2017 12:05, Lars-Peter Clausen wrote:

Sorry - I missed some of this review feedback ...

>> +
>> +static int ltc2497_wait_conv(struct ltc2497_st *st)
>> +{
>> +	s64 time_elapsed;
>> +
>> +	time_elapsed = ktime_ms_delta(ktime_get(), st->time_prev);
>> +
>> +	if (time_elapsed < LTC2497_CONVERSION_TIME_MS) {
>> +		/* delay if conversion time not passed
>> +		 * since last read or write
>> +		 */
>> +		msleep(LTC2497_CONVERSION_TIME_MS - time_elapsed);
>
> Considering how long this sleeps msleep_interruptible() might be the better
> choice.

Wondering what should be the outcome of this?
We can't simply replace it. Actually I've seen cases here in drivers/iio 
where the delay is essential, but the return value of 
msleep_interruptible() is not being checked.
Thus causing a malicious access, in case a signal is received.

We must delay here. If we switch to msleep_interruptible() the only 
reason for this would be to cancel the read and return -EINTR to the user.

Also there is another msleep below which would also need this kind of 
handling.

>
>> +		return 0;
>> +	}
>> +
>> +	if (time_elapsed - LTC2497_CONVERSION_TIME_MS <= 0) {
>> +		/* We're in automatic mode -
>> +		 * so the last reading is stil not outdated
>> +		 */
>> +		return 0;
>> +	}
>> +
>> +	return -ETIMEDOUT;
>> +}
>> +
>> +static int ltc2497_read(struct ltc2497_st *st, u8 address, int *val)
>> +{
>> +	struct i2c_client *client = st->client;
>> +	__be32 buf = 0;
>
> transfer buffers must not be on the stack to avoid issues if the controller
> should use DMA.
>
>> +	int ret;
>> +
>> +	ret = ltc2497_wait_conv(st);
>> +	if (ret < 0 || st->addr_prev != address) {
>> +		ret = i2c_smbus_write_byte(st->client, 0xA0 | address);
>> +		if (ret < 0)
>> +			return ret;
>> +		st->addr_prev = address;
>> +		msleep(LTC2497_CONVERSION_TIME_MS);
>> +	}
>> +	ret = i2c_master_recv(client, (char *)&buf, 3);
>> +	if (ret < 0)  {
>> +		dev_err(&client->dev, "i2c_master_recv failed\n");
>> +		return ret;
>> +	}
>> +	st->time_prev = ktime_get();
>> +	*val = (be32_to_cpu(buf) >> 14) - (1 << 17);
>> +
>> +	return ret;
>> +}
> [...]
>


-- 
Greetings,
Michael

--
Analog Devices GmbH      Otl-Aicher Strasse 60-64      80807 München
Sitz der Gesellschaft München, Registergericht München HRB 40368,
Geschäftsführer: Peter Kolberg, Ali Raza Husain, Eileen Wynne

  reply	other threads:[~2017-03-29  8:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-23 10:35 michael.hennerich
2017-03-23 11:05 ` Lars-Peter Clausen
2017-03-29  8:51   ` Michael Hennerich [this message]
2017-03-23 11:28 ` Peter Meerwald-Stadler
2017-03-23 14:45   ` Michael Hennerich

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=025f8461-c823-1f07-5742-e488c3e34f9f@analog.com \
    --to=michael.hennerich@analog.com \
    --cc=devicetree@vger.kernel.org \
    --cc=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=pmeerw@pmeerw.net \
    --cc=robh+dt@kernel.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

all inboxes | Powered by JetHome®