Re: [PATCH 28/49] tty: Add a new file /proc/tty/consoles

From: Jiri Slaby
Date: Sat Oct 23 2010 - 07:24:58 EST


On 10/22/2010 08:21 PM, Greg Kroah-Hartman wrote:
> --- a/fs/proc/proc_tty.c
> +++ b/fs/proc/proc_tty.c
...
> @@ -137,6 +140,160 @@ static const struct file_operations proc_tty_drivers_operations = {
> };
>
> /*
> + * The device ID of file descriptor 0 of the current reading
> + * task if a character device...
> + */
> +static dev_t current_dev;
> +
> +/*
> + * This is the handler for /proc/tty/consoles
> + */
> +static int show_console_dev(struct seq_file *m, void *v)
> +{
> + const struct tty_driver *driver;
> + struct console *con;
> + int index, len;
> + char flags[10];
> + dev_t dev;
> +
> + if (v == SEQ_START_TOKEN)
> + return 0;
> + con = (struct console *)v;

You don't hold the console sem now, so the console may be already gone,
right? You should hold the sem from ->start till ->stop.

> + if (!con)
> + return 0;
> + driver = con->device(con, &index);

Some consoles, especially the early ones don't have con->device IIRC.
If, for some reason, they are not switched to proper ttyS* (e.g. the
port fails to init), this will crash.

> + if (!driver)
> + return 0;
> + dev = MKDEV(driver->major, driver->minor_start) + index;
> +
> + index = 0;
> + if (con->flags & CON_ENABLED)
> + flags[index++] = 'E';
> + if (con->flags & CON_CONSDEV)
> + flags[index++] = 'C';
> + if (con->flags & CON_BOOT)
> + flags[index++] = 'B';
> + if (con->flags & CON_PRINTBUFFER)
> + flags[index++] = 'p';
> + if (con->flags & CON_BRL)
> + flags[index++] = 'b';
> + if (con->flags & CON_ANYTIME)
> + flags[index++] = 'a';
> + if (current_dev == dev)
> + flags[index++] = '*';
> + flags[index] = 0;
> +
> + seq_printf(m, "%s%d%n", con->name, con->index, &len);
> + len = 21 - len;
> + if (len < 1)
> + len = 1;
> + seq_printf(m, "%*c", len, ' ');
> + seq_printf(m, "%c%c%c (%s)%n", con->read ? 'R' : '-',
> + con->write ? 'W' : '-', con->unblank ? 'U' : '-',
> + flags, &len);
> + len = 13 - len;
> + if (len < 1)
> + len = 1;
> + seq_printf(m, "%*c%4d:%d\n", len, ' ', MAJOR(dev), MINOR(dev));
> +
> + return 0;
> +}

regards,
--
js
suse labs
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/