On 10/5/23 20:01, Jonathan Cameron wrote: > On Thu, 5 Oct 2023 13:59:22 +0300 > Dumitru Ceclan <mitrutzceclan@xxxxxxxxx> 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@xxxxxxxxxxxxxxx/msg2382960.html Is this it?