diff mbox series

[02/19] firmware: turris-mox-rwtm: Fix checking return value of wait_for_completion_timeout()

Message ID 20240612135443.30239-3-kabel@kernel.org (mailing list archive)
State Superseded
Headers show
Series Updates for turris-mox-rwtm driver | expand

Commit Message

Marek Behún June 12, 2024, 1:54 p.m. UTC
The wait_for_completion_timeout() function returns 0 if timed out, and a
positive value if completed. Fix the usage of this function.

Fixes: 389711b37493 ("firmware: Add Turris Mox rWTM firmware driver")
Fixes: 2eab59cf0d20 ("firmware: turris-mox-rwtm: fail probing when firmware does not support hwrng")
Signed-off-by: Marek Behún <kabel@kernel.org>
---
 drivers/firmware/turris-mox-rwtm.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

Comments

Ilpo Järvinen June 13, 2024, 8:06 a.m. UTC | #1
On Wed, 12 Jun 2024, Marek Behún wrote:

> The wait_for_completion_timeout() function returns 0 if timed out, and a
> positive value if completed. Fix the usage of this function.
> 
> Fixes: 389711b37493 ("firmware: Add Turris Mox rWTM firmware driver")
> Fixes: 2eab59cf0d20 ("firmware: turris-mox-rwtm: fail probing when firmware does not support hwrng")
> Signed-off-by: Marek Behún <kabel@kernel.org>
> ---
>  drivers/firmware/turris-mox-rwtm.c | 15 ++++++---------
>  1 file changed, 6 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/firmware/turris-mox-rwtm.c b/drivers/firmware/turris-mox-rwtm.c
> index f1f9160c4195..3f4758e03c81 100644
> --- a/drivers/firmware/turris-mox-rwtm.c
> +++ b/drivers/firmware/turris-mox-rwtm.c
> @@ -202,9 +202,8 @@ 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;
> +	if (!wait_for_completion_timeout(&rwtm->cmd_done, HZ / 2))
> +		return -ETIMEDOUT;
>  
>  	ret = mox_get_status(MBOX_CMD_BOARD_INFO, reply->retval);
>  	if (ret == -ENODATA) {
> @@ -238,9 +237,8 @@ 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;
> +	if (!wait_for_completion_timeout(&rwtm->cmd_done, HZ / 2))
> +		return -ETIMEDOUT;
>  
>  	ret = mox_get_status(MBOX_CMD_ECDSA_PUB_KEY, reply->retval);
>  	if (ret == -ENODATA) {
> @@ -277,9 +275,8 @@ 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;
> +	if (!wait_for_completion_timeout(&rwtm->cmd_done, HZ / 2))
> +		return -ETIMEDOUT;

Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
diff mbox series

Patch

diff --git a/drivers/firmware/turris-mox-rwtm.c b/drivers/firmware/turris-mox-rwtm.c
index f1f9160c4195..3f4758e03c81 100644
--- a/drivers/firmware/turris-mox-rwtm.c
+++ b/drivers/firmware/turris-mox-rwtm.c
@@ -202,9 +202,8 @@  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;
+	if (!wait_for_completion_timeout(&rwtm->cmd_done, HZ / 2))
+		return -ETIMEDOUT;
 
 	ret = mox_get_status(MBOX_CMD_BOARD_INFO, reply->retval);
 	if (ret == -ENODATA) {
@@ -238,9 +237,8 @@  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;
+	if (!wait_for_completion_timeout(&rwtm->cmd_done, HZ / 2))
+		return -ETIMEDOUT;
 
 	ret = mox_get_status(MBOX_CMD_ECDSA_PUB_KEY, reply->retval);
 	if (ret == -ENODATA) {
@@ -277,9 +275,8 @@  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;
+	if (!wait_for_completion_timeout(&rwtm->cmd_done, HZ / 2))
+		return -ETIMEDOUT;
 
 	return mox_get_status(MBOX_CMD_GET_RANDOM, rwtm->reply.retval);
 }