lib/sg_pool: change module_init(sg_pool_init) to subsys_initcall
Guenter Roeck
Tested-byQuoted 20 lines · Masahiro Yamada
sg_alloc_table_chained()is called by several drivers, but if it is called beforesg_pool_init(), it results in a NULL pointer dereference insg_pool_alloc().Since commit
9b1d6c895002("lib: scatterlist: move SG pool code from SCSI driver tolib/sg_pool.c"), we rely onmodule_init(sg_pool_init)is invoked before othermodule_initcalls but this assumption is fragile.I slightly changed the link order while
KbuildrefactoringKbuild, then uncovered this issue. I should keep the current link order, but depending on a specific call order amongmodule_initis so fragine.We usually define the init order by specifying
*_initcallcorrectly, or delay the driver probing by returning -EPROBE_DEFER.Change
module_initcall()tosubsys_initcall(), and also delete the pointlessmodule_exit()becauselib/sg_pool.cis always compiled as built-in. (CONFIG_SG_POOLis bool)
Quoted 6 lines
Fixes 9b1d6c895002 ("lib: scatterlist: move SG pool code from SCSI driver to lib/sg_pool.c")Reported-by Guenter Roeck <[email protected]>Reported-by Marek Szyprowski <[email protected]>Signed-off-by Masahiro Yamada <[email protected]>
Guenter