drivers: power: report battery voltage in AOSP compatible format
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / scsi / scsi_sysfs.c
index 931a7d9542038138537a5b76a98fa27217a95d63..53da653988ec863f65d03dda2deb515d2156d880 100644 (file)
@@ -332,17 +332,14 @@ static void scsi_device_dev_release_usercontext(struct work_struct *work)
 {
        struct scsi_device *sdev;
        struct device *parent;
-       struct scsi_target *starget;
        struct list_head *this, *tmp;
        unsigned long flags;
 
        sdev = container_of(work, struct scsi_device, ew.work);
 
        parent = sdev->sdev_gendev.parent;
-       starget = to_scsi_target(parent);
 
        spin_lock_irqsave(sdev->host->host_lock, flags);
-       starget->reap_ref++;
        list_del(&sdev->siblings);
        list_del(&sdev->same_target_siblings);
        list_del(&sdev->starved_entry);
@@ -362,8 +359,6 @@ static void scsi_device_dev_release_usercontext(struct work_struct *work)
        /* NULL queue means the device can't be used */
        sdev->request_queue = NULL;
 
-       scsi_target_reap(scsi_target(sdev));
-
        kfree(sdev->inquiry);
        kfree(sdev);
 
@@ -794,7 +789,7 @@ sdev_store_queue_ramp_up_period(struct device *dev,
                return -EINVAL;
 
        sdev->queue_ramp_up_period = msecs_to_jiffies(period);
-       return period;
+       return count;
 }
 
 static struct device_attribute sdev_attr_queue_ramp_up_period =
@@ -870,10 +865,6 @@ int scsi_sysfs_add_sdev(struct scsi_device *sdev)
        struct request_queue *rq = sdev->request_queue;
        struct scsi_target *starget = sdev->sdev_target;
 
-       error = scsi_device_set_state(sdev, SDEV_RUNNING);
-       if (error)
-               return error;
-
        error = scsi_target_add(starget);
        if (error)
                return error;
@@ -978,6 +969,13 @@ void __scsi_remove_device(struct scsi_device *sdev)
                sdev->host->hostt->slave_destroy(sdev);
        transport_destroy_device(dev);
 
+       /*
+        * Paired with the kref_get() in scsi_sysfs_initialize().  We have
+        * remoed sysfs visibility from the device, so make the target
+        * invisible if this was the last device underneath it.
+        */
+       scsi_target_reap(scsi_target(sdev));
+
        put_device(dev);
 }
 
@@ -1028,31 +1026,25 @@ static void __scsi_remove_target(struct scsi_target *starget)
 void scsi_remove_target(struct device *dev)
 {
        struct Scsi_Host *shost = dev_to_shost(dev->parent);
-       struct scsi_target *starget, *last = NULL;
+       struct scsi_target *starget, *last_target = NULL;
        unsigned long flags;
 
-       /* remove targets being careful to lookup next entry before
-        * deleting the last
-        */
+restart:
        spin_lock_irqsave(shost->host_lock, flags);
        list_for_each_entry(starget, &shost->__targets, siblings) {
-               if (starget->state == STARGET_DEL)
+               if (starget->state == STARGET_DEL ||
+                   starget == last_target)
                        continue;
                if (starget->dev.parent == dev || &starget->dev == dev) {
-                       /* assuming new targets arrive at the end */
-                       starget->reap_ref++;
+                       kref_get(&starget->reap_ref);
+                       last_target = starget;
                        spin_unlock_irqrestore(shost->host_lock, flags);
-                       if (last)
-                               scsi_target_reap(last);
-                       last = starget;
                        __scsi_remove_target(starget);
-                       spin_lock_irqsave(shost->host_lock, flags);
+                       scsi_target_reap(starget);
+                       goto restart;
                }
        }
        spin_unlock_irqrestore(shost->host_lock, flags);
-
-       if (last)
-               scsi_target_reap(last);
 }
 EXPORT_SYMBOL(scsi_remove_target);
 
@@ -1124,6 +1116,12 @@ void scsi_sysfs_device_initialize(struct scsi_device *sdev)
        list_add_tail(&sdev->same_target_siblings, &starget->devices);
        list_add_tail(&sdev->siblings, &shost->__devices);
        spin_unlock_irqrestore(shost->host_lock, flags);
+       /*
+        * device can now only be removed via __scsi_remove_device() so hold
+        * the target.  Target will be held in CREATED state until something
+        * beneath it becomes visible (in which case it moves to RUNNING)
+        */
+       kref_get(&starget->reap_ref);
 }
 
 int scsi_is_sdev_device(const struct device *dev)