On Mon, 29 Aug 2016, Greg KH wrote:
> > >> I have since compiled 4.8.0_rc1. And just as you guys suggested a part
> > >> of problem is solved. The minor number now definitely goes up to 512
> > >> before giving no more free serial devices. But it still doesn't reuse
> > >> the minors after disconnecting.
> > >>
> > >> In my code I'm calling modbus_close and modbus_free which in turn call
> > >> close() and free() on the file descriptor. Shouldn't this make the
> > >> minor reusable?
Yes, it should.
> > >> >From what i understand minor numbers are allocated and freed by the
> > >> driver. So how does the driver know to release the minor number after
> > >> the file descriptor is closed?
> > >
> > > The USB serial driver core code handles this for you automatically after
> > > the last reference goes away. Are you sure that userspace is properly
> > > releasing the device properly?
> > >
> > > thanks,
> > >
> > > greg k-h
> >
> > >From my understanding it is, but let me double check. If i compile the
> > kernel with some print statements in usb-serial.c, will i get the
> > output in stdout?
>
> You can use dynamic debugging on the usb_serial.ko kernel module to see
> the open/close messages in the kernel log, along with when minors are
> allocated. Read about how to turn that on in the Documentation/
> directory (search for dynamic debugging).
The command is:
echo module usbserial =p >/sys/kernel/debug/dynamic_debug/control
(note that you need to mount a debugfs filesystem on /sys/kernel/debug
first).
> > In the userspace is it sufficient to just call close() on the file
> > descriptor in /dev ?
>
> Yes.
>
> > Is it possible that udev has already replaced /dev/ttyUSBx with
> > /dev/ttyUSBx+1 by the time the program calls close() on it?
>
> Yes, if it is open. And udev does not create the device node, the
> kernel is doing so.
>
> If your program/device does the following:
> - userspace open ttyUSB0
> - device disconnect
> - device connect (ttyUSB1)
> - userspace close ttyUSB0
> - kernel removes ttyUSB0
>
> that could be what is happening here, you are racing and loosing :(
But even in this case, the kernel would re-use the old minor numbers
once the ttyUSB files had been closed.
Alan Stern
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html