Merge tag 'docs-4.16' of git://git.lwn.net/linux
[sfrench/cifs-2.6.git] / drivers / char / ipmi / ipmi_si_intf.c
index 71fad747c0c7c1052cc19ee3bad0568b4a80c55b..6768cb2dd740e692aeac2480ce8841be9e24ae2b 100644 (file)
@@ -1938,8 +1938,10 @@ static void check_for_broken_irqs(struct smi_info *smi_info)
 
 static inline void stop_timer_and_thread(struct smi_info *smi_info)
 {
-       if (smi_info->thread != NULL)
+       if (smi_info->thread != NULL) {
                kthread_stop(smi_info->thread);
+               smi_info->thread = NULL;
+       }
 
        smi_info->timer_can_start = false;
        if (smi_info->timer_running)
@@ -2045,6 +2047,7 @@ static int try_smi_init(struct smi_info *new_smi)
        int rv = 0;
        int i;
        char *init_name = NULL;
+       bool platform_device_registered = false;
 
        pr_info(PFX "Trying %s-specified %s state machine at %s address 0x%lx, slave address 0x%x, irq %d\n",
                ipmi_addr_src_to_str(new_smi->io.addr_source),
@@ -2173,6 +2176,7 @@ static int try_smi_init(struct smi_info *new_smi)
                                rv);
                        goto out_err;
                }
+               platform_device_registered = true;
        }
 
        dev_set_drvdata(new_smi->io.dev, new_smi);
@@ -2279,10 +2283,11 @@ out_err:
        }
 
        if (new_smi->pdev) {
-               platform_device_unregister(new_smi->pdev);
+               if (platform_device_registered)
+                       platform_device_unregister(new_smi->pdev);
+               else
+                       platform_device_put(new_smi->pdev);
                new_smi->pdev = NULL;
-       } else if (new_smi->pdev) {
-               platform_device_put(new_smi->pdev);
        }
 
        kfree(init_name);