From 4f113b3dee5c1a8edd85e9aa69588a48840bc812 Mon Sep 17 00:00:00 2001 From: Jianglei Nie Date: Mon, 11 Jul 2022 09:19:22 +0800 Subject: [PATCH] bhnd: fix potential resource leak in bhnd_pmu_core_attach() bhnd_pmu_core_attach() allocates resource with bhnd_alloc_resource_any() and bhnd_alloc_pmu(). When some error occurs in this funciton, some relevant resource is not released, which will lead to a resource leak. We should release the relevant relevant with bhnd_release_resource() and bhnd_release_pmu() on the error path to avoid the resource leak. Signed-off-by: Jianglei Nie --- sys/dev/bhnd/cores/pmu/bhnd_pmu_core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sys/dev/bhnd/cores/pmu/bhnd_pmu_core.c b/sys/dev/bhnd/cores/pmu/bhnd_pmu_core.c index f196aded6c90..43b09166ed07 100644 --- a/sys/dev/bhnd/cores/pmu/bhnd_pmu_core.c +++ b/sys/dev/bhnd/cores/pmu/bhnd_pmu_core.c @@ -100,13 +100,14 @@ bhnd_pmu_core_attach(device_t dev) if ((error = bhnd_alloc_pmu(dev))) { device_printf(sc->dev, "failed to allocate PMU state: %d\n", error); - + bhnd_release_resource(dev, SYS_RES_MEMORY, rid, res); return (error); } /* Delegate to common driver implementation */ if ((error = bhnd_pmu_attach(dev, res))) { bhnd_release_resource(dev, SYS_RES_MEMORY, rid, res); + bhnd_release_pmu(dev); return (error); } -- 2.25.1