Commit 1848d7bb authored by Stephen Hemminger's avatar Stephen Hemminger Committed by Linus Torvalds

[PATCH] drivers/char/misc -- use list() macros

Use list macros for misc_device list.
parent 69014ca5
......@@ -53,7 +53,7 @@
/*
* Head entry for the doubly linked miscdevice list
*/
static struct miscdevice misc_list = { 0, "head", NULL, &misc_list, &misc_list };
static LIST_HEAD(misc_list);
static DECLARE_MUTEX(misc_sem);
/*
......@@ -80,7 +80,9 @@ static int misc_read_proc(char *buf, char **start, off_t offset,
int written;
written=0;
for (p = misc_list.next; p != &misc_list && written < len; p = p->next) {
list_for_each_entry(p, &misc_list, list) {
if (written >= len)
break;
written += sprintf(buf+written, "%3i %s\n",p->minor, p->name ?: "");
if (written < offset) {
offset -= written;
......@@ -97,7 +99,6 @@ static int misc_read_proc(char *buf, char **start, off_t offset,
return (written<0) ? 0 : written;
}
static int misc_open(struct inode * inode, struct file * file)
{
int minor = iminor(inode);
......@@ -107,20 +108,26 @@ static int misc_open(struct inode * inode, struct file * file)
down(&misc_sem);
c = misc_list.next;
while ((c != &misc_list) && (c->minor != minor))
c = c->next;
if (c != &misc_list)
list_for_each_entry(c, &misc_list, list) {
if (c->minor == minor) {
new_fops = fops_get(c->fops);
break;
}
}
if (!new_fops) {
up(&misc_sem);
request_module("char-major-%d-%d", MISC_MAJOR, minor);
down(&misc_sem);
c = misc_list.next;
while ((c != &misc_list) && (c->minor != minor))
c = c->next;
if (c == &misc_list || (new_fops = fops_get(c->fops)) == NULL)
list_for_each_entry(c, &misc_list, list) {
if (c->minor == minor) {
new_fops = fops_get(c->fops);
if (!new_fops)
goto fail;
break;
}
}
goto fail;
}
......@@ -166,17 +173,13 @@ int misc_register(struct miscdevice * misc)
{
struct miscdevice *c;
if (misc->next || misc->prev)
return -EBUSY;
down(&misc_sem);
c = misc_list.next;
while ((c != &misc_list) && (c->minor != misc->minor))
c = c->next;
if (c != &misc_list) {
list_for_each_entry(c, &misc_list, list) {
if (c->minor == misc->minor) {
up(&misc_sem);
return -EBUSY;
}
}
if (misc->minor == MISC_DYNAMIC_MINOR) {
int i = DYNAMIC_MINORS;
......@@ -205,10 +208,7 @@ int misc_register(struct miscdevice * misc)
* Add it to the front, so that later devices can "override"
* earlier defaults
*/
misc->prev = &misc_list;
misc->next = misc_list.next;
misc->prev->next = misc;
misc->next->prev = misc;
list_add(&misc->list, &misc_list);
up(&misc_sem);
return 0;
}
......@@ -226,13 +226,12 @@ int misc_register(struct miscdevice * misc)
int misc_deregister(struct miscdevice * misc)
{
int i = misc->minor;
if (!misc->next || !misc->prev)
if (list_empty(&misc->list))
return -EINVAL;
down(&misc_sem);
misc->prev->next = misc->next;
misc->next->prev = misc->prev;
misc->next = NULL;
misc->prev = NULL;
list_del(&misc->list);
devfs_remove(misc->devfs_name);
if (i < DYNAMIC_MINORS && i>0) {
misc_minors[i>>3] &= ~(1 << (misc->minor & 7));
......
......@@ -43,7 +43,7 @@ struct miscdevice
int minor;
const char *name;
struct file_operations *fops;
struct miscdevice * next, * prev;
struct list_head list;
char devfs_name[64];
};
......
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