Skip to content

Commit

Permalink
iio: adc: tsc2046: add sanity check to avoid to big allocations
Browse files Browse the repository at this point in the history
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 <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Jonathan Cameron <[email protected]>
  • Loading branch information
olerem authored and jic23 committed Jan 23, 2022
1 parent b617693 commit 576434f
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions drivers/iio/adc/ti-tsc2046.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 576434f

Please sign in to comment.