mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg KH <gregkh@linuxfoundation.org>
To: "D. Starke" <daniel.starke@siemens.com>
Cc: linux-serial@vger.kernel.org, jirislaby@kernel.org,
	ilpo.jarvinen@linux.intel.com, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 3/3] tty: n_gsm: add TIOCMIWAIT support
Date: Thu, 2 Feb 2023 16:39:38 +0100	[thread overview]
Message-ID: <Y9vZOsAuzKjBNArJ@kroah.com> (raw)
In-Reply-To: <20230202145934.22641-3-daniel.starke@siemens.com>

On Thu, Feb 02, 2023 at 03:59:34PM +0100, D. Starke wrote:
> From: Daniel Starke <daniel.starke@siemens.com>
> 
> Add support for the TIOCMIWAIT ioctl on the virtual ttys. This enables the
> user to wait for virtual modem signals like RING.
> 
> More work is needed to support also TIOCGICOUNT.
> 
> Signed-off-by: Daniel Starke <daniel.starke@siemens.com>
> ---
>  drivers/tty/n_gsm.c | 33 ++++++++++++++++++++++++++++++++-
>  1 file changed, 32 insertions(+), 1 deletion(-)
> 
> v1 -> v2:
> A remark regarding TIOCGICOUNT has been added to the commit message.
> Wake ups in gsm_dlci_close() and gsm_dlci_begin_close() have been added to
> cope with closed DLCI during TIOCMIWAIT.
> gsm_wait_modem_change() has been properly commented to highlight all use
> cases. Furthermore, the function has been simplified and a DLCI state
> condition added to the wait_event_interruptible() call to deal with DLCI
> termination during TIOCMIWAIT correctly.
> 
> Link: https://lore.kernel.org/all/Y9pgT4VcW3oGaSbY@kroah.com/
> 
> diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
> index cf1ab7d619d9..4f710a6309a7 100644
> --- a/drivers/tty/n_gsm.c
> +++ b/drivers/tty/n_gsm.c
> @@ -1542,6 +1542,7 @@ static void gsm_process_modem(struct tty_struct *tty, struct gsm_dlci *dlci,
>  	if (brk & 0x01)
>  		tty_insert_flip_char(&dlci->port, 0, TTY_BREAK);
>  	dlci->modem_rx = mlines;
> +	wake_up_interruptible(&dlci->gsm->event);
>  }
>  
>  /**
> @@ -2129,7 +2130,7 @@ static void gsm_dlci_close(struct gsm_dlci *dlci)
>  	/* A DLCI 0 close is a MUX termination so we need to kick that
>  	   back to userspace somehow */
>  	gsm_dlci_data_kick(dlci);
> -	wake_up(&dlci->gsm->event);
> +	wake_up_all(&dlci->gsm->event);
>  }
>  
>  /**
> @@ -2339,6 +2340,7 @@ static void gsm_dlci_begin_close(struct gsm_dlci *dlci)
>  	dlci->state = DLCI_CLOSING;
>  	gsm_command(dlci->gsm, dlci->addr, DISC|PF);
>  	mod_timer(&dlci->t1, jiffies + gsm->t1 * HZ / 100);
> +	wake_up_interruptible(&gsm->event);
>  }
>  
>  /**
> @@ -3877,6 +3879,33 @@ static int gsm_modem_update(struct gsm_dlci *dlci, u8 brk)
>  	return -EPROTONOSUPPORT;
>  }
>  
> +/**
> + * gsm_wait_modem_change - wait for modem status line change
> + * @dlci: channel
> + * @mask: modem status line bits
> + *
> + * The function returns if:
> + * - any given modem status line bit changed
> + * - the wait event function got interrupted (e.g. by a signal)
> + * - the underlying DLCI was closed
> + * - the underlying ldisc device was removed
> + */
> +static int gsm_wait_modem_change(struct gsm_dlci *dlci, u32 mask)

mask is u32, but:

> +{
> +	struct gsm_mux *gsm = dlci->gsm;
> +	u32 old = dlci->modem_rx;
> +	int ret;
> +
> +	ret = wait_event_interruptible(gsm->event, gsm->dead ||
> +				       dlci->state != DLCI_OPEN ||
> +				       (old ^ dlci->modem_rx) & mask);
> +	if (gsm->dead)
> +		return -ENODEV;
> +	if (dlci->state != DLCI_OPEN)
> +		return -EL2NSYNC;
> +	return ret;
> +}
> +
>  static bool gsm_carrier_raised(struct tty_port *port)
>  {
>  	struct gsm_dlci *dlci = container_of(port, struct gsm_dlci, port);
> @@ -4136,6 +4165,8 @@ static int gsmtty_ioctl(struct tty_struct *tty,
>  		gsm_destroy_network(dlci);
>  		mutex_unlock(&dlci->mutex);
>  		return 0;
> +	case TIOCMIWAIT:
> +		return gsm_wait_modem_change(dlci, arg);

Arg is a unsigned long.  Shouldn't you cast this?

thanks,

greg k-h

  reply	other threads:[~2023-02-02 15:48 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-02 14:59 [PATCH v2 1/3] tty: n_gsm: add keep alive support D. Starke
2023-02-02 14:59 ` [PATCH v2 2/3] tty: n_gsm: add RING/CD control support D. Starke
2023-02-02 14:59 ` [PATCH v2 3/3] tty: n_gsm: add TIOCMIWAIT support D. Starke
2023-02-02 15:39   ` Greg KH [this message]
2023-02-02 15:37 ` [PATCH v2 1/3] tty: n_gsm: add keep alive support Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y9vZOsAuzKjBNArJ@kroah.com \
    --to=gregkh@linuxfoundation.org \
    --cc=daniel.starke@siemens.com \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=jirislaby@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®