Re: [PATCH 2/2] usb: gadget serial: Honour termios CLOCAL on disconnect

2014-10-27 Thread Peter Hurley
On 10/27/2014 09:38 AM, Felipe Balbi wrote:
> Hi,
> 
> On Sun, Oct 26, 2014 at 08:01:30PM +0200, Kyösti Mälkki wrote:
>> There are applications where it is desirable to not hangup ttyGS* when
>> USB disconnect is detected. USB host side of communication may
>> power-cycle periodically or there may be the actual need to physically
>> disconnect and reconnect USB cable temporarily.
>>
>> USB disconnects on serial gadget are comparable to loss of Carrier Detect
>> of conventional UARTs. With the change, if ttyGS* has termios CLOCAL flag
>> set, disconnect on USB does not hangup the TTY.
>>
>> Signed-off-by: Kyösti Mälkki 
>> ---
>>  drivers/usb/gadget/function/u_serial.c | 9 +++--
>>  1 file changed, 7 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/usb/gadget/function/u_serial.c 
>> b/drivers/usb/gadget/function/u_serial.c
>> index 491082a..e68ffd7 100644
>> --- a/drivers/usb/gadget/function/u_serial.c
>> +++ b/drivers/usb/gadget/function/u_serial.c
>> @@ -1254,8 +1254,13 @@ void gserial_disconnect(struct gserial *gser)
>>  gser->ioport = NULL;
>>  if (port->port.count > 0 || port->openclose) {
>>  wake_up_interruptible(&port->drain_wait);
>> -if (port->port.tty)
>> -tty_hangup(port->port.tty);
>> +struct tty_struct *tty = port->port.tty;
> 
> declare above as Sergei said.
> 
>> +if (tty) {
> 
> is there any situation where tty would be NULL here ?
> 
>> +if (tty->termios.c_cflag & CLOCAL)
>> +stop_tty(tty);
>> +else
>> +tty_hangup(tty);
> 
> this I'll defer to Greg who also maintains tty.

I'm curious what happens without stop_tty().

The tty is restartable from userspace with
tcflow(fd, TCOOFF);
tcflow(fd, TCOON);

Regards,
Peter Hurley
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/2] usb: gadget serial: Honour termios CLOCAL on disconnect

2014-10-27 Thread Felipe Balbi
On Mon, Oct 27, 2014 at 05:43:06PM +0200, Kyösti Mälkki wrote:
> On 10/27/2014 03:38 PM, Felipe Balbi wrote:
> >Hi,
> >
> >On Sun, Oct 26, 2014 at 08:01:30PM +0200, Kyösti Mälkki wrote:
> >>There are applications where it is desirable to not hangup ttyGS* when
> >>USB disconnect is detected. USB host side of communication may
> >>power-cycle periodically or there may be the actual need to physically
> >>disconnect and reconnect USB cable temporarily.
> >>
> >>USB disconnects on serial gadget are comparable to loss of Carrier Detect
> >>of conventional UARTs. With the change, if ttyGS* has termios CLOCAL flag
> >>set, disconnect on USB does not hangup the TTY.
> >>
> >>Signed-off-by: Kyösti Mälkki 
> >>---
> >>  drivers/usb/gadget/function/u_serial.c | 9 +++--
> >>  1 file changed, 7 insertions(+), 2 deletions(-)
> >>
> >>diff --git a/drivers/usb/gadget/function/u_serial.c 
> >>b/drivers/usb/gadget/function/u_serial.c
> >>index 491082a..e68ffd7 100644
> >>--- a/drivers/usb/gadget/function/u_serial.c
> >>+++ b/drivers/usb/gadget/function/u_serial.c
> >>@@ -1254,8 +1254,13 @@ void gserial_disconnect(struct gserial *gser)
> >>gser->ioport = NULL;
> >>if (port->port.count > 0 || port->openclose) {
> >>wake_up_interruptible(&port->drain_wait);
> >>-   if (port->port.tty)
> >>-   tty_hangup(port->port.tty);
> >>+   struct tty_struct *tty = port->port.tty;
> >
> >declare above as Sergei said.
> >
> >>+   if (tty) {
> >
> >is there any situation where tty would be NULL here ?
> >
> >>+   if (tty->termios.c_cflag & CLOCAL)
> >>+   stop_tty(tty);
> >>+   else
> >>+   tty_hangup(tty);
> >
> >this I'll defer to Greg who also maintains tty.
> >
> 
> My main concern is if someone runs getty on ttyACM without explicitly
> clearing CLOCAL. With the patch here login session would no longer get
> SIGHUP if cable is disconnected. And it is not possible to tell if it is the
> same cable that is plugged back in.

true, but woudln't the same thing happen with a real UART port using
8250.ko ?

-- 
balbi


signature.asc
Description: Digital signature


Re: [PATCH 2/2] usb: gadget serial: Honour termios CLOCAL on disconnect

2014-10-27 Thread Kyösti Mälkki

On 10/27/2014 03:38 PM, Felipe Balbi wrote:

Hi,

On Sun, Oct 26, 2014 at 08:01:30PM +0200, Kyösti Mälkki wrote:

There are applications where it is desirable to not hangup ttyGS* when
USB disconnect is detected. USB host side of communication may
power-cycle periodically or there may be the actual need to physically
disconnect and reconnect USB cable temporarily.

USB disconnects on serial gadget are comparable to loss of Carrier Detect
of conventional UARTs. With the change, if ttyGS* has termios CLOCAL flag
set, disconnect on USB does not hangup the TTY.

Signed-off-by: Kyösti Mälkki 
---
  drivers/usb/gadget/function/u_serial.c | 9 +++--
  1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/function/u_serial.c 
b/drivers/usb/gadget/function/u_serial.c
index 491082a..e68ffd7 100644
--- a/drivers/usb/gadget/function/u_serial.c
+++ b/drivers/usb/gadget/function/u_serial.c
@@ -1254,8 +1254,13 @@ void gserial_disconnect(struct gserial *gser)
gser->ioport = NULL;
if (port->port.count > 0 || port->openclose) {
wake_up_interruptible(&port->drain_wait);
-   if (port->port.tty)
-   tty_hangup(port->port.tty);
+   struct tty_struct *tty = port->port.tty;


declare above as Sergei said.


+   if (tty) {


is there any situation where tty would be NULL here ?


+   if (tty->termios.c_cflag & CLOCAL)
+   stop_tty(tty);
+   else
+   tty_hangup(tty);


this I'll defer to Greg who also maintains tty.



My main concern is if someone runs getty on ttyACM without explicitly 
clearing CLOCAL. With the patch here login session would no longer get 
SIGHUP if cable is disconnected. And it is not possible to tell if it is 
the same cable that is plugged back in.


KM




--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/2] usb: gadget serial: Honour termios CLOCAL on disconnect

2014-10-27 Thread Felipe Balbi
Hi,

On Sun, Oct 26, 2014 at 08:01:30PM +0200, Kyösti Mälkki wrote:
> There are applications where it is desirable to not hangup ttyGS* when
> USB disconnect is detected. USB host side of communication may
> power-cycle periodically or there may be the actual need to physically
> disconnect and reconnect USB cable temporarily.
> 
> USB disconnects on serial gadget are comparable to loss of Carrier Detect
> of conventional UARTs. With the change, if ttyGS* has termios CLOCAL flag
> set, disconnect on USB does not hangup the TTY.
> 
> Signed-off-by: Kyösti Mälkki 
> ---
>  drivers/usb/gadget/function/u_serial.c | 9 +++--
>  1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/gadget/function/u_serial.c 
> b/drivers/usb/gadget/function/u_serial.c
> index 491082a..e68ffd7 100644
> --- a/drivers/usb/gadget/function/u_serial.c
> +++ b/drivers/usb/gadget/function/u_serial.c
> @@ -1254,8 +1254,13 @@ void gserial_disconnect(struct gserial *gser)
>   gser->ioport = NULL;
>   if (port->port.count > 0 || port->openclose) {
>   wake_up_interruptible(&port->drain_wait);
> - if (port->port.tty)
> - tty_hangup(port->port.tty);
> + struct tty_struct *tty = port->port.tty;

declare above as Sergei said.

> + if (tty) {

is there any situation where tty would be NULL here ?

> + if (tty->termios.c_cflag & CLOCAL)
> + stop_tty(tty);
> + else
> + tty_hangup(tty);

this I'll defer to Greg who also maintains tty.

-- 
balbi


signature.asc
Description: Digital signature


Re: [PATCH 2/2] usb: gadget serial: Honour termios CLOCAL on disconnect

2014-10-27 Thread Kyösti Mälkki

On 10/27/2014 02:31 PM, Sergei Shtylyov wrote:

Hello.

On 10/26/2014 9:01 PM, Kyösti Mälkki wrote:


There are applications where it is desirable to not hangup ttyGS* when
USB disconnect is detected. USB host side of communication may
power-cycle periodically or there may be the actual need to physically
disconnect and reconnect USB cable temporarily.



USB disconnects on serial gadget are comparable to loss of Carrier Detect
of conventional UARTs. With the change, if ttyGS* has termios CLOCAL flag
set, disconnect on USB does not hangup the TTY.



Signed-off-by: Kyösti Mälkki 
---
  drivers/usb/gadget/function/u_serial.c | 9 +++--
  1 file changed, 7 insertions(+), 2 deletions(-)



diff --git a/drivers/usb/gadget/function/u_serial.c
b/drivers/usb/gadget/function/u_serial.c
index 491082a..e68ffd7 100644
--- a/drivers/usb/gadget/function/u_serial.c
+++ b/drivers/usb/gadget/function/u_serial.c
@@ -1254,8 +1254,13 @@ void gserial_disconnect(struct gserial *gser)
  gser->ioport = NULL;
  if (port->port.count > 0 || port->openclose) {
  wake_up_interruptible(&port->drain_wait);
-if (port->port.tty)
-tty_hangup(port->port.tty);
+struct tty_struct *tty = port->port.tty;


Don't declare variables amidst the code. And please add empty line
after declaration.



Sloppy rebase there from my part :/
I'll update once there is advice on the CLOCAL matter itself.


+if (tty) {
+if (tty->termios.c_cflag & CLOCAL)
+stop_tty(tty);
+else
+tty_hangup(tty);
+}
  }


WBR, Sergei




Thanks,
KM
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 2/2] usb: gadget serial: Honour termios CLOCAL on disconnect

2014-10-27 Thread Sergei Shtylyov

Hello.

On 10/26/2014 9:01 PM, Kyösti Mälkki wrote:


There are applications where it is desirable to not hangup ttyGS* when
USB disconnect is detected. USB host side of communication may
power-cycle periodically or there may be the actual need to physically
disconnect and reconnect USB cable temporarily.



USB disconnects on serial gadget are comparable to loss of Carrier Detect
of conventional UARTs. With the change, if ttyGS* has termios CLOCAL flag
set, disconnect on USB does not hangup the TTY.



Signed-off-by: Kyösti Mälkki 
---
  drivers/usb/gadget/function/u_serial.c | 9 +++--
  1 file changed, 7 insertions(+), 2 deletions(-)



diff --git a/drivers/usb/gadget/function/u_serial.c 
b/drivers/usb/gadget/function/u_serial.c
index 491082a..e68ffd7 100644
--- a/drivers/usb/gadget/function/u_serial.c
+++ b/drivers/usb/gadget/function/u_serial.c
@@ -1254,8 +1254,13 @@ void gserial_disconnect(struct gserial *gser)
gser->ioport = NULL;
if (port->port.count > 0 || port->openclose) {
wake_up_interruptible(&port->drain_wait);
-   if (port->port.tty)
-   tty_hangup(port->port.tty);
+   struct tty_struct *tty = port->port.tty;


   Don't declare variables amidst the code. And please add empty line after 
declaration.



+   if (tty) {
+   if (tty->termios.c_cflag & CLOCAL)
+   stop_tty(tty);
+   else
+   tty_hangup(tty);
+   }
}


WBR, Sergei

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 2/2] usb: gadget serial: Honour termios CLOCAL on disconnect

2014-10-26 Thread Kyösti Mälkki
There are applications where it is desirable to not hangup ttyGS* when
USB disconnect is detected. USB host side of communication may
power-cycle periodically or there may be the actual need to physically
disconnect and reconnect USB cable temporarily.

USB disconnects on serial gadget are comparable to loss of Carrier Detect
of conventional UARTs. With the change, if ttyGS* has termios CLOCAL flag
set, disconnect on USB does not hangup the TTY.

Signed-off-by: Kyösti Mälkki 
---
 drivers/usb/gadget/function/u_serial.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/function/u_serial.c 
b/drivers/usb/gadget/function/u_serial.c
index 491082a..e68ffd7 100644
--- a/drivers/usb/gadget/function/u_serial.c
+++ b/drivers/usb/gadget/function/u_serial.c
@@ -1254,8 +1254,13 @@ void gserial_disconnect(struct gserial *gser)
gser->ioport = NULL;
if (port->port.count > 0 || port->openclose) {
wake_up_interruptible(&port->drain_wait);
-   if (port->port.tty)
-   tty_hangup(port->port.tty);
+   struct tty_struct *tty = port->port.tty;
+   if (tty) {
+   if (tty->termios.c_cflag & CLOCAL)
+   stop_tty(tty);
+   else
+   tty_hangup(tty);
+   }
}
spin_unlock_irqrestore(&port->port_lock, flags);
 
-- 
1.8.1.1

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html