@@ -641,8 +641,6 @@ static int module_unload_init(struct module *mod)
641641
642642 /* Hold reference count during initialization. */
643643 __this_cpu_write (mod -> refptr -> incs , 1 );
644- /* Backwards compatibility macros put refcount during init. */
645- mod -> waiter = current ;
646644
647645 return 0 ;
648646}
@@ -768,16 +766,9 @@ static int __try_stop_module(void *_sref)
768766
769767static int try_stop_module (struct module * mod , int flags , int * forced )
770768{
771- if (flags & O_NONBLOCK ) {
772- struct stopref sref = { mod , flags , forced };
769+ struct stopref sref = { mod , flags , forced };
773770
774- return stop_machine (__try_stop_module , & sref , NULL );
775- } else {
776- /* We don't need to stop the machine for this. */
777- mod -> state = MODULE_STATE_GOING ;
778- synchronize_sched ();
779- return 0 ;
780- }
771+ return stop_machine (__try_stop_module , & sref , NULL );
781772}
782773
783774unsigned long module_refcount (struct module * mod )
@@ -810,21 +801,6 @@ EXPORT_SYMBOL(module_refcount);
810801/* This exists whether we can unload or not */
811802static void free_module (struct module * mod );
812803
813- static void wait_for_zero_refcount (struct module * mod )
814- {
815- /* Since we might sleep for some time, release the mutex first */
816- mutex_unlock (& module_mutex );
817- for (;;) {
818- pr_debug ("Looking at refcount...\n" );
819- set_current_state (TASK_UNINTERRUPTIBLE );
820- if (module_refcount (mod ) == 0 )
821- break ;
822- schedule ();
823- }
824- current -> state = TASK_RUNNING ;
825- mutex_lock (& module_mutex );
826- }
827-
828804SYSCALL_DEFINE2 (delete_module , const char __user * , name_user ,
829805 unsigned int , flags )
830806{
@@ -839,6 +815,11 @@ SYSCALL_DEFINE2(delete_module, const char __user *, name_user,
839815 return - EFAULT ;
840816 name [MODULE_NAME_LEN - 1 ] = '\0' ;
841817
818+ if (!(flags & O_NONBLOCK )) {
819+ printk (KERN_WARNING
820+ "waiting module removal not supported: please upgrade" );
821+ }
822+
842823 if (mutex_lock_interruptible (& module_mutex ) != 0 )
843824 return - EINTR ;
844825
@@ -856,8 +837,7 @@ SYSCALL_DEFINE2(delete_module, const char __user *, name_user,
856837
857838 /* Doing init or already dying? */
858839 if (mod -> state != MODULE_STATE_LIVE ) {
859- /* FIXME: if (force), slam module count and wake up
860- waiter --RR */
840+ /* FIXME: if (force), slam module count damn the torpedoes */
861841 pr_debug ("%s already dying\n" , mod -> name );
862842 ret = - EBUSY ;
863843 goto out ;
@@ -873,18 +853,11 @@ SYSCALL_DEFINE2(delete_module, const char __user *, name_user,
873853 }
874854 }
875855
876- /* Set this up before setting mod->state */
877- mod -> waiter = current ;
878-
879856 /* Stop the machine so refcounts can't move and disable module. */
880857 ret = try_stop_module (mod , flags , & forced );
881858 if (ret != 0 )
882859 goto out ;
883860
884- /* Never wait if forced. */
885- if (!forced && module_refcount (mod ) != 0 )
886- wait_for_zero_refcount (mod );
887-
888861 mutex_unlock (& module_mutex );
889862 /* Final destruction now no one is using it. */
890863 if (mod -> exit != NULL )
@@ -1002,9 +975,6 @@ void module_put(struct module *module)
1002975 __this_cpu_inc (module -> refptr -> decs );
1003976
1004977 trace_module_put (module , _RET_IP_ );
1005- /* Maybe they're waiting for us to drop reference? */
1006- if (unlikely (!module_is_live (module )))
1007- wake_up_process (module -> waiter );
1008978 preempt_enable ();
1009979 }
1010980}
@@ -2728,7 +2698,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
27282698 return 0 ;
27292699}
27302700
2731- static void find_module_sections (struct module * mod , struct load_info * info )
2701+ static int find_module_sections (struct module * mod , struct load_info * info )
27322702{
27332703 mod -> kp = section_objs (info , "__param" ,
27342704 sizeof (* mod -> kp ), & mod -> num_kp );
@@ -2758,6 +2728,18 @@ static void find_module_sections(struct module *mod, struct load_info *info)
27582728#ifdef CONFIG_CONSTRUCTORS
27592729 mod -> ctors = section_objs (info , ".ctors" ,
27602730 sizeof (* mod -> ctors ), & mod -> num_ctors );
2731+ if (!mod -> ctors )
2732+ mod -> ctors = section_objs (info , ".init_array" ,
2733+ sizeof (* mod -> ctors ), & mod -> num_ctors );
2734+ else if (find_sec (info , ".init_array" )) {
2735+ /*
2736+ * This shouldn't happen with same compiler and binutils
2737+ * building all parts of the module.
2738+ */
2739+ printk (KERN_WARNING "%s: has both .ctors and .init_array.\n" ,
2740+ mod -> name );
2741+ return - EINVAL ;
2742+ }
27612743#endif
27622744
27632745#ifdef CONFIG_TRACEPOINTS
@@ -2795,6 +2777,8 @@ static void find_module_sections(struct module *mod, struct load_info *info)
27952777
27962778 info -> debug = section_objs (info , "__verbose" ,
27972779 sizeof (* info -> debug ), & info -> num_debug );
2780+
2781+ return 0 ;
27982782}
27992783
28002784static int move_module (struct module * mod , struct load_info * info )
@@ -3248,7 +3232,9 @@ static int load_module(struct load_info *info, const char __user *uargs,
32483232
32493233 /* Now we've got everything in the final locations, we can
32503234 * find optional sections. */
3251- find_module_sections (mod , info );
3235+ err = find_module_sections (mod , info );
3236+ if (err )
3237+ goto free_unload ;
32523238
32533239 err = check_module_license_and_versions (mod );
32543240 if (err )
0 commit comments