All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Måns Rullgård" <mans@mansr.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Johan Hovold <johan@kernel.org>, linux-usb@vger.kernel.org
Subject: Re: [PATCH] USB: serial: use tty_port_register_device_serdev
Date: Thu, 02 May 2024 15:32:19 +0100	[thread overview]
Message-ID: <yw1xedakb7yk.fsf@mansr.com> (raw)
In-Reply-To: <2024050228-emission-ointment-88de@gregkh> (Greg Kroah-Hartman's message of "Thu, 2 May 2024 15:57:56 +0200")

Greg Kroah-Hartman <gregkh@linuxfoundation.org> writes:

> On Thu, May 02, 2024 at 02:24:41PM +0100, Måns Rullgård wrote:
>> Greg Kroah-Hartman <gregkh@linuxfoundation.org> writes:
>> 
>> > On Thu, May 02, 2024 at 11:45:44AM +0100, Måns Rullgård wrote:
>> >> Johan Hovold <johan@kernel.org> writes:
>> >> 
>> >> > On Thu, May 02, 2024 at 11:07:28AM +0100, Mans Rullgard wrote:
>> >> >> Use tty_port_register_device_serdev() so that usb-serial devices
>> >> >> can be used as serdev controllers.
>> >> >
>> >> > I'm afraid it's not that easy. The reason serdev is not enabled for
>> >> > usb-serial is that there's currently no support for handling hotplug in
>> >> > serdev. The device can go away from under you at any time and then you'd
>> >> > crash the kernel.
>> >> 
>> >> Oh, that's unfortunate.  Regular serial ports can go away too, though,
>> >> and that seems to be handled fine.  What am I missing?
>> >
>> > How is it handled?  Normal serial ports can go away but in practice,
>> > it's a rare occurance, and usually people use serdev for devices where
>> > the ports can not be removed (i.e. internal connections).
>> 
>> If I unbind a regular serial port from its driver using sysfs, a serdev
>> device defined in a device tree gets removed as expected.  Binding the
>> serial port makes everything come back again.  I fail to see any problem
>> here.  If there is one, you'll have to be less evasive in explaining
>> what it is.
>
> Try yanking a usb-serial device out with this patch applied and see what
> happens.  I'm pretty sure serdev will not handle that well, just like if
> you yank out a pci serial device while it is being used.  Doing
> bind/unbind is not a "surprise" removal, but a nice orderly one :)
>
> If this does now work, nice, but I haven't seen the changes to serdev to
> make this happen, I wonder what changed...

Turns out I missed one change that is needed for unplugging to be
handled:

--- a/drivers/usb/serial/bus.c
+++ b/drivers/usb/serial/bus.c
@@ -91,7 +91,7 @@ static void usb_serial_device_remove(struct device *dev)
        autopm_err = usb_autopm_get_interface(port->serial->interface);
 
        minor = port->minor;
-       tty_unregister_device(usb_serial_tty_driver, minor);
+       tty_port_unregister_device(&port->port, usb_serial_tty_driver, minor);
 
        driver = port->serial->type;
        if (driver->port_remove)

With this additional change, yanking (shorting the data lines; the thing
is soldered) the usb-serial converter works, although a couple of
warnings are printed:

[   28.678301] usb 1-1: USB disconnect, device number 2
[   28.683695] ttyUSB ttyUSB0: tty_hangup: tty->count(1) != (#fd's(0) + #kopen's(0))
[   28.691516] ftdi_sio ttyUSB0: error from flowcontrol urb
[   28.759056] ttyUSB ttyUSB0: tty_port_close_start: tty->count = 1 port count = 0
[   28.772531] ftdi_sio ttyUSB0: FTDI USB Serial Device converter now disconnected from ttyUSB0
[   28.781346] ftdi_sio 1-1:1.0: device disconnected

Where should I go looking for the cause of these?

-- 
Måns Rullgård

  reply	other threads:[~2024-05-02 14:32 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-02 10:07 [PATCH] USB: serial: use tty_port_register_device_serdev Mans Rullgard
2024-05-02 10:18 ` Johan Hovold
2024-05-02 10:45   ` Måns Rullgård
2024-05-02 10:54     ` Greg Kroah-Hartman
2024-05-02 13:24       ` Måns Rullgård
2024-05-02 13:57         ` Greg Kroah-Hartman
2024-05-02 14:32           ` Måns Rullgård [this message]
2024-05-02 23:04 ` kernel test robot

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=yw1xedakb7yk.fsf@mansr.com \
    --to=mans@mansr.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=johan@kernel.org \
    --cc=linux-usb@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.