From 07604b3220c54e10841b1004b6992600d3b684bf Mon Sep 17 00:00:00 2001 From: chao an Date: Sun, 20 Nov 2022 22:07:15 +0800 Subject: [PATCH] drivers/rpmsg/clk/ioe: destroy nxsem properly Signed-off-by: chao an --- drivers/clk/clk_rpmsg.c | 17 ++++++++--------- drivers/ioexpander/ioe_rpmsg.c | 17 ++++++++--------- 2 files changed, 16 insertions(+), 18 deletions(-) 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,