diff --git a/drivers/power/supply/regulator_rpmsg.c b/drivers/power/supply/regulator_rpmsg.c index 03c2785bd8e..ccd4edb0f76 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)