What is the difference between driver name and kernel module name for lshw?

Using lshw to query my WiFi USB adapter shows the following:

$ lshw -C network
  *-network                 
       description: Wireless interface
       physical id: 12
       bus info: usb@3:7
       logical name: ...
       serial: ...
       capabilities: ethernet physical wireless
       configuration: broadcast=yes driver=rtw_8822bu driverversion=6.5.0-28-generic firmware=N/A ip=... link=yes multicast=yes wireless=IEEE 802.11

The adapter works fine. However, I am confused by driver=rtw_8822bu. As far as I can tell there is no kernel model called rtw_8822bu.ko on my system, instead, I have rtw88_8822bu.ko,

/usr/lib/modules/6.5.0-28-generic/kernel/drivers/net/wireless/realtek/rtw88/rtw88_8822bu.ko

which also shows up using lsmod:

$ lsmod | grep rtw
rtw88_8822bu           12288  0
rtw88_usb              24576  1 rtw88_8822bu
rtw88_8822b           229376  1 rtw88_8822bu
rtw88_core            356352  2 rtw88_usb,rtw88_8822b
mac80211             1720320  3 rtw88_core,rtw88_usb,rtl8xxxu
cfg80211             1323008  3 rtw88_core,mac80211,rtl8xxxu

Question: Why does lshw show driver=rtw_8822bu when the kernel module in the system is named rtw88_8822bu. Where is the former name coming from?

Asked By: jII

||

A module is a library containing functions that can be loaded into the kernel.

When writing a module, you can define a C data structure that defines the name of a driver, and the functions to be called to check whether there’s a device that can be handled by the driver, which function to call when the device gets unplugged, among other things.

You then put a macro in there that registers that data structure as a representation of a "driver". So, "driver" is really just an idea that encompasses a name, and a couple of functions to call in specific situations (such as when you want to set up or tear down the device’s functionality).

So, here’s your driver’s data structure:

static struct usb_driver rtw_8822bu_driver = {
    .name = "rtw_8822bu",
    .id_table = rtw_8822bu_id_table,
    .probe = rtw8822bu_probe,
    .disconnect = rtw_usb_disconnect,
};

See the `.name = ‘ in there? That is where the name of the driver is defined.

Here‘s how it gets registered as driver within a module:

module_usb_driver(rtw_8822bu_driver);

You can have as many of these driver in a single module as you want, provided each of them has a different name. And there’s no reason that the name of the module needs to be the same as the name of the driver. You could have a module called drivers_for_webcams.ko and it could contain realtek_ssd_controller_driver1 through realtek_ssd_controller_driver98, and nothing would be wrong; the assumption that driver name == module name is simply wrong.

Answered By: Marcus Müller