git: ebecf6848945 - stable/15 - hwpmc: release a PMC whose ID could not be copied out

From: Mitchell Horne <mhorne_at_FreeBSD.org>
Date: Mon, 09 Nov 2026 16:07:06 UTC
The branch stable/15 has been updated by mhorne:

URL: https://cgit.FreeBSD.org/src/commit/?id=ebecf68489454f475fb30680bc9d179f1c614e7f

commit ebecf68489454f475fb30680bc9d179f1c614e7f
Author:     Andre Silva <andasilv@amd.com>
AuthorDate: 2026-11-06 15:20:08 +0000
Commit:     Mitchell Horne <mhorne@FreeBSD.org>
CommitDate: 2026-11-09 16:06:46 +0000

    hwpmc: release a PMC whose ID could not be copied out
    
    If copyout of the newly allocated PMC ID fails, the caller cannot use or
    release the PMC. Release it in the kernel.
    
    Reviewed by:    mhorne
    MFC after:      3 days
    Sponsored by:   Advanced Micro Devices, Inc.
    Differential Revision:  https://reviews.freebsd.org/D60562
    
    (cherry picked from commit e5a48c8e0dd026ba953cf401c4dec02f76078aa2)
---
 sys/dev/hwpmc/hwpmc_mod.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/sys/dev/hwpmc/hwpmc_mod.c b/sys/dev/hwpmc/hwpmc_mod.c
index c5771f8a0fe7..7ce83ad85bed 100644
--- a/sys/dev/hwpmc/hwpmc_mod.c
+++ b/sys/dev/hwpmc/hwpmc_mod.c
@@ -4277,6 +4277,12 @@ pmc_syscall_handler(struct thread *td, void *syscall_args)
 			break;
 
 		error = copyout(&pa, arg, sizeof(pa));
+		/*
+		 * The caller never learns the ID of an unpublished PMC; do
+		 * not leave it (and the row it holds) behind.
+		 */
+		if (error != 0)
+			(void)pmc_do_op_pmcrelease(pa.pm_pmcid);
 	}
 	break;