From dff81756cf86cb974134e82f713d2fbd609f050b Mon Sep 17 00:00:00 2001 From: chao an Date: Sun, 20 Nov 2022 22:28:39 +0800 Subject: [PATCH] drivers/regulator_rpmsg: destroy nxsem properly Signed-off-by: chao an --- drivers/power/supply/regulator_rpmsg.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/drivers/power/supply/regulator_rpmsg.c b/drivers/power/supply/regulator_rpmsg.c index 03c2785bd8..ccd4edb0f7 100644 --- a/drivers/power/supply/regulator_rpmsg.c +++ b/drivers/power/supply/regulator_rpmsg.c @@ -495,18 +495,17 @@ static int regulator_rpmsg_sendrecv(FAR struct rpmsg_endpoint *ept, msg->cookie = (uintptr_t)&cookie; ret = rpmsg_send_nocopy(ept, msg, len); - if (ret < 0) + if (ret >= 0) { - return ret; + ret = nxsem_wait_uninterruptible(&cookie.sem); + if (ret >= 0) + { + ret = cookie.result; + } } - ret = nxsem_wait_uninterruptible(&cookie.sem); - if (ret < 0) - { - return ret; - } - - return cookie.result; + nxsem_destroy(&cookie.sem); + return ret; } static int regulator_rpmsg_enable(FAR struct regulator_dev_s *rdev)