@@ -63,7 +63,8 @@ static void ipmi_debug_msg(const char *title, unsigned char *data,
63
63
{ }
64
64
#endif
65
65
66
- static int initialized ;
66
+ static bool initialized ;
67
+ static bool drvregistered ;
67
68
68
69
enum ipmi_panic_event_op {
69
70
IPMI_SEND_PANIC_EVENT_NONE ,
@@ -613,7 +614,7 @@ static DEFINE_MUTEX(ipmidriver_mutex);
613
614
614
615
static LIST_HEAD (ipmi_interfaces );
615
616
static DEFINE_MUTEX (ipmi_interfaces_mutex );
616
- DEFINE_STATIC_SRCU ( ipmi_interfaces_srcu ) ;
617
+ struct srcu_struct ipmi_interfaces_srcu ;
617
618
618
619
/*
619
620
* List of watchers that want to know when smi's are added and deleted.
@@ -721,7 +722,15 @@ struct watcher_entry {
721
722
int ipmi_smi_watcher_register (struct ipmi_smi_watcher * watcher )
722
723
{
723
724
struct ipmi_smi * intf ;
724
- int index ;
725
+ int index , rv ;
726
+
727
+ /*
728
+ * Make sure the driver is actually initialized, this handles
729
+ * problems with initialization order.
730
+ */
731
+ rv = ipmi_init_msghandler ();
732
+ if (rv )
733
+ return rv ;
725
734
726
735
mutex_lock (& smi_watchers_mutex );
727
736
@@ -1077,7 +1086,7 @@ int ipmi_create_user(unsigned int if_num,
1077
1086
{
1078
1087
unsigned long flags ;
1079
1088
struct ipmi_user * new_user ;
1080
- int rv = 0 , index ;
1089
+ int rv , index ;
1081
1090
struct ipmi_smi * intf ;
1082
1091
1083
1092
/*
@@ -1095,18 +1104,9 @@ int ipmi_create_user(unsigned int if_num,
1095
1104
* Make sure the driver is actually initialized, this handles
1096
1105
* problems with initialization order.
1097
1106
*/
1098
- if (!initialized ) {
1099
- rv = ipmi_init_msghandler ();
1100
- if (rv )
1101
- return rv ;
1102
-
1103
- /*
1104
- * The init code doesn't return an error if it was turned
1105
- * off, but it won't initialize. Check that.
1106
- */
1107
- if (!initialized )
1108
- return - ENODEV ;
1109
- }
1107
+ rv = ipmi_init_msghandler ();
1108
+ if (rv )
1109
+ return rv ;
1110
1110
1111
1111
new_user = kmalloc (sizeof (* new_user ), GFP_KERNEL );
1112
1112
if (!new_user )
@@ -3301,17 +3301,9 @@ int ipmi_register_smi(const struct ipmi_smi_handlers *handlers,
3301
3301
* Make sure the driver is actually initialized, this handles
3302
3302
* problems with initialization order.
3303
3303
*/
3304
- if (!initialized ) {
3305
- rv = ipmi_init_msghandler ();
3306
- if (rv )
3307
- return rv ;
3308
- /*
3309
- * The init code doesn't return an error if it was turned
3310
- * off, but it won't initialize. Check that.
3311
- */
3312
- if (!initialized )
3313
- return - ENODEV ;
3314
- }
3304
+ rv = ipmi_init_msghandler ();
3305
+ if (rv )
3306
+ return rv ;
3315
3307
3316
3308
intf = kzalloc (sizeof (* intf ), GFP_KERNEL );
3317
3309
if (!intf )
@@ -5027,6 +5019,22 @@ static int panic_event(struct notifier_block *this,
5027
5019
return NOTIFY_DONE ;
5028
5020
}
5029
5021
5022
+ /* Must be called with ipmi_interfaces_mutex held. */
5023
+ static int ipmi_register_driver (void )
5024
+ {
5025
+ int rv ;
5026
+
5027
+ if (drvregistered )
5028
+ return 0 ;
5029
+
5030
+ rv = driver_register (& ipmidriver .driver );
5031
+ if (rv )
5032
+ pr_err ("Could not register IPMI driver\n" );
5033
+ else
5034
+ drvregistered = true;
5035
+ return rv ;
5036
+ }
5037
+
5030
5038
static struct notifier_block panic_block = {
5031
5039
.notifier_call = panic_event ,
5032
5040
.next = NULL ,
@@ -5037,66 +5045,75 @@ static int ipmi_init_msghandler(void)
5037
5045
{
5038
5046
int rv ;
5039
5047
5048
+ mutex_lock (& ipmi_interfaces_mutex );
5049
+ rv = ipmi_register_driver ();
5050
+ if (rv )
5051
+ goto out ;
5040
5052
if (initialized )
5041
- return 0 ;
5053
+ goto out ;
5042
5054
5043
- rv = driver_register (& ipmidriver .driver );
5044
- if (rv ) {
5045
- pr_err ("Could not register IPMI driver\n" );
5046
- return rv ;
5047
- }
5048
-
5049
- pr_info ("version " IPMI_DRIVER_VERSION "\n" );
5055
+ init_srcu_struct (& ipmi_interfaces_srcu );
5050
5056
5051
5057
timer_setup (& ipmi_timer , ipmi_timeout , 0 );
5052
5058
mod_timer (& ipmi_timer , jiffies + IPMI_TIMEOUT_JIFFIES );
5053
5059
5054
5060
atomic_notifier_chain_register (& panic_notifier_list , & panic_block );
5055
5061
5056
- initialized = 1 ;
5062
+ initialized = true ;
5057
5063
5058
- return 0 ;
5064
+ out :
5065
+ mutex_unlock (& ipmi_interfaces_mutex );
5066
+ return rv ;
5059
5067
}
5060
5068
5061
5069
static int __init ipmi_init_msghandler_mod (void )
5062
5070
{
5063
- ipmi_init_msghandler ();
5064
- return 0 ;
5071
+ int rv ;
5072
+
5073
+ pr_info ("version " IPMI_DRIVER_VERSION "\n" );
5074
+
5075
+ mutex_lock (& ipmi_interfaces_mutex );
5076
+ rv = ipmi_register_driver ();
5077
+ mutex_unlock (& ipmi_interfaces_mutex );
5078
+
5079
+ return rv ;
5065
5080
}
5066
5081
5067
5082
static void __exit cleanup_ipmi (void )
5068
5083
{
5069
5084
int count ;
5070
5085
5071
- if (!initialized )
5072
- return ;
5073
-
5074
- atomic_notifier_chain_unregister (& panic_notifier_list , & panic_block );
5086
+ if (initialized ) {
5087
+ atomic_notifier_chain_unregister (& panic_notifier_list ,
5088
+ & panic_block );
5075
5089
5076
- /*
5077
- * This can't be called if any interfaces exist, so no worry
5078
- * about shutting down the interfaces.
5079
- */
5090
+ /*
5091
+ * This can't be called if any interfaces exist, so no worry
5092
+ * about shutting down the interfaces.
5093
+ */
5080
5094
5081
- /*
5082
- * Tell the timer to stop, then wait for it to stop. This
5083
- * avoids problems with race conditions removing the timer
5084
- * here.
5085
- */
5086
- atomic_inc (& stop_operation );
5087
- del_timer_sync (& ipmi_timer );
5095
+ /*
5096
+ * Tell the timer to stop, then wait for it to stop. This
5097
+ * avoids problems with race conditions removing the timer
5098
+ * here.
5099
+ */
5100
+ atomic_inc (& stop_operation );
5101
+ del_timer_sync (& ipmi_timer );
5088
5102
5089
- driver_unregister ( & ipmidriver . driver ) ;
5103
+ initialized = false ;
5090
5104
5091
- initialized = 0 ;
5105
+ /* Check for buffer leaks. */
5106
+ count = atomic_read (& smi_msg_inuse_count );
5107
+ if (count != 0 )
5108
+ pr_warn ("SMI message count %d at exit\n" , count );
5109
+ count = atomic_read (& recv_msg_inuse_count );
5110
+ if (count != 0 )
5111
+ pr_warn ("recv message count %d at exit\n" , count );
5092
5112
5093
- /* Check for buffer leaks. */
5094
- count = atomic_read (& smi_msg_inuse_count );
5095
- if (count != 0 )
5096
- pr_warn ("SMI message count %d at exit\n" , count );
5097
- count = atomic_read (& recv_msg_inuse_count );
5098
- if (count != 0 )
5099
- pr_warn ("recv message count %d at exit\n" , count );
5113
+ cleanup_srcu_struct (& ipmi_interfaces_srcu );
5114
+ }
5115
+ if (drvregistered )
5116
+ driver_unregister (& ipmidriver .driver );
5100
5117
}
5101
5118
module_exit (cleanup_ipmi );
5102
5119
0 commit comments