2018-12-11 00:07:07

by Arnd Bergmann

[permalink] [raw]
Subject: [PATCH] staging: speakup: change semaphore to completion

In this driver, both function the same way, but we want to eventually
kill off semaphores, so a completion is the better choice here.

Signed-off-by: Arnd Bergmann <[email protected]>
---
drivers/staging/speakup/spk_ttyio.c | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/speakup/spk_ttyio.c b/drivers/staging/speakup/spk_ttyio.c
index 979e3ae249c1..c92bbd05516e 100644
--- a/drivers/staging/speakup/spk_ttyio.c
+++ b/drivers/staging/speakup/spk_ttyio.c
@@ -10,7 +10,7 @@

struct spk_ldisc_data {
char buf;
- struct semaphore sem;
+ struct completion completion;
bool buf_free;
};

@@ -55,7 +55,7 @@ static int spk_ttyio_ldisc_open(struct tty_struct *tty)
if (!ldisc_data)
return -ENOMEM;

- sema_init(&ldisc_data->sem, 0);
+ init_completion(&ldisc_data->completion);
ldisc_data->buf_free = true;
speakup_tty->disc_data = ldisc_data;

@@ -95,7 +95,7 @@ static int spk_ttyio_receive_buf2(struct tty_struct *tty,

ldisc_data->buf = cp[0];
ldisc_data->buf_free = false;
- up(&ldisc_data->sem);
+ complete(&ldisc_data->completion);

return 1;
}
@@ -286,7 +286,8 @@ static unsigned char ttyio_in(int timeout)
struct spk_ldisc_data *ldisc_data = speakup_tty->disc_data;
char rv;

- if (down_timeout(&ldisc_data->sem, usecs_to_jiffies(timeout)) == -ETIME) {
+ if (wait_for_completion_timeout(&ldisc_data->completion,
+ usecs_to_jiffies(timeout)) == 0) {
if (timeout)
pr_warn("spk_ttyio: timeout (%d) while waiting for input\n",
timeout);
--
2.20.0



2018-12-11 01:18:09

by Samuel Thibault

[permalink] [raw]
Subject: Re: [PATCH] staging: speakup: change semaphore to completion

Arnd Bergmann, le lun. 10 déc. 2018 22:41:50 +0100, a ecrit:
> In this driver, both function the same way, but we want to eventually
> kill off semaphores, so a completion is the better choice here.
>
> Signed-off-by: Arnd Bergmann <[email protected]>

Reviewed-by: Samuel Thibault <[email protected]>

> ---
> drivers/staging/speakup/spk_ttyio.c | 9 +++++----
> 1 file changed, 5 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/staging/speakup/spk_ttyio.c b/drivers/staging/speakup/spk_ttyio.c
> index 979e3ae249c1..c92bbd05516e 100644
> --- a/drivers/staging/speakup/spk_ttyio.c
> +++ b/drivers/staging/speakup/spk_ttyio.c
> @@ -10,7 +10,7 @@
>
> struct spk_ldisc_data {
> char buf;
> - struct semaphore sem;
> + struct completion completion;
> bool buf_free;
> };
>
> @@ -55,7 +55,7 @@ static int spk_ttyio_ldisc_open(struct tty_struct *tty)
> if (!ldisc_data)
> return -ENOMEM;
>
> - sema_init(&ldisc_data->sem, 0);
> + init_completion(&ldisc_data->completion);
> ldisc_data->buf_free = true;
> speakup_tty->disc_data = ldisc_data;
>
> @@ -95,7 +95,7 @@ static int spk_ttyio_receive_buf2(struct tty_struct *tty,
>
> ldisc_data->buf = cp[0];
> ldisc_data->buf_free = false;
> - up(&ldisc_data->sem);
> + complete(&ldisc_data->completion);
>
> return 1;
> }
> @@ -286,7 +286,8 @@ static unsigned char ttyio_in(int timeout)
> struct spk_ldisc_data *ldisc_data = speakup_tty->disc_data;
> char rv;
>
> - if (down_timeout(&ldisc_data->sem, usecs_to_jiffies(timeout)) == -ETIME) {
> + if (wait_for_completion_timeout(&ldisc_data->completion,
> + usecs_to_jiffies(timeout)) == 0) {
> if (timeout)
> pr_warn("spk_ttyio: timeout (%d) while waiting for input\n",
> timeout);
> --
> 2.20.0
>

--
Samuel
Progress (n.): The process through which the Internet has evolved from
smart people in front of dumb terminals to dumb people in front of smart
terminals.