STRUCT USB_DEVICE_DRIVER(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… struct usb_device_driver(9) β€” the Kernel API Manual, bestie edition πŸŽ€

okay so. welcome to struct usb_device_driver(9), the little struct that tells usbcore "hey, this thing? it's a USB device driver, not a USB interface driver, iykyk." it's giving main character energy in ./include/linux/usb.h and honestly it ate. πŸ¦‹


✨ SYNOPSIS ✨

struct usb_device_driver {
    const char *name;
    bool (*match) (struct usb_device *udev);
    int (*probe) (struct usb_device *udev);
    void (*disconnect) (struct usb_device *udev);
    int (*suspend) (struct usb_device *udev, pm_message_t message);
    int (*resume) (struct usb_device *udev, pm_message_t message);
    int (*choose_configuration) (struct usb_device *udev);
    const struct attribute_group **dev_groups;
    struct device_driver driver;
    const struct usb_device_id *id_table;
    unsigned int supports_autosuspend:1;
    unsigned int generic_subclass:1;
 };

like, look at her. all those function pointers? she's literally the blueprint. 🫢


🌸 Members 🌸

  • name β€” the driver name, and bestie it needs to be unique among USB drivers. normally it should be the same as the module name, no cap.
  • match β€” if you set it, it's used for better device/driver matching. ✨
  • probe β€” called to see if the driver is even willing to manage a particular device. if it is, probe returns zero and uses dev_set_drvdata to associate driver-specific data with the device. if it's like "no thanks babe," you return a negative errno value. rude but valid.
  • disconnect β€” called when the device is no longer accessible, usually because it has been (or is being) disconnected, or because the driver's module is being unloaded. 😭 it's the sad goodbye function.
  • suspend β€” called when the device is going to be suspended by the system. πŸ’€
  • resume β€” called when the device is being resumed by the system. ⭐ she's back!!
  • choose_configuration β€” if non-NULL, it's called instead of the default usb_choose_configuration. and the cute part? if this returns an error then we'll go on to call the normal usb_choose_configuration anyway. so it's like a soft override, not a hard takeover. 🧚
  • dev_groups β€” attributes attached to the device that will be created once it is bound to the driver. πŸŽ€
  • driver β€” the driver-model core driver structure. the foundation, the moment, the base layer.
  • id_table β€” used with match to select a better matching driver at probe time. πŸ‘‘
  • supports_autosuspend β€” if set to 0, the USB core will not allow autosuspend for devices bound to this driver. so like, flip it to zero and no napping allowed. πŸ’€
  • generic_subclass β€” if set to 1, the generic USB driver's probe, disconnect, resume and suspend functions will be called in addition to the driver's own, so this part of the setup does not need to be replicated. it's giving "don't do the work twice, queen" πŸ’…

πŸ’– Description πŸ’–

USB device drivers must provide a name β€” that's literally the only non-negotiable. all the other driver fields are optional. so yes bestie, you can absolutely do the bare minimum here and she'll still compile. πŸ™ˆ


🌈 SEE ALSO 🌈

bestie the reading list is long, but we're getting through it together, fr fr:


ok that's the whole page, no skipped sections, every single flag accounted for. go be a good USB device driver bestie, ily πŸ«ΆπŸ’œ

this one comes straight out of ./include/linux and it's dated October 2026 β€” catch you in the next struct usb_device_driver(9) era, mwah πŸ’‹πŸŽ€

πŸ“¦ where this page comes from