0x07FC
0x07FC

Reputation: 523

Does __init is required in case of module?

When we build a driver as static along with the kernel, Then I can understand the flow of driver code from __init to _probe. But when the driver is built as a module and is loaded with insmod when the kernel is already booted, do we still require both functions ?

I mean, wouldn't only _probe be required when insmod is used ? Wouldn't the driver probe for the device directly and the device registration code could be done in the _probe itself ?

This is just not clear to me. Maybe my doubt is wrong but help me in clearing this doubt.

Upvotes: 0

Views: 1038

Answers (1)

Longfield
Longfield

Reputation: 1555

Actually, in both cases (driver in kernel or as a module) both functions (init and probe) are required.

As you mention it, the probe function is used when there is a device/driver registration (the device/driver kernel subsystem notices that there is a suitable driver for a given device and it "associates" them).

To simplify, in order to be able to achieve this "associtation", the kernel's device/driver subsystem needs a list of the devices on the system and a list of the available drivers (and a way to know if a driver can be "associated" with device, but it's not important for your question).

In a typical module, the init function is the function that initializes the driver to kernel, or to phrase it differently, to register the driver to the kernel's driver/device subsystem so that this new driver can be added to the list of available drivers that can be "associated" with the devices. This also has to be done when the driver is built as a module.

Upvotes: 1

Related Questions