Conceptual
Login

Telling the Kernel Which Hardware You Drive

A driver does not go looking for its hardware; it publishes a table of identifiers and the bus calls it when something matching appears. For a card on a bus with numeric identifiers that table lists vendor and device numbers; for hardware described by firmware it lists compatible strings. Macros in the kernel crate build the table in the exact layout C expects, including the terminating empty entry, and let you attach your own data to each entry so probe can tell the variants apart. Hand-written tables in C famously go wrong by forgetting the terminator, and the macro cannot.

Questions this Concept answers

  • Why does the `kernel` crate provide macros that build the identifier table instead of letting you write the array yourself?

This Concept is waiting for its first lesson!

A driver does not go looking for its hardware; it publishes a table of identifiers and the bus calls it when something matching appears. For a card on a bus with numeric identifiers that table lists vendor and device numbers; for hardware described by firmware it lists compatible strings. Macros in the kernel crate build the table in the exact layout C expects, including the terminating empty entry, and let you attach your own data to each entry so probe can tell the variants apart. Hand-written tables in C famously go wrong by forgetting the terminator, and the macro cannot.

Are you a teacher? Sign in to start contributing.

Sign In