linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ceclan Dumitru-Ioan <mitrutzceclan@gmail.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: linus.walleij@linaro.org, brgl@bgdev.pl, andy@kernel.org,
	linux-gpio@vger.kernel.org,
	"Lars-Peter Clausen" <lars@metafoo.de>,
	"Rob Herring" <robh+dt@kernel.org>,
	"Krzysztof Kozlowski" <krzysztof.kozlowski+dt@linaro.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"Michael Walle" <michael@walle.cc>,
	"Andy Shevchenko" <andy.shevchenko@gmail.com>,
	"Arnd Bergmann" <arnd@arndb.de>,
	"ChiaEn Wu" <chiaen_wu@richtek.com>,
	"Niklas Schnelle" <schnelle@linux.ibm.com>,
	"Leonard Göhrs" <l.goehrs@pengutronix.de>,
	"Mike Looijmans" <mike.looijmans@topic.nl>,
	"Haibo Chen" <haibo.chen@nxp.com>,
	"Hugo Villeneuve" <hvilleneuve@dimonoff.com>,
	"Ceclan Dumitru" <dumitru.ceclan@analog.com>,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v3 2/2] iio: adc: ad7173: add AD7173 driver
Date: Fri, 6 Oct 2023 17:18:36 +0300	[thread overview]
Message-ID: <07afa29c-bfef-72dc-d471-f72dfcebe342@gmail.com> (raw)
In-Reply-To: <20231005180131.0518f46c@jic23-huawei>

On 10/5/23 20:01, Jonathan Cameron wrote:
> On Thu,  5 Oct 2023 13:59:22 +0300
> Dumitru Ceclan <mitrutzceclan@gmail.com> wrote:
> 
>> The AD7173 family offer a complete integrated Sigma-Delta ADC solution
>> which can be used in high precision, low noise single channel
>> applications or higher speed multiplexed applications. The Sigma-Delta
>> ADC is intended primarily for measurement of signals close to DC but also
>> delivers outstanding performance with input bandwidths out to ~10kHz.
>>

...

>> +	case IIO_CHAN_INFO_RAW:
>> +		ret = ad_sigma_delta_single_conversion(indio_dev, chan, val);
> 
> It's fairly usual for it to be safe to grab a single conversion when the
> buffered mode might be enabled.  Do you need an iio_device_claim_direct_mode()
> here?
> 
ad_sigma_delta_single_conversion() calls iio_device_claim_direct_mode()


>> +static int ad7173_update_scan_mode(struct iio_dev *indio_dev,
>> +				   const unsigned long *scan_mask)
>> +{
>> +	struct ad7173_state *st = iio_priv(indio_dev);
>> +	int i, ret = 0;
>> +
>> +	iio_device_claim_direct_mode(indio_dev);
> 
> This looks wrong.
> Firstly iio_device_claim_direct_mode() can fail so you always have
> to check the return value. If it does fail and you then call
> iio_release_direct_mode() it is unbalanced release of a mutex.
> 
> Secondly update_scan_mode is only called as part of buffer setup
> and there should be no races around that (and the mutex this
> tries to grab is already held.
> https://elixir.bootlin.com/linux/latest/source/drivers/iio/industrialio-buffer.c#L1265
> )
> 
> If you are protecting something device specific (rather than
> the mode) then a device specific lock should be taken.
> 

The use of a lock was inspired from ad7124, but from looking at it the only use it has
was to protect concurrent access of the device setup from write_raw (that now uses ...direct_mode())

I think it's best to drop this lock. 


>> +		chan[chan_index].differential = fwnode_property_read_bool(child, "bipolar");
> 
> bipolar doesn't normally == differential. 
> You can have unipolar differential (just that you can't get a negative answer)
> Perhaps just a terminology thing?
>

This device supports only differential channels. Here, the differential flag is used to show
if bipolar coding should be used.


>> +	st->info = device_get_match_data(dev);
>> +	if (!st->info)
>> +		return -ENODEV;
> This works for the cases of DT and ACPI but not for anyone just
> using the spi_device_id table. 
> There is spi_device_get_match_data() to cover all options.
> 
I could not find the spi_device_get_match_data() function in the repo.
It appears however as a suggestion from Andy Shevchenko in a thread:
https://www.mail-archive.com/linux-kernel@vger.kernel.org/msg2382960.html
 Is this it? 

  reply	other threads:[~2023-10-06 14:18 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-05 10:59 [PATCH v3 1/2] dt-bindings: adc: add AD7173 Dumitru Ceclan
2023-10-05 10:59 ` [PATCH v3 2/2] iio: adc: ad7173: add AD7173 driver Dumitru Ceclan
2023-10-05 17:01   ` Jonathan Cameron
2023-10-06 14:18     ` Ceclan Dumitru-Ioan [this message]
2023-10-10 10:26       ` Jonathan Cameron
2023-10-09  7:42   ` Michael Walle
2023-10-05 16:40 ` [PATCH v3 1/2] dt-bindings: adc: add AD7173 Jonathan Cameron
2023-10-05 23:34 ` Conor Dooley

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=07afa29c-bfef-72dc-d471-f72dfcebe342@gmail.com \
    --to=mitrutzceclan@gmail.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=andy@kernel.org \
    --cc=arnd@arndb.de \
    --cc=brgl@bgdev.pl \
    --cc=chiaen_wu@richtek.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dumitru.ceclan@analog.com \
    --cc=haibo.chen@nxp.com \
    --cc=hvilleneuve@dimonoff.com \
    --cc=jic23@kernel.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=l.goehrs@pengutronix.de \
    --cc=lars@metafoo.de \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michael@walle.cc \
    --cc=mike.looijmans@topic.nl \
    --cc=robh+dt@kernel.org \
    --cc=schnelle@linux.ibm.com \
    /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;
as well as URLs for NNTP newsgroup(s).