diff options
author | Hans Petter Selasky <hselasky@FreeBSD.org> | 2017-04-05 12:48:24 +0000 |
---|---|---|
committer | Hans Petter Selasky <hselasky@FreeBSD.org> | 2017-04-05 12:48:24 +0000 |
commit | 6e3e654490c36939c6fbcebfa2c8512fe8120d5f (patch) | |
tree | 64e9415f331ab7b4d36068edf7bc5823a586933b | |
parent | 0bd68b774d1d1b642780878a0e73ea4b1c13d02a (diff) | |
download | src-6e3e654490c36939c6fbcebfa2c8512fe8120d5f.tar.gz src-6e3e654490c36939c6fbcebfa2c8512fe8120d5f.zip |
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
Notes
Notes:
svn path=/head/; revision=316522
-rw-r--r-- | sys/compat/linuxkpi/common/src/linux_compat.c | 41 |
1 files changed, 16 insertions, 25 deletions
diff --git a/sys/compat/linuxkpi/common/src/linux_compat.c b/sys/compat/linuxkpi/common/src/linux_compat.c index 37f607cf8861..5f81330373a2 100644 --- a/sys/compat/linuxkpi/common/src/linux_compat.c +++ b/sys/compat/linuxkpi/common/src/linux_compat.c @@ -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 cmd, caddr_t data, int fflag, 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 uio *uio, int ioflag) 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 uio *uio, int ioflag) 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 uio *uio, int ioflag) 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 uio *uio, int ioflag) 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 events, struct thread *td) 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, vm_ooffset_t *offset, 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); |