---
name: "DEV_MODULE"
section: "9"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["linux", "freebsd"]
url: "https://new.carta.tech/DEV_MODULE"
---

# DEV\_MODULE(9)

device driver module declaration macro

## NAME

**DEV\_MODULE** – device driver module declaration macro

## SYNOPSIS

**#include \<sys/param.h\>**

**#include \<sys/kernel.h\>**

**#include \<sys/module.h\>**

**#include \<sys/conf.h\>**

**DEV\_MODULE**(*name*, *modeventhand\_t evh*, *void \*arg*);

## DESCRIPTION

The **DEV\_MODULE**() macro declares a device driver kernel module. It fills in a *moduledata\_t* structure and then calls **DECLARE\_MODULE**() with the correct args, where *name* is the name of the module and *evh* (with its argument *arg*) is the event handler for the module (refer to [DECLARE\_MODULE(9)](/DECLARE_MODULE/9.md) for more information). The event handler is supposed to create the device with **make\_dev**() on load and to destroy it when it is unloaded using **destroy\_dev**().

## EXAMPLES

```
#include <sys/module.h>
#include <sys/conf.h>
static struct cdevsw foo_devsw = { ... };
static struct cdev *sdev;
static int
foo_load(module_t mod, int cmd, void *arg)
{
    int err = 0;
    switch (cmd) {
    case MOD_LOAD:
        sdev = make_dev(&foo_devsw, 0, UID_ROOT, GID_WHEEL, 0600, "foo");
        break;          /* Success*/
    case MOD_UNLOAD:
    case MOD_SHUTDOWN:
        destroy_dev(sdev);
        break;          /* Success*/
    default:
        err = EINVAL;
        break;
    }
    return(err);
}
DEV_MODULE(foo, foo_load, NULL);
```

## SEE ALSO

[DECLARE\_MODULE(9)](/DECLARE_MODULE/9.md), [destroy\_dev(9)](/destroy_dev/9.md), [make\_dev(9)](/make_dev/9.md), [module(9)](/module/9.md)

## AUTHORS

This manual page was written by Alexander Langer ⟨*alex@FreeBSD.org*⟩.
