iio: Convert IIO_CHAN_SOFT_TIMESTAMP() to be compound literal
PATCH 1/1 iio: Convert IIO_CHAN_SOFT_TIMESTAMP() to be compound literal
Currently IIO_CHAN_SOFT_TIMESTAMP() can only be used to fill the static data. In some cases it would be convenient to use it as right value in the assignment operation. But it can't be done as is, because compiler has no clue about the data layout. Converting it to be a compound literal allows the above mentioned usage.
While at it, tidy up the indentation.
---
v0: to be incorporated into David's series
include/linux/iio/iio.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
include/linux/iio/iio.h +3 -3
@@ -353,15 +353,15 @@ static inline bool iio_channel_has_available(const struct iio_chan_spec *chan, (chan->info_mask_shared_by_all_available &BIT (type)); } -#define IIO_CHAN_SOFT_TIMESTAMP (_si) { \ +#define IIO_CHAN_SOFT_TIMESTAMP (_si) (struct iio_chan_spec) { \ .type = IIO_TIMESTAMP, \ .channel = -1, \ .scan_index = _si, \ .scan_type = { \ .sign = 's', \ - .realbits = 64, \ + .realbits = 64, \ .storagebits = 64, \ - }, \ + }, \ }s64 iio_get_time_ns (const struct iio_dev *indio_dev);
Signature · 1 line
2.50.1
Quoted 6 lines · Andy Shevchenko
Currently
IIO_CHAN_SOFT_TIMESTAMP()can only be used to fill the static data. In some cases it would be convenient to use it as right value in the assignment operation. But it can't be done as is, because compiler has no clue about the data layout. Converting it to be a compound literal allows the above mentioned usage.
Quoted 6 lines
While at it, tidy up the indentation.
Signed-off-by Andy Shevchenko <[email protected]>---
v0: to be incorporated into David's series
Also may require to amend the drivers (at the same time) that use it inline
drivers/iio/adc/ad7606.c:1478drivers/iio/adc/max11410.c:807
to avoid potential compilation issues.
Signature · 2 lines
With Best Regards, Andy Shevchenko
kernel test robot
build botkernel test robot noticed the following build warnings:
Hi Andy,
kernel test robot noticed the following build warnings:
[auto build test WARNING on jic23-iio/togreg]
[also build test WARNING on linus/master v7.1-rc4 next-20260518] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Andy-Shevchenko/iio-Convert-IIO_CHAN_SOFT_TIMESTAMP-to-be-compound-literal/20260518-151541 base: https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg patch link: https://lore.kernel.org/r/20260518071349.469748-1-andriy.shevchenko%40linux.intel.com patch subject: [PATCH v0 1/1] iio: Convert IIO_CHAN_SOFT_TIMESTAMP() to be compound literal config: sparc64-randconfig-r132-20260518 (https://download.01.org/0day-ci/archive/20260519/[email protected]/config) compiler: clang version 23.0.0git (https://github.com/llvm/llvm-project 5bac06718f502014fade905512f1d26d578a18f3) sparse: v0.6.5-rc1 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260519/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
sparse warnings: (new ones prefixed by >>)
>> drivers/iio/adc/max11410.c:807:31: sparse: sparse: cast to non-scalar >> drivers/iio/adc/max11410.c:807:31: sparse: sparse: cast from non-scalar
vim +807 drivers/iio/adc/max11410.c
a44ef7c4609724e Ibrahim Tilki 2022-10-03 691
a44ef7c4609724e Ibrahim Tilki 2022-10-03 692 static int max11410_parse_channels(struct max11410_state *st,
a44ef7c4609724e Ibrahim Tilki 2022-10-03 693 struct iio_dev *indio_dev)
a44ef7c4609724e Ibrahim Tilki 2022-10-03 694 {
a44ef7c4609724e Ibrahim Tilki 2022-10-03 695 struct iio_chan_spec chanspec = chanspec_template;
a44ef7c4609724e Ibrahim Tilki 2022-10-03 696 struct device *dev = &st->spi_dev->dev;
a44ef7c4609724e Ibrahim Tilki 2022-10-03 697 struct max11410_channel_config *cfg;
a44ef7c4609724e Ibrahim Tilki 2022-10-03 698 struct iio_chan_spec *channels;
a44ef7c4609724e Ibrahim Tilki 2022-10-03 699 u32 reference, sig_path;
a44ef7c4609724e Ibrahim Tilki 2022-10-03 700 const char *node_name;
a44ef7c4609724e Ibrahim Tilki 2022-10-03 701 u32 inputs[2], scale;
a44ef7c4609724e Ibrahim Tilki 2022-10-03 702 unsigned int num_ch;
a44ef7c4609724e Ibrahim Tilki 2022-10-03 703 int chan_idx = 0;
a44ef7c4609724e Ibrahim Tilki 2022-10-03 704 int ret, i;
a44ef7c4609724e Ibrahim Tilki 2022-10-03 705
a44ef7c4609724e Ibrahim Tilki 2022-10-03 706 num_ch = device_get_child_node_count(dev);
a44ef7c4609724e Ibrahim Tilki 2022-10-03 707 if (num_ch == 0)
a44ef7c4609724e Ibrahim Tilki 2022-10-03 708 return dev_err_probe(&indio_dev->dev, -ENODEV,
a44ef7c4609724e Ibrahim Tilki 2022-10-03 709 "FW has no channels defined\n");
a44ef7c4609724e Ibrahim Tilki 2022-10-03 710
a44ef7c4609724e Ibrahim Tilki 2022-10-03 711 /* Reserve space for soft timestamp channel */
a44ef7c4609724e Ibrahim Tilki 2022-10-03 712 num_ch++;
a44ef7c4609724e Ibrahim Tilki 2022-10-03 713 channels = devm_kcalloc(dev, num_ch, sizeof(*channels), GFP_KERNEL);
a44ef7c4609724e Ibrahim Tilki 2022-10-03 714 if (!channels)
a44ef7c4609724e Ibrahim Tilki 2022-10-03 715 return -ENOMEM;
a44ef7c4609724e Ibrahim Tilki 2022-10-03 716
a44ef7c4609724e Ibrahim Tilki 2022-10-03 717 st->channels = devm_kcalloc(dev, num_ch, sizeof(*st->channels),
a44ef7c4609724e Ibrahim Tilki 2022-10-03 718 GFP_KERNEL);
a44ef7c4609724e Ibrahim Tilki 2022-10-03 719 if (!st->channels)
a44ef7c4609724e Ibrahim Tilki 2022-10-03 720 return -ENOMEM;
a44ef7c4609724e Ibrahim Tilki 2022-10-03 721
1693d2a7459183d Jonathan Cameron 2024-02-17 722 device_for_each_child_node_scoped(dev, child) {
a44ef7c4609724e Ibrahim Tilki 2022-10-03 723 node_name = fwnode_get_name(child);
a44ef7c4609724e Ibrahim Tilki 2022-10-03 724 if (fwnode_property_present(child, "diff-channels")) {
a44ef7c4609724e Ibrahim Tilki 2022-10-03 725 ret = fwnode_property_read_u32_array(child,
a44ef7c4609724e Ibrahim Tilki 2022-10-03 726 "diff-channels",
a44ef7c4609724e Ibrahim Tilki 2022-10-03 727 inputs,
a44ef7c4609724e Ibrahim Tilki 2022-10-03 728 ARRAY_SIZE(inputs));
a44ef7c4609724e Ibrahim Tilki 2022-10-03 729
a44ef7c4609724e Ibrahim Tilki 2022-10-03 730 chanspec.differential = 1;
a44ef7c4609724e Ibrahim Tilki 2022-10-03 731 } else {
a44ef7c4609724e Ibrahim Tilki 2022-10-03 732 ret = fwnode_property_read_u32(child, "reg", &inputs[0]);
a44ef7c4609724e Ibrahim Tilki 2022-10-03 733
a44ef7c4609724e Ibrahim Tilki 2022-10-03 734 inputs[1] = 0;
a44ef7c4609724e Ibrahim Tilki 2022-10-03 735 chanspec.differential = 0;
a44ef7c4609724e Ibrahim Tilki 2022-10-03 736 }
1693d2a7459183d Jonathan Cameron 2024-02-17 737 if (ret)
a44ef7c4609724e Ibrahim Tilki 2022-10-03 738 return ret;
a44ef7c4609724e Ibrahim Tilki 2022-10-03 739
a44ef7c4609724e Ibrahim Tilki 2022-10-03 740 if (inputs[0] > MAX11410_CHANNEL_INDEX_MAX ||
1693d2a7459183d Jonathan Cameron 2024-02-17 741 inputs[1] > MAX11410_CHANNEL_INDEX_MAX)
a44ef7c4609724e Ibrahim Tilki 2022-10-03 742 return dev_err_probe(&indio_dev->dev, -EINVAL,
a44ef7c4609724e Ibrahim Tilki 2022-10-03 743 "Invalid channel index for %s, should be less than %d\n",
a44ef7c4609724e Ibrahim Tilki 2022-10-03 744 node_name,
a44ef7c4609724e Ibrahim Tilki 2022-10-03 745 MAX11410_CHANNEL_INDEX_MAX + 1);
a44ef7c4609724e Ibrahim Tilki 2022-10-03 746
a44ef7c4609724e Ibrahim Tilki 2022-10-03 747 cfg = &st->channels[chan_idx];
a44ef7c4609724e Ibrahim Tilki 2022-10-03 748
a44ef7c4609724e Ibrahim Tilki 2022-10-03 749 reference = MAX11410_REFSEL_AVDD_AGND;
a44ef7c4609724e Ibrahim Tilki 2022-10-03 750 fwnode_property_read_u32(child, "adi,reference", &reference);
1693d2a7459183d Jonathan Cameron 2024-02-17 751 if (reference > MAX11410_REFSEL_MAX)
a44ef7c4609724e Ibrahim Tilki 2022-10-03 752 return dev_err_probe(&indio_dev->dev, -EINVAL,
a44ef7c4609724e Ibrahim Tilki 2022-10-03 753 "Invalid adi,reference value for %s, should be less than %d.\n",
a44ef7c4609724e Ibrahim Tilki 2022-10-03 754 node_name, MAX11410_REFSEL_MAX + 1);
a44ef7c4609724e Ibrahim Tilki 2022-10-03 755
a44ef7c4609724e Ibrahim Tilki 2022-10-03 756 if (!max11410_get_vrefp(st, reference) ||
1693d2a7459183d Jonathan Cameron 2024-02-17 757 (!max11410_get_vrefn(st, reference) && reference <= 2))
a44ef7c4609724e Ibrahim Tilki 2022-10-03 758 return dev_err_probe(&indio_dev->dev, -EINVAL,
a44ef7c4609724e Ibrahim Tilki 2022-10-03 759 "Invalid VREF configuration for %s, either specify corresponding VREF regulators or change adi,reference property.\n",
a44ef7c4609724e Ibrahim Tilki 2022-10-03 760 node_name);
a44ef7c4609724e Ibrahim Tilki 2022-10-03 761
a44ef7c4609724e Ibrahim Tilki 2022-10-03 762 sig_path = MAX11410_PGA_SIG_PATH_BUFFERED;
a44ef7c4609724e Ibrahim Tilki 2022-10-03 763 fwnode_property_read_u32(child, "adi,input-mode", &sig_path);
1693d2a7459183d Jonathan Cameron 2024-02-17 764 if (sig_path > MAX11410_SIG_PATH_MAX)
a44ef7c4609724e Ibrahim Tilki 2022-10-03 765 return dev_err_probe(&indio_dev->dev, -EINVAL,
a44ef7c4609724e Ibrahim Tilki 2022-10-03 766 "Invalid adi,input-mode value for %s, should be less than %d.\n",
a44ef7c4609724e Ibrahim Tilki 2022-10-03 767 node_name, MAX11410_SIG_PATH_MAX + 1);
a44ef7c4609724e Ibrahim Tilki 2022-10-03 768
a44ef7c4609724e Ibrahim Tilki 2022-10-03 769 fwnode_property_read_u32(child, "settling-time-us",
a44ef7c4609724e Ibrahim Tilki 2022-10-03 770 &cfg->settling_time_us);
a44ef7c4609724e Ibrahim Tilki 2022-10-03 771 cfg->bipolar = fwnode_property_read_bool(child, "bipolar");
a44ef7c4609724e Ibrahim Tilki 2022-10-03 772 cfg->buffered_vrefp = fwnode_property_read_bool(child, "adi,buffered-vrefp");
a44ef7c4609724e Ibrahim Tilki 2022-10-03 773 cfg->buffered_vrefn = fwnode_property_read_bool(child, "adi,buffered-vrefn");
a44ef7c4609724e Ibrahim Tilki 2022-10-03 774 cfg->refsel = reference;
a44ef7c4609724e Ibrahim Tilki 2022-10-03 775 cfg->sig_path = sig_path;
a44ef7c4609724e Ibrahim Tilki 2022-10-03 776 cfg->gain = 0;
a44ef7c4609724e Ibrahim Tilki 2022-10-03 777
a44ef7c4609724e Ibrahim Tilki 2022-10-03 778 /* Enable scale_available property if input mode is PGA */
a44ef7c4609724e Ibrahim Tilki 2022-10-03 779 if (sig_path == MAX11410_PGA_SIG_PATH_PGA) {
a44ef7c4609724e Ibrahim Tilki 2022-10-03 780 __set_bit(IIO_CHAN_INFO_SCALE,
a44ef7c4609724e Ibrahim Tilki 2022-10-03 781 &chanspec.info_mask_separate_available);
a44ef7c4609724e Ibrahim Tilki 2022-10-03 782 cfg->scale_avail = devm_kcalloc(dev, MAX11410_SCALE_AVAIL_SIZE * 2,
a44ef7c4609724e Ibrahim Tilki 2022-10-03 783 sizeof(*cfg->scale_avail),
a44ef7c4609724e Ibrahim Tilki 2022-10-03 784 GFP_KERNEL);
1693d2a7459183d Jonathan Cameron 2024-02-17 785 if (!cfg->scale_avail)
a44ef7c4609724e Ibrahim Tilki 2022-10-03 786 return -ENOMEM;
a44ef7c4609724e Ibrahim Tilki 2022-10-03 787
a44ef7c4609724e Ibrahim Tilki 2022-10-03 788 scale = max11410_get_scale(st, *cfg);
a44ef7c4609724e Ibrahim Tilki 2022-10-03 789 for (i = 0; i < MAX11410_SCALE_AVAIL_SIZE; i++) {
a44ef7c4609724e Ibrahim Tilki 2022-10-03 790 cfg->scale_avail[2 * i] = scale >> i;
a44ef7c4609724e Ibrahim Tilki 2022-10-03 791 cfg->scale_avail[2 * i + 1] = chanspec.scan_type.realbits;
a44ef7c4609724e Ibrahim Tilki 2022-10-03 792 }
a44ef7c4609724e Ibrahim Tilki 2022-10-03 793 } else {
a44ef7c4609724e Ibrahim Tilki 2022-10-03 794 __clear_bit(IIO_CHAN_INFO_SCALE,
a44ef7c4609724e Ibrahim Tilki 2022-10-03 795 &chanspec.info_mask_separate_available);
a44ef7c4609724e Ibrahim Tilki 2022-10-03 796 }
a44ef7c4609724e Ibrahim Tilki 2022-10-03 797
a44ef7c4609724e Ibrahim Tilki 2022-10-03 798 chanspec.address = chan_idx;
a44ef7c4609724e Ibrahim Tilki 2022-10-03 799 chanspec.scan_index = chan_idx;
a44ef7c4609724e Ibrahim Tilki 2022-10-03 800 chanspec.channel = inputs[0];
a44ef7c4609724e Ibrahim Tilki 2022-10-03 801 chanspec.channel2 = inputs[1];
a44ef7c4609724e Ibrahim Tilki 2022-10-03 802
a44ef7c4609724e Ibrahim Tilki 2022-10-03 803 channels[chan_idx] = chanspec;
a44ef7c4609724e Ibrahim Tilki 2022-10-03 804 chan_idx++;
a44ef7c4609724e Ibrahim Tilki 2022-10-03 805 }
a44ef7c4609724e Ibrahim Tilki 2022-10-03 806
a44ef7c4609724e Ibrahim Tilki 2022-10-03 @807 channels[chan_idx] = (struct iio_chan_spec)IIO_CHAN_SOFT_TIMESTAMP(chan_idx);
a44ef7c4609724e Ibrahim Tilki 2022-10-03 808
a44ef7c4609724e Ibrahim Tilki 2022-10-03 809 indio_dev->num_channels = chan_idx + 1;
a44ef7c4609724e Ibrahim Tilki 2022-10-03 810 indio_dev->channels = channels;
a44ef7c4609724e Ibrahim Tilki 2022-10-03 811
a44ef7c4609724e Ibrahim Tilki 2022-10-03 812 return 0;
a44ef7c4609724e Ibrahim Tilki 2022-10-03 813 }
a44ef7c4609724e Ibrahim Tilki 2022-10-03 814 --
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Quoted 17 lines · kernel test robot
kernel test robot noticed the following build warnings:
[auto build test WARNING on jic23-iio/togreg]
[also build test WARNING on linus/master v7.1-rc4 next-20260518] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]url: https://github.com/intel-lab-lkp/linux/commits/Andy-Shevchenko/iio-Convert-IIO_CHAN_SOFT_TIMESTAMP-to-be-compound-literal/20260518-151541 base: https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg patch link: https://lore.kernel.org/r/20260518071349.469748-1-andriy.shevchenko%40linux.intel.com patch subject: [PATCH v0 1/1] iio: Convert IIO_CHAN_SOFT_TIMESTAMP() to be compound literal config: sparc64-randconfig-r132-20260518 (https://download.01.org/0day-ci/archive/20260519/[email protected]/config) compiler: clang version 23.0.0git (https://github.com/llvm/llvm-project 5bac06718f502014fade905512f1d26d578a18f3) sparse: v0.6.5-rc1 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260519/[email protected]/reproduce)
Quoted 8 lines
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/sparse warnings: (new ones prefixed by >>)
Quoted 2 lines
Quoted 2 lines
drivers/iio/adc/max11410.c:807:31: sparse: sparse: cast to non-scalardrivers/iio/adc/max11410.c:807:31: sparse: sparse: cast from non-scalar
Thanks, the sparks were expected exactly in this and one more driver. I mentioned that in my reply to my own patch already.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 24 lines · On Mon, 18 May 2026 21:17:38 +0300 Andy Shevchenko…
Quoted 22 lines · kernel test robot
kernel test robot noticed the following build warnings:
[auto build test WARNING on jic23-iio/togreg]
[also build test WARNING on linus/master v7.1-rc4 next-20260518] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]url: https://github.com/intel-lab-lkp/linux/commits/Andy-Shevchenko/iio-Convert-IIO_CHAN_SOFT_TIMESTAMP-to-be-compound-literal/20260518-151541 base: https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg patch link: https://lore.kernel.org/r/20260518071349.469748-1-andriy.shevchenko%40linux.intel.com patch subject: [PATCH v0 1/1] iio: Convert IIO_CHAN_SOFT_TIMESTAMP() to be compound literal config: sparc64-randconfig-r132-20260518 (https://download.01.org/0day-ci/archive/20260519/[email protected]/config) compiler: clang version 23.0.0git (https://github.com/llvm/llvm-project 5bac06718f502014fade905512f1d26d578a18f3) sparse: v0.6.5-rc1 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260519/[email protected]/reproduce)If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
Quoted 7 lines
Quoted 3 lines
sparse warnings: (new ones prefixed by >>)
Quoted 2 lines
Quoted 2 lines
drivers/iio/adc/max11410.c:807:31: sparse: sparse: cast to non-scalardrivers/iio/adc/max11410.c:807:31: sparse: sparse: cast from non-scalarThanks, the sparks were expected exactly in this and one more driver. I mentioned that in my reply to my own patch already.
Can you just remove then cast from:a44ef7c4609724e Ibrahim Tilki 2022-10-03 @807 \
channels[chan_idx] = (struct iio_chan_spec)IIO_CHAN_SOFT_TIMESTAMP(chan_idx);
since it is no longer needed?
-- David
Quoted 27 lines · David Laight
Quoted 25 lines · On Mon, 18 May 2026 21:17:38 +0300 Andy Shevchenko…
Quoted 23 lines · kernel test robot
kernel test robot noticed the following build warnings:
[auto build test WARNING on jic23-iio/togreg]
[also build test WARNING on linus/master v7.1-rc4 next-20260518] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]url: https://github.com/intel-lab-lkp/linux/commits/Andy-Shevchenko/iio-Convert-IIO_CHAN_SOFT_TIMESTAMP-to-be-compound-literal/20260518-151541 base: https://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio.git togreg patch link: https://lore.kernel.org/r/20260518071349.469748-1-andriy.shevchenko%40linux.intel.com patch subject: [PATCH v0 1/1] iio: Convert IIO_CHAN_SOFT_TIMESTAMP() to be compound literal config: sparc64-randconfig-r132-20260518 (https://download.01.org/0day-ci/archive/20260519/[email protected]/config) compiler: clang version 23.0.0git (https://github.com/llvm/llvm-project 5bac06718f502014fade905512f1d26d578a18f3) sparse: v0.6.5-rc1 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260519/[email protected]/reproduce)If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/sparse warnings: (new ones prefixed by >>)
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
drivers/iio/adc/max11410.c:807:31: sparse: sparse: cast to non-scalardrivers/iio/adc/max11410.c:807:31: sparse: sparse: cast from non-scalarThanks, the sparks were expected exactly in this and one more driver. I mentioned that in my reply to my own patch already.
Can you just remove then cast from:
Not a cast! :-)
Quoted 3 lines
a44ef7c4609724eIbrahim Tilki 2022-10-03 @807 \
channels[chan_idx] = (struct iio_chan_spec)IIO_CHAN_SOFT_TIMESTAMP(chan_idx);
since it is no longer needed?
I won't have time, if you can wait a couple of weeks (my vacations started, I am busy with something else). Otherwise, feel free to drop those from the two drivers in the same patch, thanks!
Signature · 2 lines
With Best Regards, Andy Shevchenko