Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
[linux-drm-fsl-dcu.git] / drivers / char / ipmi / ipmi_msghandler.c
index 5703ee28e1cc0b97adb7488db3b843b2715290ca..3aff5e99b674360bad4fa42407d70a9d594656e4 100644 (file)
 static struct ipmi_recv_msg *ipmi_alloc_recv_msg(void);
 static int ipmi_init_msghandler(void);
 
-static int initialized = 0;
+static int initialized;
 
 #ifdef CONFIG_PROC_FS
-static struct proc_dir_entry *proc_ipmi_root = NULL;
+static struct proc_dir_entry *proc_ipmi_root;
 #endif /* CONFIG_PROC_FS */
 
 /* Remain in auto-maintenance mode for this amount of time (in ms). */
@@ -406,13 +406,14 @@ static void clean_up_interface_data(ipmi_smi_t intf)
        free_smi_msg_list(&intf->waiting_msgs);
        free_recv_msg_list(&intf->waiting_events);
 
-       /* Wholesale remove all the entries from the list in the
-        * interface and wait for RCU to know that none are in use. */
+       /*
+        * Wholesale remove all the entries from the list in the
+        * interface and wait for RCU to know that none are in use.
+        */
        mutex_lock(&intf->cmd_rcvrs_mutex);
-       list_add_rcu(&list, &intf->cmd_rcvrs);
-       list_del_rcu(&intf->cmd_rcvrs);
+       INIT_LIST_HEAD(&list);
+       list_splice_init_rcu(&intf->cmd_rcvrs, &list, synchronize_rcu);
        mutex_unlock(&intf->cmd_rcvrs_mutex);
-       synchronize_rcu();
 
        list_for_each_entry_safe(rcvr, rcvr2, &list, link)
                kfree(rcvr);
@@ -451,7 +452,7 @@ int ipmi_smi_watcher_register(struct ipmi_smi_watcher *watcher)
        mutex_lock(&ipmi_interfaces_mutex);
 
        /* Build a list of things to deliver. */
-       list_for_each_entry_rcu(intf, &ipmi_interfaces, link) {
+       list_for_each_entry(intf, &ipmi_interfaces, link) {
                if (intf->intf_num == -1)
                        continue;
                e = kmalloc(sizeof(*e), GFP_KERNEL);
@@ -1886,7 +1887,6 @@ int ipmi_smi_add_proc_entry(ipmi_smi_t smi, char *name,
                kfree(entry);
                rv = -ENOMEM;
        } else {
-               file->nlink = 1;
                file->data = data;
                file->read_proc = read_proc;
                file->write_proc = write_proc;
@@ -2142,8 +2142,7 @@ cleanup_bmc_device(struct kref *ref)
        bmc = container_of(ref, struct bmc_device, refcount);
 
        remove_files(bmc);
-       if (bmc->dev)
-               platform_device_unregister(bmc->dev);
+       platform_device_unregister(bmc->dev);
        kfree(bmc);
 }
 
@@ -2341,8 +2340,7 @@ static int ipmi_bmc_register(ipmi_smi_t intf, int ifnum,
 
                while (ipmi_find_bmc_prod_dev_id(&ipmidriver,
                                                 bmc->id.product_id,
-                                                bmc->id.device_id))
-               {
+                                                bmc->id.device_id)) {
                        if (!warn_printed) {
                                printk(KERN_WARNING PFX
                                       "This machine has two different BMCs"
@@ -2762,9 +2760,15 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
                synchronize_rcu();
                kref_put(&intf->refcount, intf_free);
        } else {
-               /* After this point the interface is legal to use. */
+               /*
+                * Keep memory order straight for RCU readers.  Make
+                * sure everything else is committed to memory before
+                * setting intf_num to mark the interface valid.
+                */
+               smp_wmb();
                intf->intf_num = i;
                mutex_unlock(&ipmi_interfaces_mutex);
+               /* After this point the interface is legal to use. */
                call_smi_watchers(i, intf->si_dev);
                mutex_unlock(&smi_watchers_mutex);
        }
@@ -3651,8 +3655,6 @@ static void ipmi_timeout_handler(long timeout_period)
        unsigned long        flags;
        int                  i;
 
-       INIT_LIST_HEAD(&timeouts);
-
        rcu_read_lock();
        list_for_each_entry_rcu(intf, &ipmi_interfaces, link) {
                /* See if any waiting messages need to be processed. */
@@ -3673,6 +3675,7 @@ static void ipmi_timeout_handler(long timeout_period)
                /* Go through the seq table and find any messages that
                   have timed out, putting them in the timeouts
                   list. */
+               INIT_LIST_HEAD(&timeouts);
                spin_lock_irqsave(&intf->seq_lock, flags);
                for (i = 0; i < IPMI_IPMB_NUM_SEQ; i++)
                        check_msg_timeout(intf, &(intf->seq_table[i]),
@@ -3926,6 +3929,14 @@ static void send_panic_events(char *str)
                        /* Interface was not ready yet. */
                        continue;
 
+               /*
+                * intf_num is used as an marker to tell if the
+                * interface is valid.  Thus we need a read barrier to
+                * make sure data fetched before checking intf_num
+                * won't be used.
+                */
+               smp_rmb();
+
                /* First job here is to figure out where to send the
                   OEM events.  There's no way in IPMI to send OEM
                   events using an event send command, so we have to
@@ -4043,7 +4054,7 @@ static void send_panic_events(char *str)
 }
 #endif /* CONFIG_IPMI_PANIC_EVENT */
 
-static int has_panicked = 0;
+static int has_panicked;
 
 static int panic_event(struct notifier_block *this,
                       unsigned long         event,