Commit 7807eb6a authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] Fix tty devfs mess

From: Christoph Hellwig <hch@lst.de>

Currently the tty code abuses tty_driver.name as the prefix for the devfs
names of the ttys.  This is a very bad idea because it means the tty name
changes depending on whether devfs is enabled or not, leading to different
names in /proc/tty/ depending on whether we have devfs or not (and not
whether it actually is mounted!) and a huge amount of ifdefs.

The patch below adds a .devfs_name member instead, similar to the block
device changes a few weeks ago.
parent 9c481bc0
......@@ -2549,11 +2549,8 @@ static int __init rs_init(void)
memset(&serial_driver, 0, sizeof(struct tty_driver));
serial_driver.magic = TTY_DRIVER_MAGIC;
serial_driver.driver_name = "serial";
#if (LINUX_VERSION_CODE > 0x2032D && defined(CONFIG_DEVFS_FS))
serial_driver.name = "tts/";
#else
serial_driver.devfs_name = "tts/";
serial_driver.name = "ttyS";
#endif
serial_driver.major = TTY_MAJOR;
serial_driver.minor_start = 64 + SERIAL_DEV_OFFSET;
serial_driver.num = NR_PORTS;
......
......@@ -2467,11 +2467,8 @@ int __init rs_8xx_init(void)
__clear_user(&serial_driver,sizeof(struct tty_driver));
serial_driver.magic = TTY_DRIVER_MAGIC;
serial_driver.driver_name = "serial";
#ifdef CONFIG_DEVFS_FS
serial_driver.name = "tts/";
#else
serial_driver.devfs_name = "tts/";
serial_driver.name = "ttyS";
#endif
serial_driver.major = TTY_MAJOR;
serial_driver.minor_start = 64;
serial_driver.num = NR_PORTS;
......
......@@ -2520,11 +2520,8 @@ int __init rs_8xx_init(void)
__clear_user(&serial_driver,sizeof(struct tty_driver));
serial_driver.magic = TTY_DRIVER_MAGIC;
serial_driver.driver_name = "serial";
#ifdef CONFIG_DEVFS_FS
serial_driver.name = "tts/";
#else
serial_driver.devfs_name = "tts/";
serial_driver.name = "ttyS";
#endif
serial_driver.major = TTY_MAJOR;
serial_driver.minor_start = 64;
serial_driver.num = NR_PORTS;
......
......@@ -1295,11 +1295,8 @@ int __init dz_init(void)
memset(&serial_driver, 0, sizeof(struct tty_driver));
serial_driver.magic = TTY_DRIVER_MAGIC;
serial_driver.owner = THIS_MODULE;
#if (LINUX_VERSION_CODE > 0x2032D && defined(CONFIG_DEVFS_FS))
serial_driver.devfs_name = "tts/";
serial_driver.name = "ttyS";
#else
serial_driver.name = "tts/";
#endif
serial_driver.major = TTY_MAJOR;
serial_driver.minor_start = 64;
serial_driver.num = DZ_NB_PORT;
......
......@@ -94,9 +94,7 @@
#include <linux/module.h>
#include <linux/signal.h>
#include <linux/sched.h>
#ifdef CONFIG_DEVFS_FS
#include <linux/devfs_fs_kernel.h>
#endif
#include <linux/timer.h>
#include <linux/interrupt.h>
#include <linux/pci.h>
......@@ -229,11 +227,6 @@ static char *pcVersion = "1.2.14";
/* String constants for port names */
static char *pcDriver_name = "ip2";
#ifdef CONFIG_DEVFS_FS
static char *pcTty = "tts/F%d";
#else
static char *pcTty = "ttyF";
#endif
static char *pcIpl = "ip2ipl";
/* Serial subtype definitions */
......@@ -564,10 +557,7 @@ cleanup_module(void)
int
ip2_loadmain(int *iop, int *irqp, unsigned char *firmware, int firmsize)
{
#ifdef CONFIG_DEVFS_FS
int j, box;
#endif
int i;
int i, j, box;
int err;
int status = 0;
static int loaded;
......@@ -786,7 +776,8 @@ ip2_loadmain(int *iop, int *irqp, unsigned char *firmware, int firmsize)
/* Initialise the relevant fields. */
ip2_tty_driver.magic = TTY_DRIVER_MAGIC;
ip2_tty_driver.owner = THIS_MODULE;
ip2_tty_driver.name = pcTty;
ip2_tty_driver.name = "ttyF";
ip2_tty_driver.devfs_name = "tts/F";
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,1,0)
ip2_tty_driver.driver_name = pcDriver_name;
ip2_tty_driver.read_proc = ip2_read_proc;
......@@ -798,11 +789,7 @@ ip2_loadmain(int *iop, int *irqp, unsigned char *firmware, int firmsize)
ip2_tty_driver.subtype = SERIAL_TYPE_NORMAL;
ip2_tty_driver.init_termios = tty_std_termios;
ip2_tty_driver.init_termios.c_cflag = B9600|CS8|CREAD|HUPCL|CLOCAL;
#ifdef CONFIG_DEVFS_FS
ip2_tty_driver.flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_NO_DEVFS;
#else
ip2_tty_driver.flags = TTY_DRIVER_REAL_RAW;
#endif
ip2_tty_driver.refcount = &ref_count;
ip2_tty_driver.table = TtyTable;
ip2_tty_driver.termios = Termios;
......@@ -851,7 +838,6 @@ ip2_loadmain(int *iop, int *irqp, unsigned char *firmware, int firmsize)
continue;
}
#ifdef CONFIG_DEVFS_FS
if ( NULL != ( pB = i2BoardPtrTable[i] ) ) {
devfs_mk_cdev(MKDEV(IP2_IPL_MAJOR, 4 * i),
S_IRUSR | S_IWUSR | S_IRGRP | S_IFCHR,
......@@ -874,7 +860,6 @@ ip2_loadmain(int *iop, int *irqp, unsigned char *firmware, int firmsize)
}
}
}
#endif
if (poll_only) {
// Poll only forces driver to only use polling and
......
......@@ -347,11 +347,8 @@ int __init pty_init(void)
pty_driver.magic = TTY_DRIVER_MAGIC;
pty_driver.owner = THIS_MODULE;
pty_driver.driver_name = "pty_master";
#ifdef CONFIG_DEVFS_FS
pty_driver.name = "pty/m";
#else
pty_driver.name = "pty";
#endif
pty_driver.devfs_name = "pty/m";
pty_driver.major = PTY_MASTER_MAJOR;
pty_driver.minor_start = 0;
pty_driver.num = NR_PTYS;
......@@ -382,11 +379,8 @@ int __init pty_init(void)
pty_slave_driver = pty_driver;
pty_slave_driver.driver_name = "pty_slave";
pty_slave_driver.proc_entry = 0;
#ifdef CONFIG_DEVFS_FS
pty_slave_driver.name = "pty/s";
#else
pty_slave_driver.name = "ttyp";
#endif
pty_slave_driver.devfs_name = "pty/s";
pty_slave_driver.subtype = PTY_TYPE_SLAVE;
pty_slave_driver.major = PTY_SLAVE_MAJOR;
pty_slave_driver.minor_start = 0;
......
......@@ -2650,6 +2650,7 @@ int __init rp_init(void)
memset(&rocket_driver, 0, sizeof (struct tty_driver));
rocket_driver.magic = TTY_DRIVER_MAGIC;
rocket_driver.flags = TTY_DRIVER_NO_DEVFS;
rocket_driver.devfs_name = "tts/R";
rocket_driver.name = "ttyR";
rocket_driver.driver_name = "Comtrol RocketPort";
rocket_driver.major = TTY_ROCKET_MAJOR;
......
......@@ -2359,11 +2359,8 @@ scrn[1] = '\0';
memset(&cy_serial_driver, 0, sizeof(struct tty_driver));
cy_serial_driver.magic = TTY_DRIVER_MAGIC;
cy_serial_driver.owner = THIS_MODULE;
#ifdef CONFIG_DEVFS_FS
cy_serial_driver.name = "tts/";
#else
cy_serial_driver.devfs_name = "tts/";
cy_serial_driver.name = "ttyS";
#endif
cy_serial_driver.major = TTY_MAJOR;
cy_serial_driver.minor_start = 64;
cy_serial_driver.num = NR_PORTS;
......
......@@ -994,11 +994,8 @@ static int sci_init_drivers(void)
sci_driver.magic = TTY_DRIVER_MAGIC;
sci_driver.owner = THIS_MODULE;
sci_driver.driver_name = "sci";
#ifdef CONFIG_DEVFS_FS
sci_driver.name = "ttsc/";
#else
sci_driver.name = "ttySC";
#endif
sci_driver.devfs_name = "ttsc/";
sci_driver.major = SCI_MAJOR;
sci_driver.minor_start = SCI_MINOR_START;
sci_driver.num = SCI_NPORTS;
......
......@@ -136,11 +136,6 @@ static int stl_nrbrds = sizeof(stl_brdconf) / sizeof(stlconf_t);
static char *stl_drvtitle = "Stallion Multiport Serial Driver";
static char *stl_drvname = "stallion";
static char *stl_drvversion = "5.6.0";
#ifdef CONFIG_DEVFS_FS
static char *stl_serialname = "tts/E%d";
#else
static char *stl_serialname = "ttyE";
#endif
static struct tty_driver stl_serial;
static struct tty_struct *stl_ttys[STL_MAXDEVS];
......@@ -3178,7 +3173,8 @@ int __init stl_init(void)
stl_serial.magic = TTY_DRIVER_MAGIC;
stl_serial.owner = THIS_MODULE;
stl_serial.driver_name = stl_drvname;
stl_serial.name = stl_serialname;
stl_serial.name = "ttyE";
stl_serial.devfs_name = "tts/E";
stl_serial.major = STL_SERIALMAJOR;
stl_serial.minor_start = 0;
stl_serial.num = STL_MAXBRDS * STL_MAXPORTS;
......
......@@ -2082,17 +2082,6 @@ static void tty_default_put_char(struct tty_struct *tty, unsigned char ch)
tty->driver->write(tty, 0, &ch, 1);
}
#ifdef CONFIG_DEVFS_FS
static void tty_unregister_devfs(struct tty_driver *driver, int index)
{
char path[64];
tty_line_name(driver, index, path);
devfs_remove(path);
}
#else
# define tty_unregister_devfs(driver, index) do { } while (0)
#endif /* CONFIG_DEVFS_FS */
struct tty_dev {
struct list_head node;
dev_t dev;
......@@ -2124,7 +2113,6 @@ static CLASS_DEVICE_ATTR(dev, S_IRUGO, show_dev, NULL);
static void tty_add_class_device(char *name, dev_t dev, struct device *device)
{
struct tty_dev *tty_dev = NULL;
char *temp;
int retval;
tty_dev = kmalloc(sizeof(*tty_dev), GFP_KERNEL);
......@@ -2132,16 +2120,9 @@ static void tty_add_class_device(char *name, dev_t dev, struct device *device)
return;
memset(tty_dev, 0x00, sizeof(*tty_dev));
/* stupid '/' in tty name strings... */
temp = strrchr(name, '/');
if (temp && (temp[1] != 0x00))
++temp;
else
temp = name;
tty_dev->class_dev.dev = device;
tty_dev->class_dev.class = &tty_class;
snprintf(tty_dev->class_dev.class_id, BUS_ID_SIZE, "%s", temp);
snprintf(tty_dev->class_dev.class_id, BUS_ID_SIZE, "%s", name);
retval = class_device_register(&tty_dev->class_dev);
if (retval)
goto error;
......@@ -2195,7 +2176,6 @@ void tty_register_device(struct tty_driver *driver, unsigned index,
struct device *device)
{
dev_t dev = MKDEV(driver->major, driver->minor_start) + index;
char name[64];
if (index >= driver->num) {
printk(KERN_ERR "Attempt to register invalid tty line number "
......@@ -2203,16 +2183,16 @@ void tty_register_device(struct tty_driver *driver, unsigned index,
return;
}
tty_line_name(driver, index, name);
devfs_mk_cdev(dev, S_IFCHR | S_IRUSR | S_IWUSR, name);
/* stupid console driver devfs names... change vc/X into ttyX */
if (driver->type == TTY_DRIVER_TYPE_CONSOLE)
sprintf(name, "tty%d", MINOR(dev));
devfs_mk_cdev(dev, S_IFCHR | S_IRUSR | S_IWUSR,
"%s%d", driver->devfs_name, index + driver->name_base);
/* we don't care about the ptys */
if (driver->type != TTY_DRIVER_TYPE_PTY)
tty_add_class_device (name, dev, device);
/* how nice to hide this behind some crappy interface.. */
if (driver->type != TTY_DRIVER_TYPE_PTY) {
char name[64];
tty_line_name(driver, index, name);
tty_add_class_device(name, dev, device);
}
}
/**
......@@ -2225,7 +2205,7 @@ void tty_register_device(struct tty_driver *driver, unsigned index,
*/
void tty_unregister_device(struct tty_driver *driver, unsigned index)
{
tty_unregister_devfs(driver, index);
devfs_remove("%s%d", driver->devfs_name, index + driver->name_base);
tty_remove_class_device(MKDEV(driver->major, driver->minor_start) + index);
}
......
......@@ -131,11 +131,8 @@ static int scc_init_drivers(void)
scc_driver.magic = TTY_DRIVER_MAGIC;
scc_driver.owner = THIS_MODULE;
scc_driver.driver_name = "scc";
#ifdef CONFIG_DEVFS_FS
scc_driver.name = "tts/";
#else
scc_driver.name = "ttyS";
#endif
scc_driver.devfs_name = "tts/";
scc_driver.major = TTY_MAJOR;
scc_driver.minor_start = SCC_MINOR_BASE;
scc_driver.num = 2;
......
......@@ -2531,7 +2531,8 @@ int __init vty_init(void)
memset(&console_driver, 0, sizeof(struct tty_driver));
console_driver.magic = TTY_DRIVER_MAGIC;
console_driver.owner = THIS_MODULE;
console_driver.name = "vc/";
console_driver.devfs_name = "vc/";
console_driver.name = "tty";
console_driver.name_base = 1;
console_driver.major = TTY_MAJOR;
console_driver.minor_start = 1;
......
......@@ -62,12 +62,6 @@ isdn_tty_event_callback(struct isdn_slot *slot, int pr, void *arg)
#define MODEM_PARANOIA_CHECK
#define MODEM_DO_RESTART
#ifdef CONFIG_DEVFS_FS
static char *isdn_ttyname_ttyI = "isdn/ttyI%d";
#else
static char *isdn_ttyname_ttyI = "ttyI";
#endif
struct isdn_modem isdn_mdm;
static int bit2si[8] =
......@@ -2013,7 +2007,8 @@ isdn_tty_init(void)
m = &isdn_mdm;
memset(&m->tty_modem, 0, sizeof(struct tty_driver));
m->tty_modem.magic = TTY_DRIVER_MAGIC;
m->tty_modem.name = isdn_ttyname_ttyI;
m->tty_modem.name = "ttyI";
m->tty_modem.devfs_name = "isdn/ttyI";
m->tty_modem.major = ISDN_TTY_MAJOR;
m->tty_modem.minor_start = 0;
m->tty_modem.num = ISDN_MAX_CHANNELS;
......
......@@ -2568,11 +2568,8 @@ int macserial_init(void)
serial_driver.magic = TTY_DRIVER_MAGIC;
serial_driver.owner = THIS_MODULE;
serial_driver.driver_name = "macserial";
#ifdef CONFIG_DEVFS_FS
serial_driver.name = "tts/";
#else
serial_driver.devfs_name = "tts/";
serial_driver.name = "ttyS";
#endif /* CONFIG_DEVFS_FS */
serial_driver.major = TTY_MAJOR;
serial_driver.minor_start = 64;
serial_driver.num = zs_channels_found;
......
......@@ -28,9 +28,7 @@
#include <linux/serial_reg.h>
#include <linux/interrupt.h>
#include <asm/uaccess.h>
#ifdef CONFIG_DEVFS_FS
# include <linux/devfs_fs_kernel.h>
#endif
#include <linux/devfs_fs_kernel.h>
#include "ctctty.h"
#define CTC_TTY_MAJOR 43
......@@ -89,12 +87,6 @@ static ctc_tty_driver *driver;
#define CTC_TTY_NAME "ctctty"
#ifdef CONFIG_DEVFS_FS
static char *ctc_ttyname = "ctc/" CTC_TTY_NAME "%d";
#else
static char *ctc_ttyname = CTC_TTY_NAME;
#endif
static __u32 ctc_tty_magic = CTC_ASYNC_MAGIC;
static int ctc_tty_shuttingdown = 0;
......@@ -1170,7 +1162,8 @@ ctc_tty_init(void)
device = &driver->ctc_tty_device;
device->magic = TTY_DRIVER_MAGIC;
device->name = ctc_ttyname;
device->devfs_name = "ctc/" CTC_TTY_NAME;
device->name = CTC_TTY_NAME;
device->major = CTC_TTY_MAJOR;
device->minor_start = 0;
device->num = CTC_TTY_MAX_DEVICES;
......
......@@ -1999,11 +1999,8 @@ console_initcall(serial8250_console_init);
static struct uart_driver serial8250_reg = {
.owner = THIS_MODULE,
.driver_name = "serial",
#ifdef CONFIG_DEVFS_FS
.dev_name = "tts/",
#else
.devfs_name = "tts/",
.dev_name = "ttyS",
#endif
.major = TTY_MAJOR,
.minor = 64,
.nr = UART_NR,
......
......@@ -2115,6 +2115,7 @@ int uart_register_driver(struct uart_driver *drv)
normal->magic = TTY_DRIVER_MAGIC;
normal->owner = drv->owner;
normal->driver_name = drv->driver_name;
normal->devfs_name = drv->devfs_name;
normal->name = drv->dev_name;
normal->major = drv->major;
normal->minor_start = drv->minor;
......
......@@ -524,11 +524,8 @@ static struct uart_ops nb85e_uart_ops = {
static struct uart_driver nb85e_uart_driver = {
.owner = THIS_MODULE,
.driver_name = "nb85e_uart",
#ifdef CONFIG_DEVFS_FS
.dev_name = "tts/",
#else
.devfs_name = "tts/",
.dev_name = "ttyS",
#endif
.major = TTY_MAJOR,
.minor = NB85E_UART_MINOR_BASE,
.nr = NB85E_UART_NUM_CHANNELS,
......
......@@ -830,11 +830,8 @@ static struct uart_ops sunsab_pops = {
static struct uart_driver sunsab_reg = {
.owner = THIS_MODULE,
.driver_name = "serial",
#ifdef CONFIG_DEVFS_FS
.dev_name = "tts/",
#else
.devfs_name = "tts/",
.dev_name = "ttyS",
#endif
.major = TTY_MAJOR,
};
......
......@@ -1285,11 +1285,8 @@ static void sunsu_autoconfig(struct uart_sunsu_port *up)
static struct uart_driver sunsu_reg = {
.owner = THIS_MODULE,
.driver_name = "serial",
#ifdef CONFIG_DEVFS_FS
.dev_name = "tts/",
#else
.devfs_name = "tts/",
.dev_name = "ttyS",
#endif
.major = TTY_MAJOR,
};
......
......@@ -1030,11 +1030,8 @@ static int zilog_irq = -1;
static struct uart_driver sunzilog_reg = {
.owner = THIS_MODULE,
.driver_name = "ttyS",
#ifdef CONFIG_DEVFS_FS
.dev_name = "tts/",
#else
.devfs_name = "tts/",
.dev_name = "ttyS",
#endif
.major = TTY_MAJOR,
};
......
......@@ -1840,11 +1840,8 @@ int __init zs_init(void)
memset(&serial_driver, 0, sizeof(struct tty_driver));
serial_driver.magic = TTY_DRIVER_MAGIC;
serial_driver.owner = THIS_MODULE;
#if (LINUX_VERSION_CODE > 0x2032D && defined(CONFIG_DEVFS_FS))
serial_driver.name = "tts/";
#else
serial_driver.devfs_name = "tts/";
serial_driver.name = "ttyS";
#endif
serial_driver.major = TTY_MAJOR;
serial_driver.minor_start = 64;
serial_driver.num = zs_channels_found;
......
......@@ -1304,11 +1304,8 @@ struct tty_driver usb_serial_tty_driver = {
.magic = TTY_DRIVER_MAGIC,
.owner = THIS_MODULE,
.driver_name = "usbserial",
#ifndef CONFIG_DEVFS_FS
.devfs_name = "usb/tts/",
.name = "ttyUSB",
#else
.name = "usb/tts/",
#endif
.major = SERIAL_TTY_MAJOR,
.minor_start = 0,
.num = SERIAL_TTY_MINORS,
......
......@@ -266,6 +266,7 @@ struct uart_driver {
struct module *owner;
const char *driver_name;
const char *dev_name;
const char *devfs_name;
int major;
int minor;
int nr;
......
......@@ -124,6 +124,7 @@ struct tty_driver {
struct cdev cdev;
struct module *owner;
const char *driver_name;
const char *devfs_name;
const char *name;
int name_base; /* offset of printed name */
short major; /* major device number */
......
......@@ -863,11 +863,8 @@ static struct tty_driver rfcomm_tty_driver = {
.magic = TTY_DRIVER_MAGIC,
.driver_name = "rfcomm",
#ifdef CONFIG_DEVFS_FS
.name = "bluetooth/rfcomm/",
#else
.devfs_name = "bluetooth/rfcomm/",
.name = "rfcomm",
#endif
.major = RFCOMM_TTY_MAJOR,
.minor_start = RFCOMM_TTY_MINOR,
.num = RFCOMM_TTY_PORTS,
......
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