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 interruptible version of down.
[cascardo/kernel/samples/char2/.git]
/
hellochar.c
diff --git
a/hellochar.c
b/hellochar.c
index
85510f7
..
628f53c
100644
(file)
--- a/
hellochar.c
+++ b/
hellochar.c
@@
-39,7
+39,8
@@
static DECLARE_MUTEX(hello_mtx);
static int hello_open(struct inode *ino, struct file *fp)
{
static int hello_open(struct inode *ino, struct file *fp)
{
- down(&hello_mtx);
+ if (down_interruptible(&hello_mtx))
+ return -ERESTARTSYS;
if (fp->f_flags & O_TRUNC) {
memset(hello->buffer, 0, MAXLEN);
hello->len = 0;
if (fp->f_flags & O_TRUNC) {
memset(hello->buffer, 0, MAXLEN);
hello->len = 0;
@@
-54,7
+55,8
@@
static ssize_t hello_read(struct file *fp, char __user *buf, size_t sz,
loff_t *pos)
{
int r;
loff_t *pos)
{
int r;
- down(&hello_mtx);
+ if (down_interruptible(&hello_mtx))
+ return -ERESTARTSYS;
if (sz + *pos > hello->len)
sz = hello->len - *pos;
r = copy_to_user(buf, hello->buffer + *pos, sz);
if (sz + *pos > hello->len)
sz = hello->len - *pos;
r = copy_to_user(buf, hello->buffer + *pos, sz);
@@
-69,7
+71,8
@@
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;
- down(&hello_mtx);
+ if (down_interruptible(&hello_mtx))
+ return -ERESTARTSYS;
if (sz + *pos > MAXLEN)
sz = MAXLEN - *pos;
r = copy_from_user(hello->buffer + *pos, buf, sz);
if (sz + *pos > MAXLEN)
sz = MAXLEN - *pos;
r = copy_from_user(hello->buffer + *pos, buf, sz);