From 91754b1945e3f997525d3c709aa1ce5a2ddfadee Mon Sep 17 00:00:00 2001 From: cem Date: Sat, 20 Oct 2018 19:42:38 +0000 Subject: [PATCH] dev_refthread: Do not initialize *ref when reference was not acquired Like the companion API devvn_refthread, leave *ref uninitialized when a reference was not acquired. Initializing to 1 provides a vaguely correct-looking but bogus value for broken callers to (mistakenly) pass to dev_relthread() when refthread fails. Make it even more clear to consumers that dev_relthread is only valid when dev_refthread succeeds. Reviewed by: kib, markj Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D16885 --- sys/kern/kern_conf.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sys/kern/kern_conf.c b/sys/kern/kern_conf.c index 6a6a44aab425..5c2c485ae7a8 100644 --- a/sys/kern/kern_conf.c +++ b/sys/kern/kern_conf.c @@ -202,7 +202,8 @@ dev_refthread(struct cdev *dev, int *ref) csw = NULL; } dev_unlock(); - *ref = 1; + if (csw != NULL) + *ref = 1; return (csw); }