[SCSI] fix scsi_setup_command_freelist failure path race
[GitHub/moto-9609/android_kernel_motorola_exynos9610.git] / drivers / scsi / scsi.c
index 412a351c6cf77ba3b7f36bc45fd5fd75c96a8309..54ff611b8677cb9fc414bb0fe2a22e860dfa997a 100644 (file)
@@ -319,17 +319,16 @@ int scsi_setup_command_freelist(struct Scsi_Host *shost)
                        GFP_KERNEL | shost->cmd_pool->gfp_mask);
        if (!cmd)
                goto fail2;
-       list_add(&cmd->list, &shost->free_list);                
+       list_add(&cmd->list, &shost->free_list);
        return 0;
 
  fail2:
+       mutex_lock(&host_cmd_pool_mutex);
        if (!--pool->users)
                kmem_cache_destroy(pool->slab);
-       return -ENOMEM;
  fail:
        mutex_unlock(&host_cmd_pool_mutex);
        return -ENOMEM;
-
 }
 
 /**
@@ -960,7 +959,7 @@ EXPORT_SYMBOL(__starget_for_each_device);
  * reference.  You must hold the host's host_lock over this call and
  * any access to the returned scsi_device.
  *
- * Note:  The only reason why drivers would want to use this is because
+ * Note:  The only reason why drivers should use this is because
  * they need to access the device list in irq context.  Otherwise you
  * really want to use scsi_device_lookup_by_target instead.
  **/