Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 23053
b: refs/heads/master
c: 7cf34c7
h: refs/heads/master
i:
  23051: 3630038
v: v3
  • Loading branch information
Ingo Molnar authored and Linus Torvalds committed Mar 23, 2006
1 parent daba2f6 commit 3b8d479
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 7a7d1cf95408863a657035701606b13644c9f55e
refs/heads/master: 7cf34c761db8827818a27e23c50756f8b821a9b0
14 changes: 8 additions & 6 deletions trunk/fs/libfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
#include <linux/pagemap.h>
#include <linux/mount.h>
#include <linux/vfs.h>
#include <linux/mutex.h>

#include <asm/uaccess.h>

int simple_getattr(struct vfsmount *mnt, struct dentry *dentry,
Expand Down Expand Up @@ -530,7 +532,7 @@ struct simple_attr {
char set_buf[24];
void *data;
const char *fmt; /* format for read operation */
struct semaphore sem; /* protects access to these buffers */
struct mutex mutex; /* protects access to these buffers */
};

/* simple_attr_open is called by an actual attribute open file operation
Expand All @@ -549,7 +551,7 @@ int simple_attr_open(struct inode *inode, struct file *file,
attr->set = set;
attr->data = inode->u.generic_ip;
attr->fmt = fmt;
init_MUTEX(&attr->sem);
mutex_init(&attr->mutex);

file->private_data = attr;

Expand All @@ -575,7 +577,7 @@ ssize_t simple_attr_read(struct file *file, char __user *buf,
if (!attr->get)
return -EACCES;

down(&attr->sem);
mutex_lock(&attr->mutex);
if (*ppos) /* continued read */
size = strlen(attr->get_buf);
else /* first read */
Expand All @@ -584,7 +586,7 @@ ssize_t simple_attr_read(struct file *file, char __user *buf,
(unsigned long long)attr->get(attr->data));

ret = simple_read_from_buffer(buf, len, ppos, attr->get_buf, size);
up(&attr->sem);
mutex_unlock(&attr->mutex);
return ret;
}

Expand All @@ -602,7 +604,7 @@ ssize_t simple_attr_write(struct file *file, const char __user *buf,
if (!attr->set)
return -EACCES;

down(&attr->sem);
mutex_lock(&attr->mutex);
ret = -EFAULT;
size = min(sizeof(attr->set_buf) - 1, len);
if (copy_from_user(attr->set_buf, buf, size))
Expand All @@ -613,7 +615,7 @@ ssize_t simple_attr_write(struct file *file, const char __user *buf,
val = simple_strtol(attr->set_buf, NULL, 0);
attr->set(attr->data, val);
out:
up(&attr->sem);
mutex_unlock(&attr->mutex);
return ret;
}

Expand Down

0 comments on commit 3b8d479

Please sign in to comment.