* FESTATE_LOSTLOCK. When the lock has been lost, and we're searching it again.
  */
 
+#define DVB_FE_NO_EXIT 0
+#define DVB_FE_NORMAL_EXIT     1
+#define DVB_FE_DEVICE_REMOVED  2
+
 static DEFINE_MUTEX(frontend_mutex);
 
 struct dvb_frontend_private {
 {
        struct dvb_frontend_private *fepriv = fe->frontend_priv;
 
-       if (fepriv->exit)
+       if (fepriv->exit != DVB_FE_NO_EXIT)
                return 1;
 
        if (fepriv->dvbdev->writers == 1)
 
                if (kthread_should_stop() || dvb_frontend_is_exiting(fe)) {
                        /* got signal or quitting */
-                       fepriv->exit = 1;
+                       fepriv->exit = DVB_FE_NORMAL_EXIT;
                        break;
                }
 
        }
 
        fepriv->thread = NULL;
-       fepriv->exit = 0;
+       if (kthread_should_stop())
+               fepriv->exit = DVB_FE_DEVICE_REMOVED;
+       else
+               fepriv->exit = DVB_FE_NO_EXIT;
        mb();
 
        dvb_frontend_wakeup(fe);
 
        dprintk ("%s\n", __func__);
 
-       fepriv->exit = 1;
+       fepriv->exit = DVB_FE_NORMAL_EXIT;
        mb();
 
        if (!fepriv->thread)
        dprintk ("%s\n", __func__);
 
        if (fepriv->thread) {
-               if (!fepriv->exit)
+               if (fepriv->exit == DVB_FE_NO_EXIT)
                        return 0;
                else
                        dvb_frontend_stop (fe);
                return -EINTR;
 
        fepriv->state = FESTATE_IDLE;
-       fepriv->exit = 0;
+       fepriv->exit = DVB_FE_NO_EXIT;
        fepriv->thread = NULL;
        mb();
 
 
        dprintk("%s (%d)\n", __func__, _IOC_NR(cmd));
 
-       if (fepriv->exit)
+       if (fepriv->exit != DVB_FE_NO_EXIT)
                return -ENODEV;
 
        if ((file->f_flags & O_ACCMODE) == O_RDONLY &&
        int ret;
 
        dprintk ("%s\n", __func__);
+       if (fepriv->exit == DVB_FE_DEVICE_REMOVED)
+               return -ENODEV;
 
        if (adapter->mfe_shared) {
                mutex_lock (&adapter->mfe_lock);
        ret = dvb_generic_release (inode, file);
 
        if (dvbdev->users == -1) {
-               if (fepriv->exit == 1) {
+               if (fepriv->exit != DVB_FE_NO_EXIT) {
                        fops_put(file->f_op);
                        file->f_op = NULL;
                        wake_up(&dvbdev->wait_queue);