staging: comedi: unioxx5: fix unioxx5_detach()
[pandora-kernel.git] / drivers / staging / comedi / drivers / unioxx5.c
index 0c24347..fc88b66 100644 (file)
  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
  *  GNU General Public License for more details.                           *
  *                                                                         *
- *  You should have received a copy of the GNU General Public License      *
- *  along with this program; if not, write to the Free Software            *
- *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.              *
- *                                                                         *
  ***************************************************************************/
 /*
 
@@ -478,15 +474,16 @@ static int unioxx5_attach(struct comedi_device *dev,
 
 static void unioxx5_detach(struct comedi_device *dev)
 {
+       struct comedi_subdevice *s;
+       struct unioxx5_subd_priv *spriv;
        int i;
-       struct comedi_subdevice *subdev;
-       struct unioxx5_subd_priv *usp;
 
        for (i = 0; i < dev->n_subdevices; i++) {
-               subdev = &dev->subdevices[i];
-               usp = subdev->private;
-               release_region(usp->usp_iobase, UNIOXX5_SIZE);
-               kfree(subdev->private);
+               s = &dev->subdevices[i];
+               spriv = s->private;
+               if (spriv && spriv->usp_iobase)
+                       release_region(spriv->usp_iobase, UNIOXX5_SIZE);
+               kfree(spriv);
        }
 }