2019-07-08 22:47:54

by Martin Hundebøll

[permalink] [raw]
Subject: [PATCH 1/4] tty: n_gsm: remove obsolete mknod doc example

The n_gsm driver handles registration of /dev/gsmttyX nodes, so there's
no need to do mknod manually.

Signed-off-by: Martin Hundebøll <[email protected]>
---
Documentation/serial/n_gsm.rst | 10 ----------
1 file changed, 10 deletions(-)

diff --git a/Documentation/serial/n_gsm.rst b/Documentation/serial/n_gsm.rst
index f3ad9fd26408..78f91ce06956 100644
--- a/Documentation/serial/n_gsm.rst
+++ b/Documentation/serial/n_gsm.rst
@@ -63,16 +63,6 @@ Major parts of the initialization program :
daemon(0,0);
pause();

-4. create the devices corresponding to the "virtual" serial ports (take care,
- each modem has its configuration and some DLC have dedicated functions,
- for example GPS), starting with minor 1 (DLC0 is reserved for the management
- of the mux)::
-
- MAJOR=`cat /proc/devices |grep gsmtty | awk '{print $1}`
- for i in `seq 1 4`; do
- mknod /dev/ttygsm$i c $MAJOR $i
- done
-
5. use these devices as plain serial ports.

for example, it's possible:
--
2.22.0


2019-07-08 23:16:35

by Martin Hundebøll

[permalink] [raw]
Subject: [PATCH 3/4] tty: n_gsm: add helper to convert mux-num to/from tty-base

Make it obvious how the gsm mux number relates to the virtual tty lines
by using helper function instead of shifting 6 bits.

Signed-off-by: Martin Hundebøll <[email protected]>
---
drivers/tty/n_gsm.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
index c4e16b31f9ab..cba06063c44a 100644
--- a/drivers/tty/n_gsm.c
+++ b/drivers/tty/n_gsm.c
@@ -2171,6 +2171,16 @@ static inline void mux_put(struct gsm_mux *gsm)
kref_put(&gsm->ref, gsm_free_muxr);
}

+static inline int mux_num_to_base(struct gsm_mux *gsm)
+{
+ return gsm->num * NUM_DLCI;
+}
+
+static inline unsigned int mux_line_to_num(int line)
+{
+ return line / NUM_DLCI;
+}
+
/**
* gsm_alloc_mux - allocate a mux
*
@@ -2361,7 +2371,7 @@ static int gsmld_attach_gsm(struct tty_struct *tty, struct gsm_mux *gsm)
else {
/* Don't register device 0 - this is the control channel and not
a usable tty interface */
- base = gsm->num << 6; /* Base for this MUX */
+ base = mux_num_to_base(gsm); /* Base for this MUX */
for (i = 1; i < NUM_DLCI; i++)
tty_register_device(gsm_tty_driver, base + i, NULL);
}
@@ -2380,7 +2390,7 @@ static int gsmld_attach_gsm(struct tty_struct *tty, struct gsm_mux *gsm)
static void gsmld_detach_gsm(struct tty_struct *tty, struct gsm_mux *gsm)
{
int i;
- int base = gsm->num << 6; /* Base for this MUX */
+ int base = mux_num_to_base(gsm); /* Base for this MUX */

WARN_ON(tty != gsm->tty);
for (i = 1; i < NUM_DLCI; i++)
@@ -2908,7 +2918,7 @@ static int gsmtty_install(struct tty_driver *driver, struct tty_struct *tty)
struct gsm_mux *gsm;
struct gsm_dlci *dlci;
unsigned int line = tty->index;
- unsigned int mux = line >> 6;
+ unsigned int mux = mux_line_to_num(line);
bool alloc = false;
int ret;

--
2.22.0

2019-07-09 05:33:21

by Jiri Slaby

[permalink] [raw]
Subject: Re: [PATCH 1/4] tty: n_gsm: remove obsolete mknod doc example

On 08. 07. 19, 21:02, Martin Hundebøll wrote:
> The n_gsm driver handles registration of /dev/gsmttyX nodes, so there's
> no need to do mknod manually.
>
> Signed-off-by: Martin Hundebøll <[email protected]>
> ---
> Documentation/serial/n_gsm.rst | 10 ----------
> 1 file changed, 10 deletions(-)
>
> diff --git a/Documentation/serial/n_gsm.rst b/Documentation/serial/n_gsm.rst
> index f3ad9fd26408..78f91ce06956 100644
> --- a/Documentation/serial/n_gsm.rst
> +++ b/Documentation/serial/n_gsm.rst
> @@ -63,16 +63,6 @@ Major parts of the initialization program :
> daemon(0,0);
> pause();
>
> -4. create the devices corresponding to the "virtual" serial ports (take care,
> - each modem has its configuration and some DLC have dedicated functions,
> - for example GPS), starting with minor 1 (DLC0 is reserved for the management
> - of the mux)::
> -
> - MAJOR=`cat /proc/devices |grep gsmtty | awk '{print $1}`
> - for i in `seq 1 4`; do
> - mknod /dev/ttygsm$i c $MAJOR $i
> - done
> -
> 5. use these devices as plain serial ports.

So you should renumber the rest now...

thanks,
--
js
suse labs