fix broken/dubious driver suspend() methods
authorDavid Brownell <david-b@pacbell.net>
Tue, 15 Aug 2006 06:11:03 +0000 (23:11 -0700)
committerGreg Kroah-Hartman <gregkh@suse.de>
Tue, 26 Sep 2006 04:08:37 +0000 (21:08 -0700)
Small driver suspend() fixes in preparation for the PRETHAW events:

 - Only compare message events for equality against PM_EVENT_* codes;
   not against integers, or using greater/less-than comparisons.
   (PM_EVENT_* should really become a __bitwise thing.)

 - Explicitly test for SUSPEND events (rather than not-something-else)
   before suspending devices.

 - Removes more of the confusion between a pm_message_t (wraps event code)
   and a "state" ... suspend() originally took a target system state.

These updates are correct and appropriate even without new PM_EVENT codes.

benh: "I think in the Mesh case, we should handle the freeze case as well or
we might get wild DMA."

Signed-off-by: David Brownell <dbrownell@users.sourceforge.net>
Acked-by: Pavel Machek <pavel@ucw.cz>
Cc: Greg KH <greg@kroah.com>
Cc: Paul Mackerras <paulus@samba.org>
Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Mauro Carvalho Chehab <mchehab@infradead.org>
Cc: James Bottomley <James.Bottomley@steeleye.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/ide/ppc/pmac.c
drivers/media/dvb/cinergyT2/cinergyT2.c
drivers/scsi/mesh.c

index 996c694341bc33d47971d1ef0a01c8d42adc3982..31ad79f52df72386b5b99ec334353dd8d3240e5b 100644 (file)
@@ -1369,15 +1369,16 @@ pmac_ide_macio_attach(struct macio_dev *mdev, const struct of_device_id *match)
 }
 
 static int
-pmac_ide_macio_suspend(struct macio_dev *mdev, pm_message_t state)
+pmac_ide_macio_suspend(struct macio_dev *mdev, pm_message_t mesg)
 {
        ide_hwif_t      *hwif = (ide_hwif_t *)dev_get_drvdata(&mdev->ofdev.dev);
        int             rc = 0;
 
-       if (state.event != mdev->ofdev.dev.power.power_state.event && state.event >= PM_EVENT_SUSPEND) {
+       if (mesg.event != mdev->ofdev.dev.power.power_state.event
+                       && mesg.event == PM_EVENT_SUSPEND) {
                rc = pmac_ide_do_suspend(hwif);
                if (rc == 0)
-                       mdev->ofdev.dev.power.power_state = state;
+                       mdev->ofdev.dev.power.power_state = mesg;
        }
 
        return rc;
@@ -1473,15 +1474,16 @@ pmac_ide_pci_attach(struct pci_dev *pdev, const struct pci_device_id *id)
 }
 
 static int
-pmac_ide_pci_suspend(struct pci_dev *pdev, pm_message_t state)
+pmac_ide_pci_suspend(struct pci_dev *pdev, pm_message_t mesg)
 {
        ide_hwif_t      *hwif = (ide_hwif_t *)pci_get_drvdata(pdev);
        int             rc = 0;
        
-       if (state.event != pdev->dev.power.power_state.event && state.event >= 2) {
+       if (mesg.event != pdev->dev.power.power_state.event
+                       && mesg.event == PM_EVENT_SUSPEND) {
                rc = pmac_ide_do_suspend(hwif);
                if (rc == 0)
-                       pdev->dev.power.power_state = state;
+                       pdev->dev.power.power_state = mesg;
        }
 
        return rc;
index 001c71b6be61a970a59aad312bf59b65ab706e54..410fa6d620ff930daa43744a54e6a53880d28cf5 100644 (file)
@@ -981,7 +981,7 @@ static int cinergyt2_suspend (struct usb_interface *intf, pm_message_t state)
        if (cinergyt2->disconnect_pending || mutex_lock_interruptible(&cinergyt2->sem))
                return -ERESTARTSYS;
 
-       if (state.event > PM_EVENT_ON) {
+       if (1) {
                struct cinergyt2 *cinergyt2 = usb_get_intfdata (intf);
 
                cinergyt2_suspend_rc(cinergyt2);
index 592b52afe6582ceed90c1870617b061b6d3a2e24..683fc7ae4b8ffb1f52823779d81b852db3fb2274 100644 (file)
@@ -1756,16 +1756,23 @@ static void set_mesh_power(struct mesh_state *ms, int state)
                pmac_call_feature(PMAC_FTR_MESH_ENABLE, macio_get_of_node(ms->mdev), 0, 0);
                msleep(10);
        }
-}                      
+}
 
 
 #ifdef CONFIG_PM
-static int mesh_suspend(struct macio_dev *mdev, pm_message_t state)
+static int mesh_suspend(struct macio_dev *mdev, pm_message_t mesg)
 {
        struct mesh_state *ms = (struct mesh_state *)macio_get_drvdata(mdev);
        unsigned long flags;
 
-       if (state.event == mdev->ofdev.dev.power.power_state.event || state.event < 2)
+       switch (mesg.event) {
+       case PM_EVENT_SUSPEND:
+       case PM_EVENT_FREEZE:
+               break;
+       default:
+               return 0;
+       }
+       if (mesg.event == mdev->ofdev.dev.power.power_state.event)
                return 0;
 
        scsi_block_requests(ms->host);
@@ -1780,7 +1787,7 @@ static int mesh_suspend(struct macio_dev *mdev, pm_message_t state)
        disable_irq(ms->meshintr);
        set_mesh_power(ms, 0);
 
-       mdev->ofdev.dev.power.power_state = state;
+       mdev->ofdev.dev.power.power_state = mesg;
 
        return 0;
 }