USe interruptible version of down.
[cascardo/kernel/samples/char2/.git] / hellochar.c
index 85510f7..628f53c 100644 (file)
@@ -39,7 +39,8 @@ static DECLARE_MUTEX(hello_mtx);
 
 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;
@@ -54,7 +55,8 @@ static ssize_t hello_read(struct file *fp, char __user *buf, size_t sz,
        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);
@@ -69,7 +71,8 @@ static ssize_t hello_write(struct file *fp, const char __user *buf, size_t sz,
        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);