Skip to content

devm_iio_device_alloc()

Purpose

Allocates an iio_dev object with device-managed lifetime.

#include <linux/iio/iio.h>

Prototype

struct iio_dev *devm_iio_device_alloc(struct device *dev, int sizeof_priv);

Parameters

  • dev: parent device used for managed cleanup.
  • sizeof_priv: size of the private driver data placed after the iio_dev object.

Return Value

  • Success: pointer to struct iio_dev.
  • Failure: NULL.

Minimal Example

indio_dev = devm_iio_device_alloc(dev, sizeof(*priv));
if (!indio_dev)
    return -ENOMEM;

priv = iio_priv(indio_dev);

Common Pitfalls

  • Use iio_priv() to access the private driver data.
  • Do not manually free the returned object when using the devm_ variant.
  • Initialize indio_dev->info, indio_dev->channels, indio_dev->num_channels, and indio_dev->modes before registration.