Commit 6664ef72 authored by David Herrmann's avatar David Herrmann Committed by Jiri Kosina

HID: uhid: implement write() on uhid devices

Similar to read() you can only write() a single event with one call to an
uhid device. To write multiple events use writev() which is supported by
uhid.

We currently always return -EOPNOTSUPP but other events will be added in
later patches.
Signed-off-by: default avatarDavid Herrmann <dh.herrmann@googlemail.com>
Signed-off-by: default avatarJiri Kosina <jkosina@suse.cz>
parent d937ae5f
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
struct uhid_device { struct uhid_device {
struct mutex devlock; struct mutex devlock;
struct hid_device *hid; struct hid_device *hid;
struct uhid_event input_buf;
wait_queue_head_t waitq; wait_queue_head_t waitq;
spinlock_t qlock; spinlock_t qlock;
...@@ -156,7 +157,35 @@ static ssize_t uhid_char_read(struct file *file, char __user *buffer, ...@@ -156,7 +157,35 @@ static ssize_t uhid_char_read(struct file *file, char __user *buffer,
static ssize_t uhid_char_write(struct file *file, const char __user *buffer, static ssize_t uhid_char_write(struct file *file, const char __user *buffer,
size_t count, loff_t *ppos) size_t count, loff_t *ppos)
{ {
return 0; struct uhid_device *uhid = file->private_data;
int ret;
size_t len;
/* we need at least the "type" member of uhid_event */
if (count < sizeof(__u32))
return -EINVAL;
ret = mutex_lock_interruptible(&uhid->devlock);
if (ret)
return ret;
memset(&uhid->input_buf, 0, sizeof(uhid->input_buf));
len = min(count, sizeof(uhid->input_buf));
if (copy_from_user(&uhid->input_buf, buffer, len)) {
ret = -EFAULT;
goto unlock;
}
switch (uhid->input_buf.type) {
default:
ret = -EOPNOTSUPP;
}
unlock:
mutex_unlock(&uhid->devlock);
/* return "count" not "len" to not confuse the caller */
return ret ? ret : count;
} }
static unsigned int uhid_char_poll(struct file *file, poll_table *wait) static unsigned int uhid_char_poll(struct file *file, poll_table *wait)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment