agp - fix potential panic
authorAlex Hornung <ahornung@gmail.com>
Fri, 24 Feb 2012 19:49:10 +0000 (19:49 +0000)
committerAlex Hornung <ahornung@gmail.com>
Fri, 24 Feb 2012 19:49:10 +0000 (19:49 +0000)
 * Fix a potential panic when close() is called on an agp device that
   hasn't been opened.

 * Check whether it's open (and has been busied) before trying to unbusy
   it.

Reported-by: Pierre Abbat
DragonFly-bug: http://bugs.dragonflybsd.org/issue2310

sys/dev/agp/agp.c

index bf4e0bd..71ef88d 100644 (file)
@@ -794,8 +794,10 @@ agp_close(struct dev_close_args *ap)
        }
        if (sc->as_state == AGP_ACQUIRE_USER)
                agp_release_helper(dev, AGP_ACQUIRE_USER);
-       sc->as_isopen = 0;
-       device_unbusy(dev);
+       if (sc->as_isopen) {
+               sc->as_isopen = 0;
+               device_unbusy(dev);
+       }
 
        return 0;
 }