Skip to contentSkip to conversation

lib/sg_pool: change module_init(sg_pool_init) to subsys_initcall

PATCH Guenter Roeck 1 participant 1 message Sep 23, 2022 Kbuild

lore
Share & tools
lore

Guenter Roeck

author Tested-by
#0 lore raw
Quoted 20 lines · Masahiro Yamada

sg_alloc_table_chained() is called by several drivers, but if it is called before sg_pool_init(), it results in a NULL pointer dereference in sg_pool_alloc().

Since commit 9b1d6c895002 ("lib: scatterlist: move SG pool code from SCSI driver to lib/sg_pool.c"), we rely on module_init(sg_pool_init) is invoked before other module_init calls but this assumption is fragile.

I slightly changed the link order while Kbuild refactoring Kbuild, then uncovered this issue. I should keep the current link order, but depending on a specific call order among module_init is so fragine.

We usually define the init order by specifying *_initcall correctly, or delay the driver probing by returning -EPROBE_DEFER.

Change module_initcall() to subsys_initcall(), and also delete the pointless module_exit() because lib/sg_pool.c is always compiled as built-in. (CONFIG_SG_POOL is bool)

Quoted 6 lines

Guenter