What is the difference between module_init
and subsys_initcall
while initializing the driver?
Asked
Active
Viewed 1.3k times
18

kzs
- 1,793
- 3
- 24
- 44
-
Did you check the man pages? – rekire Mar 21 '13 at 07:07
-
1No manual page entry available for that. – kzs Mar 21 '13 at 07:26
-
1You can always grep through the sources. A great deal can be explained by just looking at the sources. – Jörgen Sigvardsson Jan 22 '14 at 08:09
1 Answers
27
The difference relates to timing, or more precisely, order of execution. That is, the procedure declared as subsys_initcall
is guaranteed to be executed before the procedure declared as module_init
. This ordering ensures that subsystem and platform drivers are initialized before device drivers try to utilize the former's functionality (e.g. a device driver registers as a subsystem device).
The actual macro definition for each depends on if the kernel is configured for (loadable) modules or not. The definition for these macros (and other init macros) can be found in include/linux/init.h
Note that subsys_initcall()
can only be used by a built-in (statically linked) module.
module_init
can be used by either built-in or loadable modules.

sawdust
- 16,103
- 3
- 40
- 50
-
3For loadable `*.ko` modules, `subsys_initcall()` is mapped to the same as `module_init()` i.e. `device_initcall()` Reference: http://lxr.free-electrons.com/source/include/linux/init.h#L298 – TheCodeArtist Jan 22 '15 at 09:54