#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");
char buffer[0];
};
static struct hello_buffer *hello;
-static DECLARE_MUTEX(hello_mtx);
+static DEFINE_MUTEX(hello_mtx);
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);
}
if (fp->f_flags & O_APPEND)
fp->f_pos = hello->len;
- up(&hello_mtx);
+ mutex_unlock(&hello_mtx);
return 0;
}
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);
- up(&hello_mtx);
+ mutex_unlock(&hello_mtx);
if (r)
return -EFAULT;
*pos += sz;
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) {
- up(&hello_mtx);
+ mutex_unlock(&hello_mtx);
return -EFAULT;
}
*pos += sz;
if (hello->len < *pos)
hello->len = *pos;
- up(&hello_mtx);
+ mutex_unlock(&hello_mtx);
return sz;
}