Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

[PATCH] sysfs: reinstate exclusion between method calls and attribute unregistration

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>

authored by

Alan Stern and committed by
Linus Torvalds
e7b0d26a d9a9cdfb

+12 -8
+5 -5
fs/sysfs/file.c
··· 168 168 ssize_t retval = 0; 169 169 170 170 down(&buffer->sem); 171 - if (buffer->orphaned) { 172 - retval = -ENODEV; 173 - goto out; 174 - } 175 171 if (buffer->needs_read_fill) { 176 - if ((retval = fill_read_buffer(file->f_path.dentry,buffer))) 172 + if (buffer->orphaned) 173 + retval = -ENODEV; 174 + else 175 + retval = fill_read_buffer(file->f_path.dentry,buffer); 176 + if (retval) 177 177 goto out; 178 178 } 179 179 pr_debug("%s: count = %zd, ppos = %lld, buf = %s\n",
+7 -3
fs/sysfs/inode.c
··· 222 222 223 223 static inline void orphan_all_buffers(struct inode *node) 224 224 { 225 - struct sysfs_buffer_collection *set = node->i_private; 225 + struct sysfs_buffer_collection *set; 226 226 struct sysfs_buffer *buf; 227 227 228 228 mutex_lock_nested(&node->i_mutex, I_MUTEX_CHILD); 229 - if (node->i_private) { 230 - list_for_each_entry(buf, &set->associates, associates) 229 + set = node->i_private; 230 + if (set) { 231 + list_for_each_entry(buf, &set->associates, associates) { 232 + down(&buf->sem); 231 233 buf->orphaned = 1; 234 + up(&buf->sem); 235 + } 232 236 } 233 237 mutex_unlock(&node->i_mutex); 234 238 }