Skip to content

module_platform_driver()

Purpose

module_platform_driver() is a helper macro for registering and unregistering a platform driver in a loadable kernel module.

It reduces boilerplate for simple platform drivers.

#include <linux/platform_device.h>
#include <linux/module.h>

Typical Usage

static struct platform_driver my_driver = {
    .probe = my_probe,
    .remove = my_remove,
    .driver = {
        .name = "my-driver",
        .of_match_table = my_of_match,
    },
};

module_platform_driver(my_driver);

Equivalent Concept

It is equivalent to writing module init and exit functions that call:

platform_driver_register(&my_driver);
platform_driver_unregister(&my_driver);

Common Pitfalls

  • missing MODULE_DEVICE_TABLE(of, ...)
  • wrong compatible string
  • probe not called because the Device Tree node does not match
  • using this helper when custom init or exit ordering is required