media: dvb_frontend: better document the -EPERM condition
authorMauro Carvalho Chehab <mchehab@s-opensource.com>
Fri, 5 Jun 2020 16:25:10 +0000 (09:25 -0700)
committerSasha Levin <sashal@kernel.org>
Tue, 30 Jun 2020 19:38:34 +0000 (15:38 -0400)
commit da5516b5e81d45a96291823620f6c820178dc055 upstream

Two readonly ioctls can't be allowed if the frontend device
is opened in read only mode. Explain why.

Reviewed by: Shuah Khan <shuahkh@osg.samsung.com>

Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/media/dvb-core/dvb_frontend.c

index a7ba8e200b677be01104e380c6f0d1aa0922a4d3..673cefb7230cb3d186462e15b167bafa953537fe 100644 (file)
@@ -1925,9 +1925,23 @@ static int dvb_frontend_ioctl(struct file *file, unsigned int cmd, void *parg)
                return -ENODEV;
        }
 
-       if ((file->f_flags & O_ACCMODE) == O_RDONLY &&
-           (_IOC_DIR(cmd) != _IOC_READ || cmd == FE_GET_EVENT ||
-            cmd == FE_DISEQC_RECV_SLAVE_REPLY)) {
+       /*
+        * If the frontend is opened in read-only mode, only the ioctls
+        * that don't interfere with the tune logic should be accepted.
+        * That allows an external application to monitor the DVB QoS and
+        * statistics parameters.
+        *
+        * That matches all _IOR() ioctls, except for two special cases:
+        *   - FE_GET_EVENT is part of the tuning logic on a DVB application;
+        *   - FE_DISEQC_RECV_SLAVE_REPLY is part of DiSEqC 2.0
+        *     setup
+        * So, those two ioctls should also return -EPERM, as otherwise
+        * reading from them would interfere with a DVB tune application
+        */
+       if ((file->f_flags & O_ACCMODE) == O_RDONLY
+           && (_IOC_DIR(cmd) != _IOC_READ
+               || cmd == FE_GET_EVENT
+               || cmd == FE_DISEQC_RECV_SLAVE_REPLY)) {
                up(&fepriv->sem);
                return -EPERM;
        }