From 81a83fa0ac51834161c07d1060db5f8c94a8ec60 Mon Sep 17 00:00:00 2001 From: anton Date: Tue, 28 Dec 2021 17:50:10 +0000 Subject: [PATCH] The initial kd_lookup() in kcovopen() is redundant as kcov is a cloning device. Turn it into an assertion instead to better state the expected semantics of D_CLONE. Prompted after a discussion with visa@ --- sys/dev/kcov.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/sys/dev/kcov.c b/sys/dev/kcov.c index 0a130fd0c25..5db7e764786 100644 --- a/sys/dev/kcov.c +++ b/sys/dev/kcov.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kcov.c,v 1.42 2021/12/27 15:38:25 anton Exp $ */ +/* $OpenBSD: kcov.c,v 1.43 2021/12/28 17:50:10 anton Exp $ */ /* * Copyright (c) 2018 Anton Lindqvist @@ -53,7 +53,7 @@ struct kcov_dev { int kd_state; /* [M] */ int kd_mode; /* [M] */ - int kd_unit; /* [I] device minor */ + int kd_unit; /* [I] D_CLONE unique device minor */ int kd_intr; /* [M] currently used in interrupt */ uintptr_t *kd_buf; /* [a] traced coverage */ size_t kd_nmemb; /* [I] */ @@ -290,21 +290,13 @@ kcovopen(dev_t dev, int flag, int mode, struct proc *p) { struct kcov_dev *kd; - mtx_enter(&kcov_mtx); - - if (kd_lookup(minor(dev)) != NULL) { - mtx_leave(&kcov_mtx); - return (EBUSY); - } - - if (kcov_cold) - kcov_cold = 0; - - mtx_leave(&kcov_mtx); kd = malloc(sizeof(*kd), M_SUBPROC, M_WAITOK | M_ZERO); kd->kd_unit = minor(dev); mtx_enter(&kcov_mtx); + KASSERT(kd_lookup(kd->kd_unit) == NULL); TAILQ_INSERT_TAIL(&kd_list, kd, kd_entry); + if (kcov_cold) + kcov_cold = 0; mtx_leave(&kcov_mtx); return (0); } -- 2.20.1