Commit 43574c1a authored by Al Viro's avatar Al Viro Committed by Richard Weinberger

um: get rid of the init_prio mess

make line_setup() act on a separate array of conf strings + default conf,
have lines array initialized explicitly by that data, bury LINE_INIT()
macro from hell.
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
Signed-off-by: default avatarRichard Weinberger <richard@nod.at>
parent fe9a6b00
...@@ -489,7 +489,7 @@ void close_lines(struct line *lines, int nlines) ...@@ -489,7 +489,7 @@ void close_lines(struct line *lines, int nlines)
close_chan(&lines[i].chan_list, 0); close_chan(&lines[i].chan_list, 0);
} }
static int setup_one_line(struct line *lines, int n, char *init, int init_prio, static int setup_one_line(struct line *lines, int n, char *init,
char **error_out) char **error_out)
{ {
struct line *line = &lines[n]; struct line *line = &lines[n];
...@@ -502,14 +502,11 @@ static int setup_one_line(struct line *lines, int n, char *init, int init_prio, ...@@ -502,14 +502,11 @@ static int setup_one_line(struct line *lines, int n, char *init, int init_prio,
goto out; goto out;
} }
if (line->init_pri <= init_prio) { if (!strcmp(init, "none"))
line->init_pri = init_prio; line->valid = 0;
if (!strcmp(init, "none")) else {
line->valid = 0; line->init_str = init;
else { line->valid = 1;
line->init_str = init;
line->valid = 1;
}
} }
err = 0; err = 0;
out: out:
...@@ -524,47 +521,37 @@ static int setup_one_line(struct line *lines, int n, char *init, int init_prio, ...@@ -524,47 +521,37 @@ static int setup_one_line(struct line *lines, int n, char *init, int init_prio,
* @error_out is an error string in the case of failure; * @error_out is an error string in the case of failure;
*/ */
int line_setup(struct line *lines, unsigned int num, char *init, int line_setup(char **conf, unsigned int num, char **def,
char **error_out) char *init, char *name)
{ {
int i, n, err; char *error;
char *end;
if (*init == '=') { if (*init == '=') {
/* /*
* We said con=/ssl= instead of con#=, so we are configuring all * We said con=/ssl= instead of con#=, so we are configuring all
* consoles at once. * consoles at once.
*/ */
n = -1; *def = init + 1;
} } else {
else { char *end;
n = simple_strtoul(init, &end, 0); unsigned n = simple_strtoul(init, &end, 0);
if (*end != '=') { if (*end != '=') {
*error_out = "Couldn't parse device number"; error = "Couldn't parse device number";
return -EINVAL; goto out;
} }
init = end; if (n >= num) {
} error = "Device number out of range";
init++; goto out;
if (n >= (signed int) num) {
*error_out = "Device number out of range";
return -EINVAL;
}
else if (n >= 0) {
err = setup_one_line(lines, n, init, INIT_ONE, error_out);
if (err)
return err;
}
else {
for(i = 0; i < num; i++) {
err = setup_one_line(lines, i, init, INIT_ALL,
error_out);
if (err)
return err;
} }
conf[n] = end + 1;
} }
return n == -1 ? num : n; return 0;
out:
printk(KERN_ERR "Failed to set up %s with "
"configuration string \"%s\" : %s\n", name, init, error);
return -EINVAL;
} }
int line_config(struct line *lines, unsigned int num, char *str, int line_config(struct line *lines, unsigned int num, char *str,
...@@ -595,7 +582,7 @@ int line_config(struct line *lines, unsigned int num, char *str, ...@@ -595,7 +582,7 @@ int line_config(struct line *lines, unsigned int num, char *str,
*error_out = "Failed to allocate memory"; *error_out = "Failed to allocate memory";
return -ENOMEM; return -ENOMEM;
} }
err = setup_one_line(lines, n, new, INIT_ONE, error_out); err = setup_one_line(lines, n, new, error_out);
if (err) if (err)
return err; return err;
line = &lines[n]; line = &lines[n];
...@@ -654,7 +641,7 @@ int line_remove(struct line *lines, unsigned int num, int n, char **error_out) ...@@ -654,7 +641,7 @@ int line_remove(struct line *lines, unsigned int num, int n, char **error_out)
*error_out = "Device number out of range"; *error_out = "Device number out of range";
return -EINVAL; return -EINVAL;
} }
return setup_one_line(lines, n, "none", INIT_ONE, error_out); return setup_one_line(lines, n, "none", error_out);
} }
struct tty_driver *register_lines(struct line_driver *line_driver, struct tty_driver *register_lines(struct line_driver *line_driver,
......
...@@ -37,7 +37,6 @@ struct line { ...@@ -37,7 +37,6 @@ struct line {
int valid; int valid;
char *init_str; char *init_str;
int init_pri;
struct list_head chan_list; struct list_head chan_list;
/*This lock is actually, mostly, local to*/ /*This lock is actually, mostly, local to*/
...@@ -58,18 +57,10 @@ struct line { ...@@ -58,18 +57,10 @@ struct line {
int have_irq; int have_irq;
}; };
#define LINE_INIT(str, d) \
{ .count_lock = __SPIN_LOCK_UNLOCKED((str).count_lock), \
.init_str = str, \
.init_pri = INIT_STATIC, \
.valid = 1, \
.lock = __SPIN_LOCK_UNLOCKED((str).lock), \
.driver = d }
extern void line_close(struct tty_struct *tty, struct file * filp); extern void line_close(struct tty_struct *tty, struct file * filp);
extern int line_open(struct line *lines, struct tty_struct *tty); extern int line_open(struct line *lines, struct tty_struct *tty);
extern int line_setup(struct line *lines, unsigned int sizeof_lines, extern int line_setup(char **conf, unsigned nlines, char **def,
char *init, char **error_out); char *init, char *name);
extern int line_write(struct tty_struct *tty, const unsigned char *buf, extern int line_write(struct tty_struct *tty, const unsigned char *buf,
int len); int len);
extern int line_put_char(struct tty_struct *tty, unsigned char ch); extern int line_put_char(struct tty_struct *tty, unsigned char ch);
......
...@@ -71,8 +71,9 @@ static struct line_driver driver = { ...@@ -71,8 +71,9 @@ static struct line_driver driver = {
/* The array is initialized by line_init, at initcall time. The /* The array is initialized by line_init, at initcall time. The
* elements are locked individually as needed. * elements are locked individually as needed.
*/ */
static struct line serial_lines[NR_PORTS] = static char *conf[NR_PORTS];
{ [0 ... NR_PORTS - 1] = LINE_INIT(CONFIG_SSL_CHAN, &driver) }; static char *def_conf = CONFIG_SSL_CHAN;
static struct line serial_lines[NR_PORTS];
static int ssl_config(char *str, char **error_out) static int ssl_config(char *str, char **error_out)
{ {
...@@ -186,9 +187,23 @@ static struct console ssl_cons = { ...@@ -186,9 +187,23 @@ static struct console ssl_cons = {
static int ssl_init(void) static int ssl_init(void)
{ {
char *new_title; char *new_title;
int i;
printk(KERN_INFO "Initializing software serial port version %d\n", printk(KERN_INFO "Initializing software serial port version %d\n",
ssl_version); ssl_version);
for (i = 0; i < NR_PORTS; i++) {
char *s = conf[i];
if (!s)
s = def_conf;
if (s && strcmp(s, "none") != 0) {
serial_lines[i].init_str = s;
serial_lines[i].valid = 1;
}
spin_lock_init(&serial_lines[i].lock);
spin_lock_init(&serial_lines[i].count_lock);
serial_lines[i].driver = &driver;
}
ssl_driver = register_lines(&driver, &ssl_ops, serial_lines, ssl_driver = register_lines(&driver, &ssl_ops, serial_lines,
ARRAY_SIZE(serial_lines)); ARRAY_SIZE(serial_lines));
...@@ -214,14 +229,7 @@ __uml_exitcall(ssl_exit); ...@@ -214,14 +229,7 @@ __uml_exitcall(ssl_exit);
static int ssl_chan_setup(char *str) static int ssl_chan_setup(char *str)
{ {
char *error; line_setup(conf, NR_PORTS, &def_conf, str, "serial line");
int ret;
ret = line_setup(serial_lines, ARRAY_SIZE(serial_lines), str, &error);
if(ret < 0)
printk(KERN_ERR "Failed to set up serial line with "
"configuration string \"%s\" : %s\n", str, error);
return 1; return 1;
} }
......
...@@ -76,9 +76,9 @@ static struct line_driver driver = { ...@@ -76,9 +76,9 @@ static struct line_driver driver = {
/* The array is initialized by line_init, at initcall time. The /* The array is initialized by line_init, at initcall time. The
* elements are locked individually as needed. * elements are locked individually as needed.
*/ */
static struct line vts[MAX_TTYS] = { LINE_INIT(CONFIG_CON_ZERO_CHAN, &driver), static char *vt_conf[MAX_TTYS];
[ 1 ... MAX_TTYS - 1 ] = static char *def_conf;
LINE_INIT(CONFIG_CON_CHAN, &driver) }; static struct line vts[MAX_TTYS];
static int con_config(char *str, char **error_out) static int con_config(char *str, char **error_out)
{ {
...@@ -160,7 +160,22 @@ static struct console stdiocons = { ...@@ -160,7 +160,22 @@ static struct console stdiocons = {
static int stdio_init(void) static int stdio_init(void)
{ {
char *new_title; char *new_title;
int i;
for (i = 0; i < MAX_TTYS; i++) {
char *s = vt_conf[i];
if (!s)
s = def_conf;
if (!s)
s = i ? CONFIG_CON_CHAN : CONFIG_CON_ZERO_CHAN;
if (s && strcmp(s, "none") != 0) {
vts[i].init_str = s;
vts[i].valid = 1;
}
spin_lock_init(&vts[i].lock);
spin_lock_init(&vts[i].count_lock);
vts[i].driver = &driver;
}
console_driver = register_lines(&driver, &console_ops, vts, console_driver = register_lines(&driver, &console_ops, vts,
ARRAY_SIZE(vts)); ARRAY_SIZE(vts));
if (console_driver == NULL) if (console_driver == NULL)
...@@ -189,14 +204,7 @@ __uml_exitcall(console_exit); ...@@ -189,14 +204,7 @@ __uml_exitcall(console_exit);
static int console_chan_setup(char *str) static int console_chan_setup(char *str)
{ {
char *error; line_setup(vt_conf, MAX_TTYS, &def_conf, str, "console");
int ret;
ret = line_setup(vts, ARRAY_SIZE(vts), str, &error);
if(ret < 0)
printk(KERN_ERR "Failed to set up console with "
"configuration string \"%s\" : %s\n", str, error);
return 1; return 1;
} }
__setup("con", console_chan_setup); __setup("con", console_chan_setup);
......
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