summaryrefslogtreecommitdiffstats
path: root/sys/dev/drm
diff options
context:
space:
mode:
authorhselasky <hselasky@FreeBSD.org>2012-08-15 16:19:39 +0000
committerhselasky <hselasky@FreeBSD.org>2012-08-15 16:19:39 +0000
commitcd2aff73464a800a4055a28629369fe7640150be (patch)
tree1000f4d07590bc41e68544d52176932383b84915 /sys/dev/drm
parentc92e1b68a6eaa87cbe2e4382cf95fd57d37583b7 (diff)
downloadFreeBSD-src-cd2aff73464a800a4055a28629369fe7640150be.zip
FreeBSD-src-cd2aff73464a800a4055a28629369fe7640150be.tar.gz
Streamline use of cdevpriv and correct some corner cases.
1) It is not useful to call "devfs_clear_cdevpriv()" from "d_close" callbacks, hence for example read, write, ioctl and so on might be sleeping at the time of "d_close" being called and then then freed private data can still be accessed. Examples: dtrace, linux_compat, ksyms (all fixed by this patch) 2) In sys/dev/drm* there are some cases in which memory will be freed twice, if open fails, first by code in the open routine, secondly by the cdevpriv destructor. Move registration of the cdevpriv to the end of the drm open routines. 3) devfs_clear_cdevpriv() is not called if the "d_open" callback registered cdevpriv data and the "d_open" callback function returned an error. Fix this. Discussed with: phk MFC after: 2 weeks
Diffstat (limited to 'sys/dev/drm')
-rw-r--r--sys/dev/drm/drm_fops.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/sys/dev/drm/drm_fops.c b/sys/dev/drm/drm_fops.c
index 3f743e0..814958e 100644
--- a/sys/dev/drm/drm_fops.c
+++ b/sys/dev/drm/drm_fops.c
@@ -57,12 +57,6 @@ int drm_open_helper(struct cdev *kdev, int flags, int fmt, DRM_STRUCTPROC *p,
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, int flags, int fmt, DRM_STRUCTPROC *p,
/* 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, int flags, int fmt, DRM_STRUCTPROC *p,
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);
}
OpenPOWER on IntegriCloud