Commit 43a9e710 authored by Martin Hundebøll's avatar Martin Hundebøll Committed by Greg Kroah-Hartman

tty: n_gsm: add helpers 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 functions instead of shifting 6 bits.
Signed-off-by: default avatarMartin Hundebøll <martin@geanix.com>
Link: https://lore.kernel.org/r/20190710192656.60381-3-martin@geanix.comSigned-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent a64d19aa
...@@ -2171,6 +2171,16 @@ static inline void mux_put(struct gsm_mux *gsm) ...@@ -2171,6 +2171,16 @@ static inline void mux_put(struct gsm_mux *gsm)
kref_put(&gsm->ref, gsm_free_muxr); kref_put(&gsm->ref, gsm_free_muxr);
} }
static inline unsigned int mux_num_to_base(struct gsm_mux *gsm)
{
return gsm->num * NUM_DLCI;
}
static inline unsigned int mux_line_to_num(unsigned int line)
{
return line / NUM_DLCI;
}
/** /**
* gsm_alloc_mux - allocate a mux * gsm_alloc_mux - allocate a mux
* *
...@@ -2351,7 +2361,8 @@ static int gsmld_output(struct gsm_mux *gsm, u8 *data, int len) ...@@ -2351,7 +2361,8 @@ static int gsmld_output(struct gsm_mux *gsm, u8 *data, int len)
static int gsmld_attach_gsm(struct tty_struct *tty, struct gsm_mux *gsm) static int gsmld_attach_gsm(struct tty_struct *tty, struct gsm_mux *gsm)
{ {
int ret, i, base; unsigned int base;
int ret, i;
gsm->tty = tty_kref_get(tty); gsm->tty = tty_kref_get(tty);
gsm->output = gsmld_output; gsm->output = gsmld_output;
...@@ -2361,7 +2372,7 @@ static int gsmld_attach_gsm(struct tty_struct *tty, struct gsm_mux *gsm) ...@@ -2361,7 +2372,7 @@ static int gsmld_attach_gsm(struct tty_struct *tty, struct gsm_mux *gsm)
else { else {
/* Don't register device 0 - this is the control channel and not /* Don't register device 0 - this is the control channel and not
a usable tty interface */ 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++) for (i = 1; i < NUM_DLCI; i++)
tty_register_device(gsm_tty_driver, base + i, NULL); tty_register_device(gsm_tty_driver, base + i, NULL);
} }
...@@ -2379,8 +2390,8 @@ static int gsmld_attach_gsm(struct tty_struct *tty, struct gsm_mux *gsm) ...@@ -2379,8 +2390,8 @@ 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) static void gsmld_detach_gsm(struct tty_struct *tty, struct gsm_mux *gsm)
{ {
unsigned int base = mux_num_to_base(gsm); /* Base for this MUX */
int i; int i;
int base = gsm->num << 6; /* Base for this MUX */
WARN_ON(tty != gsm->tty); WARN_ON(tty != gsm->tty);
for (i = 1; i < NUM_DLCI; i++) for (i = 1; i < NUM_DLCI; i++)
...@@ -2908,7 +2919,7 @@ static int gsmtty_install(struct tty_driver *driver, struct tty_struct *tty) ...@@ -2908,7 +2919,7 @@ static int gsmtty_install(struct tty_driver *driver, struct tty_struct *tty)
struct gsm_mux *gsm; struct gsm_mux *gsm;
struct gsm_dlci *dlci; struct gsm_dlci *dlci;
unsigned int line = tty->index; unsigned int line = tty->index;
unsigned int mux = line >> 6; unsigned int mux = mux_line_to_num(line);
bool alloc = false; bool alloc = false;
int ret; int ret;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment