* [PATCH] firmware: turris-mox-rwtm: Fix return value check of wait_for_completion_timeout
@ 2022-04-12 3:12 Miaoqian Lin
0 siblings, 0 replies; 3+ messages in thread
From: Miaoqian Lin @ 2022-04-12 3:12 UTC (permalink / raw)
To: Marek Behún, Arnd Bergmann, linux-kernel; +Cc: linmq006
wait_for_completion_timeout() returns unsigned long not int.
It returns 0 if timed out, and positive if completed.
The check for < 0 is ambiguous and should be == 0 here
indicating timeout which is the only error case.
Fixes: 389711b37493 ("firmware: Add Turris Mox rWTM firmware driver")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
drivers/firmware/turris-mox-rwtm.c | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/drivers/firmware/turris-mox-rwtm.c b/drivers/firmware/turris-mox-rwtm.c
index c2d34dc8ba46..2090afe00b7f 100644
--- a/drivers/firmware/turris-mox-rwtm.c
+++ b/drivers/firmware/turris-mox-rwtm.c
@@ -193,15 +193,16 @@ static int mox_get_board_info(struct mox_rwtm *rwtm)
struct armada_37xx_rwtm_tx_msg msg;
struct armada_37xx_rwtm_rx_msg *reply = &rwtm->reply;
int ret;
+ unsigned long time_left;
msg.command = MBOX_CMD_BOARD_INFO;
ret = mbox_send_message(rwtm->mbox, &msg);
if (ret < 0)
return ret;
- ret = wait_for_completion_timeout(&rwtm->cmd_done, HZ / 2);
- if (ret < 0)
- return ret;
+ time_left = wait_for_completion_timeout(&rwtm->cmd_done, HZ / 2);
+ if (time_left == 0)
+ return -ETIMEDOUT;
ret = mox_get_status(MBOX_CMD_BOARD_INFO, reply->retval);
if (ret == -ENODATA) {
@@ -235,9 +236,9 @@ static int mox_get_board_info(struct mox_rwtm *rwtm)
if (ret < 0)
return ret;
- ret = wait_for_completion_timeout(&rwtm->cmd_done, HZ / 2);
- if (ret < 0)
- return ret;
+ time_left = wait_for_completion_timeout(&rwtm->cmd_done, HZ / 2);
+ if (time_left == 0)
+ return -ETIMEDOUT;
ret = mox_get_status(MBOX_CMD_ECDSA_PUB_KEY, reply->retval);
if (ret == -ENODATA) {
@@ -264,6 +265,7 @@ static int check_get_random_support(struct mox_rwtm *rwtm)
{
struct armada_37xx_rwtm_tx_msg msg;
int ret;
+ unsigned long time_left;
msg.command = MBOX_CMD_GET_RANDOM;
msg.args[0] = 1;
@@ -274,9 +276,9 @@ static int check_get_random_support(struct mox_rwtm *rwtm)
if (ret < 0)
return ret;
- ret = wait_for_completion_timeout(&rwtm->cmd_done, HZ / 2);
- if (ret < 0)
- return ret;
+ time_left = wait_for_completion_timeout(&rwtm->cmd_done, HZ / 2);
+ if (time_left == 0)
+ return -ETIMEDOUT;
return mox_get_status(MBOX_CMD_GET_RANDOM, rwtm->reply.retval);
}
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] firmware: turris-mox-rwtm: Fix return value check of wait_for_completion_timeout
2022-04-11 10:45 Miaoqian Lin
@ 2022-04-11 16:07 ` Marek Behún
0 siblings, 0 replies; 3+ messages in thread
From: Marek Behún @ 2022-04-11 16:07 UTC (permalink / raw)
To: Miaoqian Lin; +Cc: Arnd Bergmann, linux-kernel
On Mon, 11 Apr 2022 10:45:38 +0000
Miaoqian Lin <linmq006@gmail.com> wrote:
> wait_for_completion_timeout() returns unsigned long not int.
> It returns 0 if timed out, and positive if completed.
> The check for <= 0 is ambiguous and should be == 0 here
> indicating timeout which is the only error case
>
> Fixes: 389711b37493 ("firmware: Add Turris Mox rWTM firmware driver")
> Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
Reviewed-by: Marek Behún <kabel@kernel.org>
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH] firmware: turris-mox-rwtm: Fix return value check of wait_for_completion_timeout
@ 2022-04-11 10:45 Miaoqian Lin
2022-04-11 16:07 ` Marek Behún
0 siblings, 1 reply; 3+ messages in thread
From: Miaoqian Lin @ 2022-04-11 10:45 UTC (permalink / raw)
To: Marek Behún, Arnd Bergmann, linux-kernel; +Cc: linmq006
wait_for_completion_timeout() returns unsigned long not int.
It returns 0 if timed out, and positive if completed.
The check for <= 0 is ambiguous and should be == 0 here
indicating timeout which is the only error case
Fixes: 389711b37493 ("firmware: Add Turris Mox rWTM firmware driver")
Signed-off-by: Miaoqian Lin <linmq006@gmail.com>
---
drivers/firmware/turris-mox-rwtm.c | 20 +++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/drivers/firmware/turris-mox-rwtm.c b/drivers/firmware/turris-mox-rwtm.c
index c2d34dc8ba46..5040b81d7849 100644
--- a/drivers/firmware/turris-mox-rwtm.c
+++ b/drivers/firmware/turris-mox-rwtm.c
@@ -193,15 +193,16 @@ static int mox_get_board_info(struct mox_rwtm *rwtm)
struct armada_37xx_rwtm_tx_msg msg;
struct armada_37xx_rwtm_rx_msg *reply = &rwtm->reply;
int ret;
+ unsigned long timeout;
msg.command = MBOX_CMD_BOARD_INFO;
ret = mbox_send_message(rwtm->mbox, &msg);
if (ret < 0)
return ret;
- ret = wait_for_completion_timeout(&rwtm->cmd_done, HZ / 2);
- if (ret < 0)
- return ret;
+ timeout = wait_for_completion_timeout(&rwtm->cmd_done, HZ / 2);
+ if (timeout == 0)
+ return -ETIMEDOUT;
ret = mox_get_status(MBOX_CMD_BOARD_INFO, reply->retval);
if (ret == -ENODATA) {
@@ -235,9 +236,9 @@ static int mox_get_board_info(struct mox_rwtm *rwtm)
if (ret < 0)
return ret;
- ret = wait_for_completion_timeout(&rwtm->cmd_done, HZ / 2);
- if (ret < 0)
- return ret;
+ timeout = wait_for_completion_timeout(&rwtm->cmd_done, HZ / 2);
+ if (timeout == 0)
+ return -ETIMEDOUT;
ret = mox_get_status(MBOX_CMD_ECDSA_PUB_KEY, reply->retval);
if (ret == -ENODATA) {
@@ -264,6 +265,7 @@ static int check_get_random_support(struct mox_rwtm *rwtm)
{
struct armada_37xx_rwtm_tx_msg msg;
int ret;
+ unsigned long timeout;
msg.command = MBOX_CMD_GET_RANDOM;
msg.args[0] = 1;
@@ -274,9 +276,9 @@ static int check_get_random_support(struct mox_rwtm *rwtm)
if (ret < 0)
return ret;
- ret = wait_for_completion_timeout(&rwtm->cmd_done, HZ / 2);
- if (ret < 0)
- return ret;
+ timeout = wait_for_completion_timeout(&rwtm->cmd_done, HZ / 2);
+ if (timeout == 0)
+ return -ETIMEDOUT;
return mox_get_status(MBOX_CMD_GET_RANDOM, rwtm->reply.retval);
}
--
2.17.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-04-12 3:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-12 3:12 [PATCH] firmware: turris-mox-rwtm: Fix return value check of wait_for_completion_timeout Miaoqian Lin
-- strict thread matches above, loose matches on Subject: below --
2022-04-11 10:45 Miaoqian Lin
2022-04-11 16:07 ` Marek Behún
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.