Commit 576434fd authored by Oleksij Rempel's avatar Oleksij Rempel Committed by Jonathan Cameron
Browse files

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: default avatarOleksij Rempel <o.rempel@pengutronix.de>
Link: https://lore.kernel.org/r/20220117082852.3370869-2-o.rempel@pengutronix.de


Signed-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent b617693a
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -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;