linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] Prevent sysfs-related oops in pcmcia class code
@ 2003-06-15 17:08 Russell King
  0 siblings, 0 replies; only message in thread
From: Russell King @ 2003-06-15 17:08 UTC (permalink / raw)
  To: Linux Kernel List; +Cc: Dominik Brodowski, linux-pcmcia

Although no such oops has been reported, removing a socket driver
while a file under /sysfs/class/pcmcia_socket/pcmcia_socket* is
held open by user space could potentially cause an oops.

Plug this by preventing pcmcia_unregister_socket from returning
until all references by sysfs to the pcmcia socket have been
dropped.

This patch is against my current bk tree, so will apply with offsets
to 2.5.71.

diff -Nru a/drivers/pcmcia/cs.c b/drivers/pcmcia/cs.c
--- a/drivers/pcmcia/cs.c	Sun Jun 15 18:05:06 2003
+++ b/drivers/pcmcia/cs.c	Sun Jun 15 18:05:06 2003
@@ -387,6 +387,12 @@
 	socket->ss_entry = NULL;
 }
 
+static void pcmcia_release_socket(struct class_device *class_dev)
+{
+	struct pcmcia_socket *socket = class_get_devdata(class_dev);
+	complete(&socket->socket_released);
+}
+
 
 /**
  * pcmcia_register_socket - add a new pcmcia socket device
@@ -450,6 +456,8 @@
 
 	DEBUG(0, "cs: pcmcia_unregister_socket(0x%p)\n", socket->ss_entry);
 
+	init_completion(&socket->socket_released);
+
 	/* remove from the device core */
 	class_device_unregister(&socket->dev);
 
@@ -457,6 +465,9 @@
 	down_write(&pcmcia_socket_list_rwsem);
 	list_del(&socket->socket_list);
 	up_write(&pcmcia_socket_list_rwsem);
+
+	/* wait for sysfs to drop all references */
+	wait_for_completion(&socket->socket_released);
 } /* pcmcia_unregister_socket */
 EXPORT_SYMBOL(pcmcia_unregister_socket);
 
@@ -2496,6 +2507,7 @@
 
 struct class pcmcia_socket_class = {
 	.name = "pcmcia_socket",
+	.release = pcmcia_release_socket,
 };
 EXPORT_SYMBOL(pcmcia_socket_class);
 
diff -Nru a/include/pcmcia/ss.h b/include/pcmcia/ss.h
--- a/include/pcmcia/ss.h	Sun Jun 15 18:05:06 2003
+++ b/include/pcmcia/ss.h	Sun Jun 15 18:05:06 2003
@@ -193,6 +193,7 @@
 	char				*fake_cis;
 
 	struct list_head		socket_list;
+	struct completion		socket_released;
 
  	/* deprecated */
 	unsigned int			sock;		/* socket number */

-- 
Russell King (rmk@arm.linux.org.uk)                The developer of ARM Linux
             http://www.arm.linux.org.uk/personal/aboutme.html


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-06-15 16:54 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-06-15 17:08 [PATCH] Prevent sysfs-related oops in pcmcia class code Russell King

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).