Skip to content

Commit e7b0d26

Browse files
AlanSternLinus Torvalds
authored andcommitted
[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>
1 parent d9a9cdf commit e7b0d26

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

fs/sysfs/file.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,12 @@ sysfs_read_file(struct file *file, char __user *buf, size_t count, loff_t *ppos)
168168
ssize_t retval = 0;
169169

170170
down(&buffer->sem);
171-
if (buffer->orphaned) {
172-
retval = -ENODEV;
173-
goto out;
174-
}
175171
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)
177177
goto out;
178178
}
179179
pr_debug("%s: count = %zd, ppos = %lld, buf = %s\n",

fs/sysfs/inode.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,17 @@ const unsigned char * sysfs_get_name(struct sysfs_dirent *sd)
222222

223223
static inline void orphan_all_buffers(struct inode *node)
224224
{
225-
struct sysfs_buffer_collection *set = node->i_private;
225+
struct sysfs_buffer_collection *set;
226226
struct sysfs_buffer *buf;
227227

228228
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);
231233
buf->orphaned = 1;
234+
up(&buf->sem);
235+
}
232236
}
233237
mutex_unlock(&node->i_mutex);
234238
}

0 commit comments

Comments
 (0)