diff --git a/src/usb_moded-modules.c b/src/usb_moded-modules.c index 1bbcc42..4bd8706 100644 --- a/src/usb_moded-modules.c +++ b/src/usb_moded-modules.c @@ -42,9 +42,23 @@ #include "usb_moded-modesetting.h" #include "usb_moded-modes.h" -/* kmod context - initialized at start in usb_moded_init */ +/* kmod context - initialized at start in usb_moded_init by ctx_init() + and cleaned up by ctx_cleanup() functions */ struct kmod_ctx *ctx; +/* kmod module init */ +void usb_moded_module_ctx_init(void) +{ + ctx = kmod_new(NULL, NULL); + kmod_load_resources(ctx); +} + +/* kmod module cleanup */ +void usb_moded_module_ctx_cleanup(void) +{ + kmod_unref(ctx); +} + /** load module * * @param module Name of the module to load diff --git a/src/usb_moded-modules.h b/src/usb_moded-modules.h index 167c314..b54f2b5 100644 --- a/src/usb_moded-modules.h +++ b/src/usb_moded-modules.h @@ -33,6 +33,12 @@ #define MODULE_DEVELOPER "g_ether" #define MODULE_MTP "g_ffs" +/* module loading init */ +void usb_moded_module_ctx_init(void); + +/* module loading context cleanup */ +void usb_moded_module_ctx_cleanup(void); + /* load module */ int usb_moded_load_module(const char *module); diff --git a/src/usb_moded.c b/src/usb_moded.c index e96e512..5438f90 100644 --- a/src/usb_moded.c +++ b/src/usb_moded.c @@ -535,8 +535,6 @@ inline struct mode_list_elem * get_usb_mode_data(void) /* set default values for usb_moded */ static void usb_moded_init(void) { - extern struct kmod_ctx *ctx; - current_mode.connected = FALSE; current_mode.mounted = FALSE; current_mode.mode = strdup(MODE_UNDEFINED); @@ -571,8 +569,7 @@ static void usb_moded_init(void) } /* kmod init */ - ctx = kmod_new(NULL, NULL); - kmod_load_resources(ctx); + usb_moded_module_ctx_init(); /* Android specific stuff */ if(android_settings()) @@ -607,8 +604,6 @@ static gboolean charging_fallback(gpointer data) static void handle_exit(void) { - extern struct kmod_ctx *ctx; - /* exiting and clean-up when mainloop ended */ appsync_stop(); hwal_cleanup(); @@ -618,7 +613,7 @@ static void handle_exit(void) #endif /* MEEGOLOCK */ free_mode_list(modelist); - kmod_unref(ctx); + usb_moded_module_ctx_cleanup(); #ifdef APP_SYNC free_appsync_list();