From 72b66398fa7114124f4fecbaa5e04e6c205b2434 Mon Sep 17 00:00:00 2001 From: Andrew Turner Date: Tue, 19 Feb 2019 17:03:34 +0000 Subject: Create a common function to handle freeing the kcov info struct. Both places that may free the kcov info struct are identical. Create a new common function to hold the code. Sponsored by: DARPA, AFRL --- sys/kern/kern_kcov.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'sys/kern/kern_kcov.c') diff --git a/sys/kern/kern_kcov.c b/sys/kern/kern_kcov.c index 84949a7296bd..121b1736ed2b 100644 --- a/sys/kern/kern_kcov.c +++ b/sys/kern/kern_kcov.c @@ -136,6 +136,7 @@ static d_mmap_single_t kcov_mmap_single; static d_ioctl_t kcov_ioctl; static int kcov_alloc(struct kcov_info *info, size_t entries); +static void kcov_free(struct kcov_info *info); static void kcov_init(const void *unused); static struct cdevsw kcov_cdevsw = { @@ -288,14 +289,7 @@ kcov_mmap_cleanup(void *arg) * The KCOV_STATE_DYING stops new threads from using it. * The lack of a thread means nothing is currently using the buffers. */ - - if (info->kvaddr != 0) { - pmap_qremove(info->kvaddr, info->bufsize / PAGE_SIZE); - kva_free(info->kvaddr, info->bufsize); - } - if (info->bufobj != NULL && !info->mmap) - vm_object_deallocate(info->bufobj); - free(info, M_KCOV_INFO); + kcov_free(info); } static int @@ -398,6 +392,19 @@ kcov_alloc(struct kcov_info *info, size_t entries) return (0); } +static void +kcov_free(struct kcov_info *info) +{ + + if (info->kvaddr != 0) { + pmap_qremove(info->kvaddr, info->bufsize / PAGE_SIZE); + kva_free(info->kvaddr, info->bufsize); + } + if (info->bufobj != NULL && !info->mmap) + vm_object_deallocate(info->bufobj); + free(info, M_KCOV_INFO); +} + static int kcov_ioctl(struct cdev *dev, u_long cmd, caddr_t data, int fflag __unused, struct thread *td) @@ -531,14 +538,7 @@ kcov_thread_dtor(void *arg __unused, struct thread *td) * The KCOV_STATE_DYING stops new threads from using it. * It also stops the current thread from trying to use the info struct. */ - - if (info->kvaddr != 0) { - pmap_qremove(info->kvaddr, info->bufsize / PAGE_SIZE); - kva_free(info->kvaddr, info->bufsize); - } - if (info->bufobj != NULL && !info->mmap) - vm_object_deallocate(info->bufobj); - free(info, M_KCOV_INFO); + kcov_free(info); } static void -- cgit v1.2.3