[PATCH] sysfs: reinstate exclusion between method calls and attribute unregistration
authorAlan Stern <stern@rowland.harvard.edu>
Thu, 15 Mar 2007 19:51:28 +0000 (15:51 -0400)
committerLinus Torvalds <torvalds@woody.linux-foundation.org>
Thu, 15 Mar 2007 22:29:26 +0000 (15:29 -0700)
This patch (as869) reinstates the mutual exclusion between sysfs
attribute method calls and attribute unregistration.  The
previously-reported deadlocks have been fixed, and this exclusion is
by far the simplest way to avoid races during driver unbinding.

The check for orphaned read-buffers has been moved down slightly, so
that the remainder of a partially-read buffer will still be available
to userspace even after the attribute has been unregistered.

Signed-off-by: Alan Stern <stern@rowland.harvard.edu>
Cc: Hugh Dickins <hugh@veritas.com>
Cc: Cornelia Huck <cornelia.huck@de.ibm.com>
Cc: Oliver Neukum <oneukum@suse.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
fs/sysfs/file.c
fs/sysfs/inode.c

index 1bafdf6e171cb5c73d9c0650368b2ad8795684e6..fc4633378dc05e064e8d207babaebe2a917e2b78 100644 (file)
@@ -168,12 +168,12 @@ sysfs_read_file(struct file *file, char __user *buf, size_t count, loff_t *ppos)
        ssize_t retval = 0;
 
        down(&buffer->sem);
-       if (buffer->orphaned) {
-               retval = -ENODEV;
-               goto out;
-       }
        if (buffer->needs_read_fill) {
-               if ((retval = fill_read_buffer(file->f_path.dentry,buffer)))
+               if (buffer->orphaned)
+                       retval = -ENODEV;
+               else
+                       retval = fill_read_buffer(file->f_path.dentry,buffer);
+               if (retval)
                        goto out;
        }
        pr_debug("%s: count = %zd, ppos = %lld, buf = %s\n",
index ccb7d722c55897a6105e93457b923e5b1b741c0d..4de5c6b899181b47c07bf7140cda467c1f68d8cc 100644 (file)
@@ -222,13 +222,17 @@ const unsigned char * sysfs_get_name(struct sysfs_dirent *sd)
 
 static inline void orphan_all_buffers(struct inode *node)
 {
-       struct sysfs_buffer_collection *set = node->i_private;
+       struct sysfs_buffer_collection *set;
        struct sysfs_buffer *buf;
 
        mutex_lock_nested(&node->i_mutex, I_MUTEX_CHILD);
-       if (node->i_private) {
-               list_for_each_entry(buf, &set->associates, associates)
+       set = node->i_private;
+       if (set) {
+               list_for_each_entry(buf, &set->associates, associates) {
+                       down(&buf->sem);
                        buf->orphaned = 1;
+                       up(&buf->sem);
+               }
        }
        mutex_unlock(&node->i_mutex);
 }