From owner-svn-src-all@freebsd.org Wed Apr 5 12:48:25 2017 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A6ED2D2E4C4; Wed, 5 Apr 2017 12:48:25 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 81A9D647; Wed, 5 Apr 2017 12:48:25 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v35CmOTk061289; Wed, 5 Apr 2017 12:48:24 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v35CmOYj061288; Wed, 5 Apr 2017 12:48:24 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201704051248.v35CmOYj061288@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Wed, 5 Apr 2017 12:48:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r316522 - head/sys/compat/linuxkpi/common/src X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 05 Apr 2017 12:48:25 -0000 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 #include #include +#include #include @@ -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);