staging: unisys: clean up initiate_chipset_device_pause_resume()
authorBenjamin Romer <benjamin.romer@unisys.com>
Tue, 23 Feb 2016 15:01:54 +0000 (10:01 -0500)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 26 Feb 2016 06:40:52 +0000 (22:40 -0800)
Simplify this function by removing the goto in favor of handling errors
immediately. Eliminate the vaguely-named variable x, and remove the
unneeded initialization of rc. Lastly, provide meaningful error values
to the callback function instead of just passing back a -1 for failure.

Signed-off-by: Benjamin Romer <benjamin.romer@unisys.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/staging/unisys/visorbus/visorbus_main.c

index bf04df3..4f7d743 100644 (file)
@@ -1397,7 +1397,7 @@ resume_state_change_complete(struct visor_device *dev, int status)
 static void
 initiate_chipset_device_pause_resume(struct visor_device *dev, bool is_pause)
 {
-       int rc = -1, x;
+       int rc;
        struct visor_driver *drv = NULL;
        void (*notify_func)(struct visor_device *dev, int response) = NULL;
 
@@ -1406,14 +1406,18 @@ initiate_chipset_device_pause_resume(struct visor_device *dev, bool is_pause)
        else
                notify_func = chipset_responders.device_resume;
        if (!notify_func)
-               goto away;
+               return;
 
        drv = to_visor_driver(dev->device.driver);
-       if (!drv)
-               goto away;
+       if (!drv) {
+               (*notify_func)(dev, -ENODEV);
+               return;
+       }
 
-       if (dev->pausing || dev->resuming)
-               goto away;
+       if (dev->pausing || dev->resuming) {
+               (*notify_func)(dev, -EBUSY);
+               return;
+       }
 
        /* Note that even though both drv->pause() and drv->resume
         * specify a callback function, it is NOT necessary for us to
@@ -1423,11 +1427,13 @@ initiate_chipset_device_pause_resume(struct visor_device *dev, bool is_pause)
         * visorbus while child function drivers are still running.
         */
        if (is_pause) {
-               if (!drv->pause)
-                       goto away;
+               if (!drv->pause) {
+                       (*notify_func)(dev, -EINVAL);
+                       return;
+               }
 
                dev->pausing = true;
-               x = drv->pause(dev, pause_state_change_complete);
+               rc = drv->pause(dev, pause_state_change_complete);
        } else {
                /* This should be done at BUS resume time, but an
                 * existing problem prevents us from ever getting a bus
@@ -1436,24 +1442,20 @@ initiate_chipset_device_pause_resume(struct visor_device *dev, bool is_pause)
                 * would never even get here in that case.
                 */
                fix_vbus_dev_info(dev);
-               if (!drv->resume)
-                       goto away;
+               if (!drv->resume) {
+                       (*notify_func)(dev, -EINVAL);
+                       return;
+               }
 
                dev->resuming = true;
-               x = drv->resume(dev, resume_state_change_complete);
+               rc = drv->resume(dev, resume_state_change_complete);
        }
-       if (x < 0) {
+       if (rc < 0) {
                if (is_pause)
                        dev->pausing = false;
                else
                        dev->resuming = false;
-               goto away;
-       }
-       rc = 0;
-away:
-       if (rc < 0) {
-               if (notify_func)
-                       (*notify_func)(dev, rc);
+               (*notify_func)(dev, -EINVAL);
        }
 }