Author: hselasky
Date: Wed Apr  5 12:48:24 2017
New Revision: 316522
URL: https://svnweb.freebsd.org/changeset/base/316522

Log:
  Unify error handling when si_drv1 is NULL in the LinuxKPI.
  
  Make sure the character device poll callback function does not return
  an error code, but a POLLXXX value, in case of failure.
  
  MFC after:            1 week
  Sponsored by:         Mellanox Technologies

Modified:
  head/sys/compat/linuxkpi/common/src/linux_compat.c

Modified: head/sys/compat/linuxkpi/common/src/linux_compat.c
==============================================================================
--- head/sys/compat/linuxkpi/common/src/linux_compat.c  Wed Apr  5 12:10:02 
2017        (r316521)
+++ head/sys/compat/linuxkpi/common/src/linux_compat.c  Wed Apr  5 12:48:24 
2017        (r316522)
@@ -73,6 +73,7 @@ __FBSDID("$FreeBSD$");
 #include <linux/kernel.h>
 #include <linux/list.h>
 #include <linux/compat.h>
+#include <linux/poll.h>
 
 #include <vm/vm_pager.h>
 
@@ -430,14 +431,12 @@ done:
 static int
 linux_dev_close(struct cdev *dev, int fflag, int devtype, struct thread *td)
 {
-       struct linux_cdev *ldev;
        struct linux_file *filp;
        struct file *file;
        int error;
 
        file = td->td_fpop;
-       ldev = dev->si_drv1;
-       if (ldev == NULL)
+       if (dev->si_drv1 == NULL)
                return (0);
        if ((error = devfs_get_cdevpriv((void **)&filp)) != 0)
                return (error);
@@ -566,16 +565,14 @@ static int
 linux_dev_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag,
     struct thread *td)
 {
-       struct linux_cdev *ldev;
        struct linux_file *filp;
        struct file *file;
        unsigned size;
        int error;
 
        file = td->td_fpop;
-       ldev = dev->si_drv1;
-       if (ldev == NULL)
-               return (0);
+       if (dev->si_drv1 == NULL)
+               return (ENXIO);
        if ((error = devfs_get_cdevpriv((void **)&filp)) != 0)
                return (error);
        filp->f_flags = file->f_flag;
@@ -612,7 +609,6 @@ linux_dev_ioctl(struct cdev *dev, u_long
 static int
 linux_dev_read(struct cdev *dev, struct uio *uio, int ioflag)
 {
-       struct linux_cdev *ldev;
        struct linux_file *filp;
        struct thread *td;
        struct file *file;
@@ -621,9 +617,8 @@ linux_dev_read(struct cdev *dev, struct 
 
        td = curthread;
        file = td->td_fpop;
-       ldev = dev->si_drv1;
-       if (ldev == NULL)
-               return (0);
+       if (dev->si_drv1 == NULL)
+               return (ENXIO);
        if ((error = devfs_get_cdevpriv((void **)&filp)) != 0)
                return (error);
        filp->f_flags = file->f_flag;
@@ -650,7 +645,6 @@ linux_dev_read(struct cdev *dev, struct 
 static int
 linux_dev_write(struct cdev *dev, struct uio *uio, int ioflag)
 {
-       struct linux_cdev *ldev;
        struct linux_file *filp;
        struct thread *td;
        struct file *file;
@@ -659,9 +653,8 @@ linux_dev_write(struct cdev *dev, struct
 
        td = curthread;
        file = td->td_fpop;
-       ldev = dev->si_drv1;
-       if (ldev == NULL)
-               return (0);
+       if (dev->si_drv1 == NULL)
+               return (ENXIO);
        if ((error = devfs_get_cdevpriv((void **)&filp)) != 0)
                return (error);
        filp->f_flags = file->f_flag;
@@ -688,18 +681,16 @@ linux_dev_write(struct cdev *dev, struct
 static int
 linux_dev_poll(struct cdev *dev, int events, struct thread *td)
 {
-       struct linux_cdev *ldev;
        struct linux_file *filp;
        struct file *file;
        int revents;
-       int error;
+
+       if (dev->si_drv1 == NULL)
+               goto error;
+       if (devfs_get_cdevpriv((void **)&filp) != 0)
+               goto error;
 
        file = td->td_fpop;
-       ldev = dev->si_drv1;
-       if (ldev == NULL)
-               return (0);
-       if ((error = devfs_get_cdevpriv((void **)&filp)) != 0)
-               return (error);
        filp->f_flags = file->f_flag;
        linux_set_current(td);
        if (filp->f_op->poll)
@@ -708,13 +699,14 @@ linux_dev_poll(struct cdev *dev, int eve
                revents = 0;
 
        return (revents);
+error:
+       return (events & (POLLHUP|POLLIN|POLLRDNORM|POLLOUT|POLLWRNORM));
 }
 
 static int
 linux_dev_mmap_single(struct cdev *dev, vm_ooffset_t *offset,
     vm_size_t size, struct vm_object **object, int nprot)
 {
-       struct linux_cdev *ldev;
        struct linux_file *filp;
        struct thread *td;
        struct file *file;
@@ -723,8 +715,7 @@ linux_dev_mmap_single(struct cdev *dev, 
 
        td = curthread;
        file = td->td_fpop;
-       ldev = dev->si_drv1;
-       if (ldev == NULL)
+       if (dev->si_drv1 == NULL)
                return (ENODEV);
        if ((error = devfs_get_cdevpriv((void **)&filp)) != 0)
                return (error);
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to