Author: hselasky
Date: Mon Oct  1 06:42:07 2012
New Revision: 241088
URL: http://svn.freebsd.org/changeset/base/241088

Log:
  MFC r239303:
  Streamline use of cdevpriv and correct some corner cases.

Modified:
  stable/9/sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c
  stable/9/sys/dev/drm/drm_fops.c
  stable/9/sys/dev/drm2/drm_fops.c
  stable/9/sys/dev/ksyms/ksyms.c
  stable/9/sys/fs/devfs/devfs_vnops.c
  stable/9/sys/ofed/include/linux/linux_compat.c
Directory Properties:
  stable/9/sys/   (props changed)
  stable/9/sys/cddl/contrib/opensolaris/   (props changed)
  stable/9/sys/dev/   (props changed)
  stable/9/sys/fs/   (props changed)

Modified: stable/9/sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c
==============================================================================
--- stable/9/sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c    Mon Oct 
 1 06:01:20 2012        (r241087)
+++ stable/9/sys/cddl/contrib/opensolaris/uts/common/dtrace/dtrace.c    Mon Oct 
 1 06:42:07 2012        (r241088)
@@ -15517,8 +15517,6 @@ dtrace_close(struct cdev *dev, int flags
                kmem_free(state, 0);
 #if __FreeBSD_version < 800039
                dev->si_drv1 = NULL;
-#else
-               devfs_clear_cdevpriv();
 #endif
 #endif
        }

Modified: stable/9/sys/dev/drm/drm_fops.c
==============================================================================
--- stable/9/sys/dev/drm/drm_fops.c     Mon Oct  1 06:01:20 2012        
(r241087)
+++ stable/9/sys/dev/drm/drm_fops.c     Mon Oct  1 06:42:07 2012        
(r241088)
@@ -57,12 +57,6 @@ int drm_open_helper(struct cdev *kdev, i
                return ENOMEM;
        }
 
-       retcode = devfs_set_cdevpriv(priv, drm_close);
-       if (retcode != 0) {
-               free(priv, DRM_MEM_FILES);
-               return retcode;
-       }
-
        DRM_LOCK();
        priv->dev               = dev;
        priv->uid               = p->td_ucred->cr_svuid;
@@ -76,7 +70,6 @@ int drm_open_helper(struct cdev *kdev, i
                /* shared code returns -errno */
                retcode = -dev->driver->open(dev, priv);
                if (retcode != 0) {
-                       devfs_clear_cdevpriv();
                        free(priv, DRM_MEM_FILES);
                        DRM_UNLOCK();
                        return retcode;
@@ -89,7 +82,12 @@ int drm_open_helper(struct cdev *kdev, i
        TAILQ_INSERT_TAIL(&dev->files, priv, link);
        DRM_UNLOCK();
        kdev->si_drv1 = dev;
-       return 0;
+
+       retcode = devfs_set_cdevpriv(priv, drm_close);
+       if (retcode != 0)
+               drm_close(priv);
+
+       return (retcode);
 }
 
 

Modified: stable/9/sys/dev/drm2/drm_fops.c
==============================================================================
--- stable/9/sys/dev/drm2/drm_fops.c    Mon Oct  1 06:01:20 2012        
(r241087)
+++ stable/9/sys/dev/drm2/drm_fops.c    Mon Oct  1 06:42:07 2012        
(r241088)
@@ -57,12 +57,6 @@ int drm_open_helper(struct cdev *kdev, i
                return ENOMEM;
        }
 
-       retcode = devfs_set_cdevpriv(priv, drm_close);
-       if (retcode != 0) {
-               free(priv, DRM_MEM_FILES);
-               return retcode;
-       }
-
        DRM_LOCK(dev);
        priv->dev               = dev;
        priv->uid               = p->td_ucred->cr_svuid;
@@ -83,7 +77,6 @@ int drm_open_helper(struct cdev *kdev, i
                /* shared code returns -errno */
                retcode = -dev->driver->open(dev, priv);
                if (retcode != 0) {
-                       devfs_clear_cdevpriv();
                        free(priv, DRM_MEM_FILES);
                        DRM_UNLOCK(dev);
                        return retcode;
@@ -96,7 +89,12 @@ int drm_open_helper(struct cdev *kdev, i
        TAILQ_INSERT_TAIL(&dev->files, priv, link);
        DRM_UNLOCK(dev);
        kdev->si_drv1 = dev;
-       return 0;
+
+       retcode = devfs_set_cdevpriv(priv, drm_close);
+       if (retcode != 0)
+               drm_close(priv);
+
+       return (retcode);
 }
 
 static bool

Modified: stable/9/sys/dev/ksyms/ksyms.c
==============================================================================
--- stable/9/sys/dev/ksyms/ksyms.c      Mon Oct  1 06:01:20 2012        
(r241087)
+++ stable/9/sys/dev/ksyms/ksyms.c      Mon Oct  1 06:42:07 2012        
(r241088)
@@ -579,8 +579,6 @@ ksyms_close(struct cdev *dev, int flags 
        /* Unmap the buffer from the process address space. */
        error = copyout_unmap(td, sc->sc_uaddr, sc->sc_usize);
 
-       devfs_clear_cdevpriv();
-
        return (error);
 }
 

Modified: stable/9/sys/fs/devfs/devfs_vnops.c
==============================================================================
--- stable/9/sys/fs/devfs/devfs_vnops.c Mon Oct  1 06:01:20 2012        
(r241087)
+++ stable/9/sys/fs/devfs/devfs_vnops.c Mon Oct  1 06:42:07 2012        
(r241088)
@@ -1081,6 +1081,9 @@ devfs_open(struct vop_open_args *ap)
                error = dsw->d_fdopen(dev, ap->a_mode, td, fp);
        else
                error = dsw->d_open(dev, ap->a_mode, S_IFCHR, td);
+       /* cleanup any cdevpriv upon error */
+       if (error != 0)
+               devfs_clear_cdevpriv();
        td->td_fpop = fpop;
 
        vn_lock(vp, vlocked | LK_RETRY);

Modified: stable/9/sys/ofed/include/linux/linux_compat.c
==============================================================================
--- stable/9/sys/ofed/include/linux/linux_compat.c      Mon Oct  1 06:01:20 
2012        (r241087)
+++ stable/9/sys/ofed/include/linux/linux_compat.c      Mon Oct  1 06:42:07 
2012        (r241088)
@@ -263,7 +263,6 @@ linux_dev_close(struct cdev *dev, int ff
        if ((error = devfs_get_cdevpriv((void **)&filp)) != 0)
                return (error);
        filp->f_flags = file->f_flag;
-       devfs_clear_cdevpriv();
 
        return (0);
 }
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to