]> rtime.felk.cvut.cz Git - linux-imx.git/blobdiff - drivers/media/dvb/dvb-core/dvb_frontend.c
Merge branch 'bkl/ioctl' of git://git.kernel.org/pub/scm/linux/kernel/git/frederic...
[linux-imx.git] / drivers / media / dvb / dvb-core / dvb_frontend.c
index 5450d1f7a53841b0d04fd1f14595e8803683cd5d..44ae89ecef94ba4701ad2cb600e42c3d7e5e7692 100644 (file)
@@ -96,6 +96,10 @@ MODULE_PARM_DESC(dvb_mfe_wait_time, "Wait up to <mfe_wait_time> seconds on open(
  * 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 {
@@ -498,7 +502,7 @@ static int dvb_frontend_is_exiting(struct dvb_frontend *fe)
 {
        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)
@@ -560,7 +564,7 @@ restart:
 
                if (kthread_should_stop() || dvb_frontend_is_exiting(fe)) {
                        /* got signal or quitting */
-                       fepriv->exit = 1;
+                       fepriv->exit = DVB_FE_NORMAL_EXIT;
                        break;
                }
 
@@ -674,7 +678,10 @@ restart:
        }
 
        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);
@@ -687,7 +694,7 @@ static void dvb_frontend_stop(struct dvb_frontend *fe)
 
        dprintk ("%s\n", __func__);
 
-       fepriv->exit = 1;
+       fepriv->exit = DVB_FE_NORMAL_EXIT;
        mb();
 
        if (!fepriv->thread)
@@ -756,7 +763,7 @@ static int dvb_frontend_start(struct dvb_frontend *fe)
        dprintk ("%s\n", __func__);
 
        if (fepriv->thread) {
-               if (!fepriv->exit)
+               if (fepriv->exit == DVB_FE_NO_EXIT)
                        return 0;
                else
                        dvb_frontend_stop (fe);
@@ -768,7 +775,7 @@ static int dvb_frontend_start(struct dvb_frontend *fe)
                return -EINTR;
 
        fepriv->state = FESTATE_IDLE;
-       fepriv->exit = 0;
+       fepriv->exit = DVB_FE_NO_EXIT;
        fepriv->thread = NULL;
        mb();
 
@@ -1490,7 +1497,7 @@ static int dvb_frontend_ioctl(struct file *file,
 
        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 &&
@@ -1916,6 +1923,8 @@ static int dvb_frontend_open(struct inode *inode, struct file *file)
        int ret;
 
        dprintk ("%s\n", __func__);
+       if (fepriv->exit == DVB_FE_DEVICE_REMOVED)
+               return -ENODEV;
 
        if (adapter->mfe_shared) {
                mutex_lock (&adapter->mfe_lock);
@@ -2008,7 +2017,7 @@ static int dvb_frontend_release(struct inode *inode, struct file *file)
        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);