Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iio: adc: ad4030: don't store scan_type in state

Move getting the scan_type to ad4030_conversion(). Previously, we were
getting the scan_type in two other places, then storing it in the
state struct before using it in ad4030_conversion(). This was a bit
fragile against potential future changes since it isn't obvious that
anything that could potentially change the scan_type would need to
also update the state struct. Also, the non-obviousness of this led to
a redundant call to iio_get_current_scan_type() in
ad4030_single_conversion() since it also calls ad4030_set_mode() which
in turn calls ad4030_conversion().

To simplify things, just call iio_get_current_scan_type() in
ad4030_conversion() where the returned struct is actually used and
don't bother storing it in the state struct.

Signed-off-by: David Lechner <dlechner@baylibre.com>
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Link: https://patch.msgid.link/20250310-iio-adc-ad4030-check-scan-type-err-v1-4-589e4ebd9711@baylibre.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

David Lechner and committed by
Jonathan Cameron
15ffee89 efaa981e

+9 -15
+9 -15
drivers/iio/adc/ad4030.c
··· 147 147 struct spi_device *spi; 148 148 struct regmap *regmap; 149 149 const struct ad4030_chip_info *chip; 150 - const struct iio_scan_type *current_scan_type; 151 150 struct gpio_desc *cnv_gpio; 152 151 int vref_uv; 153 152 int vio_uv; ··· 561 562 st->mode = AD4030_OUT_DATA_MD_DIFF; 562 563 } 563 564 564 - st->current_scan_type = iio_get_current_scan_type(indio_dev, 565 - st->chip->channels); 566 - if (IS_ERR(st->current_scan_type)) 567 - return PTR_ERR(st->current_scan_type); 568 - 569 565 return regmap_update_bits(st->regmap, AD4030_REG_MODES, 570 566 AD4030_REG_MODES_MASK_OUT_DATA_MODE, 571 567 st->mode); ··· 608 614 static int ad4030_conversion(struct iio_dev *indio_dev) 609 615 { 610 616 struct ad4030_state *st = iio_priv(indio_dev); 611 - unsigned char diff_realbytes = 612 - BITS_TO_BYTES(st->current_scan_type->realbits); 613 - unsigned char diff_storagebytes = 614 - BITS_TO_BYTES(st->current_scan_type->storagebits); 617 + const struct iio_scan_type *scan_type; 618 + unsigned char diff_realbytes, diff_storagebytes; 615 619 unsigned int bytes_to_read; 616 620 unsigned long cnv_nb = BIT(st->avg_log2); 617 621 unsigned int i; 618 622 int ret; 623 + 624 + scan_type = iio_get_current_scan_type(indio_dev, st->chip->channels); 625 + if (IS_ERR(scan_type)) 626 + return PTR_ERR(scan_type); 627 + 628 + diff_realbytes = BITS_TO_BYTES(scan_type->realbits); 629 + diff_storagebytes = BITS_TO_BYTES(scan_type->storagebits); 619 630 620 631 /* Number of bytes for one differential channel */ 621 632 bytes_to_read = diff_realbytes; ··· 671 672 ret = ad4030_set_mode(indio_dev, BIT(chan->scan_index)); 672 673 if (ret) 673 674 return ret; 674 - 675 - st->current_scan_type = iio_get_current_scan_type(indio_dev, 676 - st->chip->channels); 677 - if (IS_ERR(st->current_scan_type)) 678 - return PTR_ERR(st->current_scan_type); 679 675 680 676 ret = ad4030_conversion(indio_dev); 681 677 if (ret)