Re: RFC: mcu_tty: Trying to open /dev/ttyUSB0 and lock access from a kernel driver

From: Alan Cox
Date: Mon Sep 25 2017 - 19:05:24 EST


On Mon, 25 Sep 2017 15:01:13 +0200
Ulf Samuelsson <linux-kernel@xxxxxxxxxx> wrote:

> Trying to open /dev/ttyUSB from a kernel driver (which works), but
> locking the
> serial port so noone else can access it does not work.
> Any advice would be appreciated.

File locks are advisory only.

For the rest of it you might want to take a look at how the gsm mux
driver works (the protocol stuff is scary but you can ignore that end).
It plugs a line discipline into a tty and that muxes out as a collection
of ttys and shows how it's meant to be done.

That also means you have an owning process with the port open that can do
locking on it and/or route any raw read/writes to the master port into
the bit bucket.

Alan