linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Stephen Hemminger <shemminger@osdl.org>
To: Linus Torvalds <torvalds@osdl.org>, Andrew Morton <akpm@digeo.com>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] (1/2) drivers/char/misc -- use list() macros
Date: Wed, 17 Sep 2003 13:44:46 -0700	[thread overview]
Message-ID: <20030917134446.3ebcf234.shemminger@osdl.org> (raw)

Use list macros for misc_device list.
Patch against 2.6.0-test5 bk latest.

diff -Nru a/drivers/char/misc.c b/drivers/char/misc.c
--- a/drivers/char/misc.c	Wed Sep 17 13:43:05 2003
+++ b/drivers/char/misc.c	Wed Sep 17 13:43:05 2003
@@ -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 @@
 	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 @@
 	return (written<0) ? 0 : written;
 }
 
-
 static int misc_open(struct inode * inode, struct file * file)
 {
 	int minor = iminor(inode);
@@ -107,21 +108,27 @@
 	
 	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);
+	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)
-			goto fail;
+
+		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;
 	}
 
 	err = 0;
@@ -166,16 +173,12 @@
 {
 	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) {
-		up(&misc_sem);
-		return -EBUSY;
+	list_for_each_entry(c, &misc_list, list) {
+		if (c->minor == misc->minor) {
+			up(&misc_sem);
+			return -EBUSY;
+		}
 	}
 
 	if (misc->minor == MISC_DYNAMIC_MINOR) {
@@ -205,10 +208,7 @@
 	 * 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_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));
diff -Nru a/include/linux/miscdevice.h b/include/linux/miscdevice.h
--- a/include/linux/miscdevice.h	Wed Sep 17 13:43:05 2003
+++ b/include/linux/miscdevice.h	Wed Sep 17 13:43:05 2003
@@ -43,7 +43,7 @@
 	int minor;
 	const char *name;
 	struct file_operations *fops;
-	struct miscdevice * next, * prev;
+	struct list_head list;
 	char devfs_name[64];
 };
 

                 reply	other threads:[~2003-09-17 20:46 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030917134446.3ebcf234.shemminger@osdl.org \
    --to=shemminger@osdl.org \
    --cc=akpm@digeo.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@osdl.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).