projects
/
cascardo
/
kernel
/
samples
/
char2
/
.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Use mutex.
[cascardo/kernel/samples/char2/.git]
/
hellochar.c
diff --git
a/hellochar.c
b/hellochar.c
index
628f53c
..
1b0c9f2
100644
(file)
--- a/
hellochar.c
+++ b/
hellochar.c
@@
-20,7
+20,7
@@
#include <linux/fs.h>
#include <linux/cdev.h>
#include <linux/slab.h>
#include <linux/fs.h>
#include <linux/cdev.h>
#include <linux/slab.h>
-#include <linux/
semaphore
.h>
+#include <linux/
mutex
.h>
#include <asm/uaccess.h>
MODULE_LICENSE("GPL");
#include <asm/uaccess.h>
MODULE_LICENSE("GPL");
@@
-35,11
+35,11
@@
struct hello_buffer {
char buffer[0];
};
static struct hello_buffer *hello;
char buffer[0];
};
static struct hello_buffer *hello;
-static DE
CLAR
E_MUTEX(hello_mtx);
+static DE
FIN
E_MUTEX(hello_mtx);
static int hello_open(struct inode *ino, struct file *fp)
{
static int hello_open(struct inode *ino, struct file *fp)
{
- if (
down
_interruptible(&hello_mtx))
+ if (
mutex_lock
_interruptible(&hello_mtx))
return -ERESTARTSYS;
if (fp->f_flags & O_TRUNC) {
memset(hello->buffer, 0, MAXLEN);
return -ERESTARTSYS;
if (fp->f_flags & O_TRUNC) {
memset(hello->buffer, 0, MAXLEN);
@@
-47,7
+47,7
@@
static int hello_open(struct inode *ino, struct file *fp)
}
if (fp->f_flags & O_APPEND)
fp->f_pos = hello->len;
}
if (fp->f_flags & O_APPEND)
fp->f_pos = hello->len;
-
up
(&hello_mtx);
+
mutex_unlock
(&hello_mtx);
return 0;
}
return 0;
}
@@
-55,12
+55,12
@@
static ssize_t hello_read(struct file *fp, char __user *buf, size_t sz,
loff_t *pos)
{
int r;
loff_t *pos)
{
int r;
- if (
down
_interruptible(&hello_mtx))
+ if (
mutex_lock
_interruptible(&hello_mtx))
return -ERESTARTSYS;
if (sz + *pos > hello->len)
sz = hello->len - *pos;
r = copy_to_user(buf, hello->buffer + *pos, sz);
return -ERESTARTSYS;
if (sz + *pos > hello->len)
sz = hello->len - *pos;
r = copy_to_user(buf, hello->buffer + *pos, sz);
-
up
(&hello_mtx);
+
mutex_unlock
(&hello_mtx);
if (r)
return -EFAULT;
*pos += sz;
if (r)
return -EFAULT;
*pos += sz;
@@
-71,19
+71,19
@@
static ssize_t hello_write(struct file *fp, const char __user *buf, size_t sz,
loff_t *pos)
{
int r;
loff_t *pos)
{
int r;
- if (
down
_interruptible(&hello_mtx))
+ if (
mutex_lock
_interruptible(&hello_mtx))
return -ERESTARTSYS;
if (sz + *pos > MAXLEN)
sz = MAXLEN - *pos;
r = copy_from_user(hello->buffer + *pos, buf, sz);
if (r) {
return -ERESTARTSYS;
if (sz + *pos > MAXLEN)
sz = MAXLEN - *pos;
r = copy_from_user(hello->buffer + *pos, buf, sz);
if (r) {
-
up
(&hello_mtx);
+
mutex_unlock
(&hello_mtx);
return -EFAULT;
}
*pos += sz;
if (hello->len < *pos)
hello->len = *pos;
return -EFAULT;
}
*pos += sz;
if (hello->len < *pos)
hello->len = *pos;
-
up
(&hello_mtx);
+
mutex_unlock
(&hello_mtx);
return sz;
}
return sz;
}