Commit 864c2acd authored by Andrew Morton's avatar Andrew Morton Committed by Dave Jones

[PATCH] tty_io cleanup

From: Andries.Brouwer@cwi.nl

Adding the unregister_chrdev_region call that is the counterpart to
register_chrdev_region, we get a nice cleanup of tty_io.c.
parent 9110cac9
...@@ -2143,31 +2143,16 @@ int tty_register_driver(struct tty_driver *driver) ...@@ -2143,31 +2143,16 @@ int tty_register_driver(struct tty_driver *driver)
*/ */
int tty_unregister_driver(struct tty_driver *driver) int tty_unregister_driver(struct tty_driver *driver)
{ {
int retval; int retval, i;
struct tty_driver *p;
int i, found = 0;
struct termios *tp; struct termios *tp;
const char *othername = NULL;
if (*driver->refcount) if (*driver->refcount)
return -EBUSY; return -EBUSY;
list_for_each_entry(p, &tty_drivers, tty_drivers) { retval = unregister_chrdev_region(driver->major, driver->minor_start,
if (p == driver) driver->num, driver->name);
found++;
else if (p->major == driver->major)
othername = p->name;
}
if (!found)
return -ENOENT;
if (othername == NULL) {
retval = unregister_chrdev(driver->major, driver->name);
if (retval) if (retval)
return retval; return retval;
} else
register_chrdev(driver->major, othername, &tty_fops);
list_del(&driver->tty_drivers); list_del(&driver->tty_drivers);
......
...@@ -174,7 +174,8 @@ int register_chrdev(unsigned int major, const char *name, ...@@ -174,7 +174,8 @@ int register_chrdev(unsigned int major, const char *name,
} }
/* todo: make void - error printk here */ /* todo: make void - error printk here */
int unregister_chrdev(unsigned int major, const char * name) int unregister_chrdev_region(unsigned int major, unsigned int baseminor,
int minorct, const char *name)
{ {
struct char_device_struct *cd, **cp; struct char_device_struct *cd, **cp;
int ret = 0; int ret = 0;
...@@ -184,7 +185,9 @@ int unregister_chrdev(unsigned int major, const char * name) ...@@ -184,7 +185,9 @@ int unregister_chrdev(unsigned int major, const char * name)
write_lock(&chrdevs_lock); write_lock(&chrdevs_lock);
for (cp = &chrdevs[i]; *cp; cp = &(*cp)->next) for (cp = &chrdevs[i]; *cp; cp = &(*cp)->next)
if ((*cp)->major == major) if ((*cp)->major == major &&
(*cp)->baseminor == baseminor &&
(*cp)->minorct == minorct)
break; break;
if (!*cp || strcmp((*cp)->name, name)) if (!*cp || strcmp((*cp)->name, name))
ret = -EINVAL; ret = -EINVAL;
...@@ -198,6 +201,11 @@ int unregister_chrdev(unsigned int major, const char * name) ...@@ -198,6 +201,11 @@ int unregister_chrdev(unsigned int major, const char * name)
return ret; return ret;
} }
int unregister_chrdev(unsigned int major, const char *name)
{
return unregister_chrdev_region(major, 0, 256, name);
}
/* /*
* Called every time a character special file is opened * Called every time a character special file is opened
*/ */
......
...@@ -1060,6 +1060,8 @@ extern int register_chrdev_region(unsigned int, unsigned int, int, ...@@ -1060,6 +1060,8 @@ extern int register_chrdev_region(unsigned int, unsigned int, int,
extern int register_chrdev(unsigned int, const char *, extern int register_chrdev(unsigned int, const char *,
struct file_operations *); struct file_operations *);
extern int unregister_chrdev(unsigned int, const char *); extern int unregister_chrdev(unsigned int, const char *);
extern int unregister_chrdev_region(unsigned int, unsigned int, int,
const char *);
extern int chrdev_open(struct inode *, struct file *); extern int chrdev_open(struct inode *, struct file *);
/* fs/block_dev.c */ /* fs/block_dev.c */
......
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