[PATCH] memstick: Add timeout to prevent indefinite waiting

Jiayi Li posted 1 patch 2 months ago
drivers/memstick/core/memstick.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
[PATCH] memstick: Add timeout to prevent indefinite waiting
Posted by Jiayi Li 2 months ago
Add timeout handling to wait_for_completion calls in memstick_set_rw_addr()
and memstick_alloc_card() to prevent indefinite blocking in case of
hardware or communication failures.

Signed-off-by: Jiayi Li <lijiayi@kylinos.cn>
---
 drivers/memstick/core/memstick.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/memstick/core/memstick.c b/drivers/memstick/core/memstick.c
index 95e65f4958f2..3eeb93b51f80 100644
--- a/drivers/memstick/core/memstick.c
+++ b/drivers/memstick/core/memstick.c
@@ -370,7 +370,9 @@ int memstick_set_rw_addr(struct memstick_dev *card)
 {
 	card->next_request = h_memstick_set_rw_addr;
 	memstick_new_req(card->host);
-	wait_for_completion(&card->mrq_complete);
+	if (!wait_for_completion_timeout(&card->mrq_complete,
+			msecs_to_jiffies(500)))
+		card->current_mrq.error = -ETIMEDOUT;
 
 	return card->current_mrq.error;
 }
@@ -404,7 +406,9 @@ static struct memstick_dev *memstick_alloc_card(struct memstick_host *host)
 
 		card->next_request = h_memstick_read_dev_id;
 		memstick_new_req(host);
-		wait_for_completion(&card->mrq_complete);
+		if (!wait_for_completion_timeout(&card->mrq_complete,
+				msecs_to_jiffies(500)))
+			card->current_mrq.error = -ETIMEDOUT;
 
 		if (card->current_mrq.error)
 			goto err_out;
-- 
2.47.1
Re: [PATCH] memstick: Add timeout to prevent indefinite waiting
Posted by Ulf Hansson 1 month, 2 weeks ago
On Mon, 4 Aug 2025 at 04:48, Jiayi Li <lijiayi@kylinos.cn> wrote:
>
> Add timeout handling to wait_for_completion calls in memstick_set_rw_addr()
> and memstick_alloc_card() to prevent indefinite blocking in case of
> hardware or communication failures.
>
> Signed-off-by: Jiayi Li <lijiayi@kylinos.cn>

Applied for next, thanks!

Kind regards
Uffe


> ---
>  drivers/memstick/core/memstick.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/memstick/core/memstick.c b/drivers/memstick/core/memstick.c
> index 95e65f4958f2..3eeb93b51f80 100644
> --- a/drivers/memstick/core/memstick.c
> +++ b/drivers/memstick/core/memstick.c
> @@ -370,7 +370,9 @@ int memstick_set_rw_addr(struct memstick_dev *card)
>  {
>         card->next_request = h_memstick_set_rw_addr;
>         memstick_new_req(card->host);
> -       wait_for_completion(&card->mrq_complete);
> +       if (!wait_for_completion_timeout(&card->mrq_complete,
> +                       msecs_to_jiffies(500)))
> +               card->current_mrq.error = -ETIMEDOUT;
>
>         return card->current_mrq.error;
>  }
> @@ -404,7 +406,9 @@ static struct memstick_dev *memstick_alloc_card(struct memstick_host *host)
>
>                 card->next_request = h_memstick_read_dev_id;
>                 memstick_new_req(host);
> -               wait_for_completion(&card->mrq_complete);
> +               if (!wait_for_completion_timeout(&card->mrq_complete,
> +                               msecs_to_jiffies(500)))
> +                       card->current_mrq.error = -ETIMEDOUT;
>
>                 if (card->current_mrq.error)
>                         goto err_out;
> --
> 2.47.1
>