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

iio: adc: ad7768-1: Move buffer allocation to a separate function

This change moves the buffer allocation and related trigger allocation
in a separate function, making space for adding another type of iio
buffer if needed.

Reviewed-by: Marcelo Schmitt <marcelo.schmitt@analog.com>
Reviewed-by: David Lechner <dlechner@baylibre.com>
Signed-off-by: Sergiu Cuciurean <sergiu.cuciurean@analog.com>
Signed-off-by: Jonathan Santos <Jonathan.Santos@analog.com>
Link: https://patch.msgid.link/11c1777b406875ce1a7216dc4b094ff99af8da7f.1744325346.git.Jonathan.Santos@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Sergiu Cuciurean and committed by
Jonathan Cameron
ef24ea86 1fa0f4ea

+26 -18
+26 -18
drivers/iio/adc/ad7768-1.c
··· 619 619 return 0; 620 620 } 621 621 622 + static int ad7768_triggered_buffer_alloc(struct iio_dev *indio_dev) 623 + { 624 + struct ad7768_state *st = iio_priv(indio_dev); 625 + int ret; 626 + 627 + st->trig = devm_iio_trigger_alloc(indio_dev->dev.parent, "%s-dev%d", 628 + indio_dev->name, 629 + iio_device_id(indio_dev)); 630 + if (!st->trig) 631 + return -ENOMEM; 632 + 633 + st->trig->ops = &ad7768_trigger_ops; 634 + iio_trigger_set_drvdata(st->trig, indio_dev); 635 + ret = devm_iio_trigger_register(indio_dev->dev.parent, st->trig); 636 + if (ret) 637 + return ret; 638 + 639 + indio_dev->trig = iio_trigger_get(st->trig); 640 + 641 + return devm_iio_triggered_buffer_setup(indio_dev->dev.parent, indio_dev, 642 + &iio_pollfunc_store_time, 643 + &ad7768_trigger_handler, 644 + &ad7768_buffer_ops); 645 + } 646 + 622 647 static int ad7768_probe(struct spi_device *spi) 623 648 { 624 649 struct ad7768_state *st; ··· 714 689 return ret; 715 690 } 716 691 717 - st->trig = devm_iio_trigger_alloc(&spi->dev, "%s-dev%d", 718 - indio_dev->name, 719 - iio_device_id(indio_dev)); 720 - if (!st->trig) 721 - return -ENOMEM; 722 - 723 - st->trig->ops = &ad7768_trigger_ops; 724 - iio_trigger_set_drvdata(st->trig, indio_dev); 725 - ret = devm_iio_trigger_register(&spi->dev, st->trig); 726 - if (ret) 727 - return ret; 728 - 729 - indio_dev->trig = iio_trigger_get(st->trig); 730 - 731 692 init_completion(&st->completion); 732 693 733 694 ret = ad7768_set_channel_label(indio_dev, ARRAY_SIZE(ad7768_channels)); ··· 727 716 if (ret) 728 717 return ret; 729 718 730 - ret = devm_iio_triggered_buffer_setup(&spi->dev, indio_dev, 731 - &iio_pollfunc_store_time, 732 - &ad7768_trigger_handler, 733 - &ad7768_buffer_ops); 719 + ret = ad7768_triggered_buffer_alloc(indio_dev); 734 720 if (ret) 735 721 return ret; 736 722