Skip to content

Commit b909459

Browse files
Sachin Kamatjic23
authored andcommitted
staging: iio: ade7854: Use devm_iio_device_alloc
devm_iio_device_alloc makes code simpler. Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org> Cc: Barry Song <21cnbao@gmail.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
1 parent b67637a commit b909459

3 files changed

Lines changed: 3 additions & 11 deletions

File tree

‎drivers/staging/iio/meter/ade7854-i2c.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ static int ade7854_i2c_probe(struct i2c_client *client,
208208
struct ade7854_state *st;
209209
struct iio_dev *indio_dev;
210210

211-
indio_dev = iio_device_alloc(sizeof(*st));
211+
indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*st));
212212
if (indio_dev == NULL)
213213
return -ENOMEM;
214214
st = iio_priv(indio_dev);
@@ -225,8 +225,6 @@ static int ade7854_i2c_probe(struct i2c_client *client,
225225
st->irq = client->irq;
226226

227227
ret = ade7854_probe(indio_dev, &client->dev);
228-
if (ret)
229-
iio_device_free(indio_dev);
230228

231229
return ret;
232230
}

‎drivers/staging/iio/meter/ade7854-spi.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ static int ade7854_spi_probe(struct spi_device *spi)
278278
struct ade7854_state *st;
279279
struct iio_dev *indio_dev;
280280

281-
indio_dev = iio_device_alloc(sizeof(*st));
281+
indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
282282
if (indio_dev == NULL)
283283
return -ENOMEM;
284284
st = iio_priv(indio_dev);
@@ -296,8 +296,6 @@ static int ade7854_spi_probe(struct spi_device *spi)
296296

297297

298298
ret = ade7854_probe(indio_dev, &spi->dev);
299-
if (ret)
300-
iio_device_free(indio_dev);
301299

302300
return 0;
303301
}

‎drivers/staging/iio/meter/ade7854.c‎

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ int ade7854_probe(struct iio_dev *indio_dev, struct device *dev)
550550

551551
ret = iio_device_register(indio_dev);
552552
if (ret)
553-
goto error_free_dev;
553+
return ret;
554554

555555
/* Get the device into a sane initial state */
556556
ret = ade7854_initial_setup(indio_dev);
@@ -561,17 +561,13 @@ int ade7854_probe(struct iio_dev *indio_dev, struct device *dev)
561561

562562
error_unreg_dev:
563563
iio_device_unregister(indio_dev);
564-
error_free_dev:
565-
iio_device_free(indio_dev);
566-
567564
return ret;
568565
}
569566
EXPORT_SYMBOL(ade7854_probe);
570567

571568
int ade7854_remove(struct iio_dev *indio_dev)
572569
{
573570
iio_device_unregister(indio_dev);
574-
iio_device_free(indio_dev);
575571

576572
return 0;
577573
}

0 commit comments

Comments
 (0)