diff --git a/drivers/clk/clk_rpmsg.c b/drivers/clk/clk_rpmsg.c index 2918b73399..e0bbc50f35 100644 --- a/drivers/clk/clk_rpmsg.c +++ b/drivers/clk/clk_rpmsg.c @@ -485,18 +485,17 @@ static int64_t clk_rpmsg_sendrecv(FAR struct rpmsg_endpoint *ept, cookie.result = -EIO; 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 bool clk_rpmsg_server_match(FAR struct rpmsg_device *rdev, diff --git a/drivers/ioexpander/ioe_rpmsg.c b/drivers/ioexpander/ioe_rpmsg.c index 8e26fa3060..7507ce6adb 100644 --- a/drivers/ioexpander/ioe_rpmsg.c +++ b/drivers/ioexpander/ioe_rpmsg.c @@ -275,18 +275,17 @@ static int ioe_rpmsg_sendrecv(FAR struct rpmsg_endpoint *ept, msg->cookie = (uintptr_t)&cookie; ret = rpmsg_send(ept, msg, len); - if (ret < 0) + if (ret >= 0) { - return ret; + ret = rpmsg_wait(ept, &cookie.sem); + if (ret >= 0) + { + ret = cookie.result; + } } - ret = rpmsg_wait(ept, &cookie.sem); - if (ret < 0) - { - return ret; - } - - return cookie.result; + nxsem_destroy(&cookie.sem); + return ret; } static int ioe_rpmsg_direction(FAR struct ioexpander_dev_s *dev, uint8_t pin,