From: Thadeu Lima de Souza Cascardo Date: Thu, 20 May 2010 14:21:36 +0000 (-0400) Subject: USe interruptible version of down. X-Git-Url: http://git.cascardo.info/?p=cascardo%2Fkernel%2Fsamples%2Fchar2%2F.git;a=commitdiff_plain;h=0ac89f0fe059f1985e9ad39c15794938b5eda7fd USe interruptible version of down. --- diff --git a/hellochar.c b/hellochar.c index 85510f7..628f53c 100644 --- 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) { - 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);