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: ad7124: Refuse invalid input specifiers

The ad7124-4 has 8 analog inputs; the input select values 8 to 15 are
reserved and not to be used. These are fine for ad7124-8. For both
ad7124-4 and ad7124-8 values bigger than 15 are internal channels that
might appear as inputs in the channels specified in the device
description according to the description of commit f1794fd7bdf7 ("iio:
adc: ad7124: Remove input number limitation"), values bigger than 31
don't fit into the respective register bit field and the driver masked
them to smaller values.

Check for these invalid input specifiers and fail to probe if one is
found.

Fixes: f1794fd7bdf7 ("iio: adc: ad7124: Remove input number limitation")
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
Link: https://patch.msgid.link/80e3bd629d2b755ab5e061c8731dafa57d08698a.1733504533.git.u.kleine-koenig@baylibre.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Uwe Kleine-König and committed by
Jonathan Cameron
9ecad7f4 cc597af1

+18
+18
drivers/iio/adc/ad7124.c
··· 807 807 return 0; 808 808 } 809 809 810 + /* 811 + * Input specifiers 8 - 15 are explicitly reserved for ad7124-4 812 + * while they are fine for ad7124-8. Values above 31 don't fit 813 + * into the register field and so are invalid for sure. 814 + */ 815 + static bool ad7124_valid_input_select(unsigned int ain, const struct ad7124_chip_info *info) 816 + { 817 + if (ain >= info->num_inputs && ain < 16) 818 + return false; 819 + 820 + return ain <= FIELD_MAX(AD7124_CHANNEL_AINM_MSK); 821 + } 822 + 810 823 static int ad7124_parse_channel_config(struct iio_dev *indio_dev, 811 824 struct device *dev) 812 825 { ··· 871 858 ain, 2); 872 859 if (ret) 873 860 return ret; 861 + 862 + if (!ad7124_valid_input_select(ain[0], st->chip_info) || 863 + !ad7124_valid_input_select(ain[1], st->chip_info)) 864 + return dev_err_probe(dev, -EINVAL, 865 + "diff-channels property of %pfwP contains invalid data\n", child); 874 866 875 867 st->channels[channel].nr = channel; 876 868 st->channels[channel].ain = AD7124_CHANNEL_AINP(ain[0]) |