Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 370E9C61DA4 for ; Thu, 2 Feb 2023 15:48:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233137AbjBBPsz (ORCPT ); Thu, 2 Feb 2023 10:48:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49754 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232949AbjBBPs3 (ORCPT ); Thu, 2 Feb 2023 10:48:29 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B1C5B20D07; Thu, 2 Feb 2023 07:48:04 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id 1F18ECE28E5; Thu, 2 Feb 2023 15:39:43 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CF1D6C433EF; Thu, 2 Feb 2023 15:39:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1675352381; bh=G9U0bwBFDr4Az7fj7vKYud2tMLL3AwsRgYpOxZ00iok=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=pFoEofEI6DaPMNfsK5NAXlfIidxtWncQoOHV9u3INIoUgBo5B6keCEapmPsSkHJTG X+ZpbYO8boGGKnmNHT9YG0lx/ri7vlAtRjurJq6ncOgahjrEltNJYN0fT+SJ28+uPw LrZgH8SmETzOqFxW5NPbApUTlMA6Bjz/oh4SKNEA= Date: Thu, 2 Feb 2023 16:39:38 +0100 From: Greg KH To: "D. Starke" 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 Message-ID: References: <20230202145934.22641-1-daniel.starke@siemens.com> <20230202145934.22641-3-daniel.starke@siemens.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230202145934.22641-3-daniel.starke@siemens.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 02, 2023 at 03:59:34PM +0100, D. Starke wrote: > From: Daniel Starke > > 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 > --- > 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