Skip to content

devm_input_allocate_device()

Purpose

Allocates an input device with device-managed lifetime.

#include <linux/input.h>

Prototype

struct input_dev *devm_input_allocate_device(struct device *dev);

Parameters

  • dev: parent device used for managed cleanup.

Return Value

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

Minimal Example

input = devm_input_allocate_device(dev);
if (!input)
    return -ENOMEM;

input->name = "mygpio-input";

Common Pitfalls

  • Configure supported event types and codes before registration.
  • Do not manually free the device when using the devm_ variant.