tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

pre-configure module initialization



If I have a module that needs to run some code to set up some data
structures before I can configure a device, I would like to use code
that looks like the following.  This works for modules compiled
separately, but for builtin modules, it doesn't, because the kernel
runs configure long before it runs module_class_init(MODULE_CLASS_ANY)
to initialize all the modules.

I could duplicate xyz_setup in xyz_modcmd and in a RUN_ONCE inside
xyz_match, but I would strongly prefer to avoid such duplication.

What to do?


static int
xyz_modcmd(modcmd_t cmd, void *arg)
{
        int error;

        switch (cmd) {
        case MODULE_CMD_INIT:
                error = xyz_setup();
                if (error)
                        return error;

#ifdef _MODULE
                error = config_init_component(cfdriver_ioconf_xyz, ...);
                if (error) {
                        xyz_teardown();
                        return error;
                }
#endif

                return 0;

        case MODULE_CMD_FINI:
#ifdef _MODULE
                error = config_fini_component(cfdriver_ioconf_xyz, ...);
                if (error)
                        return error;
#endif

                xyz_teardown();
                return 0;
        }
}


Home | Main Index | Thread Index | Old Index