summaryrefslogtreecommitdiffstats
path: root/drivers/iio/adc
diff options
context:
space:
mode:
authorOleksij Rempel <o.rempel@pengutronix.de>2022-01-17 09:28:52 +0100
committerJonathan Cameron <Jonathan.Cameron@huawei.com>2022-01-23 18:03:37 +0000
commit576434fd93b91d36cb62d531888e88dac5e52540 (patch)
tree0ffbd9d6a5c604b467b327a518fb8ab272c1a37c /drivers/iio/adc
parentb617693a5d139dec0a3a19a909d687d2d95d78bc (diff)
downloadlinux-576434fd93b91d36cb62d531888e88dac5e52540.tar.bz2
iio: adc: tsc2046: add sanity check to avoid to big allocations
To avoid problematic devicetree configurations. Set allocation limit with error message and suggestion on what can be done to solve this issue. Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de> Link: https://lore.kernel.org/r/20220117082852.3370869-2-o.rempel@pengutronix.de Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Diffstat (limited to 'drivers/iio/adc')
-rw-r--r--drivers/iio/adc/ti-tsc2046.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/drivers/iio/adc/ti-tsc2046.c b/drivers/iio/adc/ti-tsc2046.c
index eb219ff3d610..2b87f39f377a 100644
--- a/drivers/iio/adc/ti-tsc2046.c
+++ b/drivers/iio/adc/ti-tsc2046.c
@@ -679,6 +679,12 @@ static int tsc2046_adc_setup_spi_msg(struct tsc2046_adc_priv *priv)
for (ch_idx = 0; ch_idx < priv->dcfg->num_channels; ch_idx++)
size += tsc2046_adc_group_set_layout(priv, ch_idx, ch_idx);
+ if (size > PAGE_SIZE) {
+ dev_err(&priv->spi->dev,
+ "Calculated scan buffer is too big. Try to reduce spi-max-frequency, settling-time-us or oversampling-ratio\n");
+ return -ENOSPC;
+ }
+
priv->tx = devm_kzalloc(&priv->spi->dev, size, GFP_KERNEL);
if (!priv->tx)
return -ENOMEM;