Skip to content

Commit 4132f19

Browse files
Demon000jic23
authored andcommitted
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: Cosmin Tanislav <[email protected]> Fixes: f110f31 ("iio: temperature: Add support for LTC2983") Cc: <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 72b2aa3 commit 4132f19

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

drivers/iio/temperature/ltc2983.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,13 +1385,6 @@ static int ltc2983_setup(struct ltc2983_data *st, bool assign_iio)
13851385
return ret;
13861386
}
13871387

1388-
st->iio_chan = devm_kzalloc(&st->spi->dev,
1389-
st->iio_channels * sizeof(*st->iio_chan),
1390-
GFP_KERNEL);
1391-
1392-
if (!st->iio_chan)
1393-
return -ENOMEM;
1394-
13951388
ret = regmap_update_bits(st->regmap, LTC2983_GLOBAL_CONFIG_REG,
13961389
LTC2983_NOTCH_FREQ_MASK,
13971390
LTC2983_NOTCH_FREQ(st->filter_notch_freq));
@@ -1514,6 +1507,12 @@ static int ltc2983_probe(struct spi_device *spi)
15141507
gpiod_set_value_cansleep(gpio, 0);
15151508
}
15161509

1510+
st->iio_chan = devm_kzalloc(&spi->dev,
1511+
st->iio_channels * sizeof(*st->iio_chan),
1512+
GFP_KERNEL);
1513+
if (!st->iio_chan)
1514+
return -ENOMEM;
1515+
15171516
ret = ltc2983_setup(st, true);
15181517
if (ret)
15191518
return ret;

0 commit comments

Comments
 (0)