summaryrefslogtreecommitdiffstats
path: root/sys/fs/devfs
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/fs/devfs
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/fs/devfs')
-rw-r--r--sys/fs/devfs/devfs_vnops.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/sys/fs/devfs/devfs_vnops.c b/sys/fs/devfs/devfs_vnops.c
index d3e6cf5..97a1bcf 100644
--- a/sys/fs/devfs/devfs_vnops.c
+++ b/sys/fs/devfs/devfs_vnops.c
@@ -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);
OpenPOWER on IntegriCloud