Commit 4132f191 authored by Cosmin Tanislav's avatar Cosmin Tanislav Committed by Jonathan Cameron

iio: temperature: ltc2983: allocate iio channels once

Currently, every time the device wakes up from sleep, the
iio_chan array is reallocated, leaking the previous one
until the device is removed (basically never).

Move the allocation to the probe function to avoid this.
Signed-off-by: default avatarCosmin Tanislav <cosmin.tanislav@analog.com>
Fixes: f110f318 ("iio: temperature: Add support for LTC2983")
Cc: <Stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20221014123724.1401011-2-demonsingur@gmail.comSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 72b2aa38
...@@ -1385,13 +1385,6 @@ static int ltc2983_setup(struct ltc2983_data *st, bool assign_iio) ...@@ -1385,13 +1385,6 @@ static int ltc2983_setup(struct ltc2983_data *st, bool assign_iio)
return ret; return ret;
} }
st->iio_chan = devm_kzalloc(&st->spi->dev,
st->iio_channels * sizeof(*st->iio_chan),
GFP_KERNEL);
if (!st->iio_chan)
return -ENOMEM;
ret = regmap_update_bits(st->regmap, LTC2983_GLOBAL_CONFIG_REG, ret = regmap_update_bits(st->regmap, LTC2983_GLOBAL_CONFIG_REG,
LTC2983_NOTCH_FREQ_MASK, LTC2983_NOTCH_FREQ_MASK,
LTC2983_NOTCH_FREQ(st->filter_notch_freq)); LTC2983_NOTCH_FREQ(st->filter_notch_freq));
...@@ -1514,6 +1507,12 @@ static int ltc2983_probe(struct spi_device *spi) ...@@ -1514,6 +1507,12 @@ static int ltc2983_probe(struct spi_device *spi)
gpiod_set_value_cansleep(gpio, 0); gpiod_set_value_cansleep(gpio, 0);
} }
st->iio_chan = devm_kzalloc(&spi->dev,
st->iio_channels * sizeof(*st->iio_chan),
GFP_KERNEL);
if (!st->iio_chan)
return -ENOMEM;
ret = ltc2983_setup(st, true); ret = ltc2983_setup(st, true);
if (ret) if (ret)
return ret; return ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment