| From 853ca7ae292f9c4809e1e42914e81453eaa15367 Mon Sep 17 00:00:00 2001 |
| From: Bjorn Bringert <bringert@android.com> |
| Date: Tue, 20 Dec 2011 16:49:49 -0800 |
| Subject: ashmem: Implement read(2) in ashmem driver |
| MIME-Version: 1.0 |
| Content-Type: text/plain; charset=UTF-8 |
| Content-Transfer-Encoding: 8bit |
| Patch-mainline: HEAD |
| Git-commit: 853ca7ae292f9c4809e1e42914e81453eaa15367 |
| |
| Signed-off-by: Bjorn Bringert <bringert@android.com> |
| [jstultz: Tweaked commit subject] |
| CC: Brian Swetland <swetland@google.com> |
| CC: Colin Cross <ccross@android.com> |
| CC: Arve Hjønnevåg <arve@android.com> |
| CC: Dima Zavin <dima@android.com> |
| CC: Robert Love <rlove@google.com> |
| Signed-off-by: John Stultz <john.stultz@linaro.org> |
| Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de> |
| |
| diff --git a/drivers/staging/android/ashmem.c b/drivers/staging/android/ashmem.c |
| index 5775c6c..6f1a0bb 100644 |
| --- a/drivers/staging/android/ashmem.c |
| +++ b/drivers/staging/android/ashmem.c |
| @@ -211,6 +211,32 @@ static int ashmem_release(struct inode *ignored, struct file *file) |
| return 0; |
| } |
| |
| +static ssize_t ashmem_read(struct file *file, char __user *buf, |
| + size_t len, loff_t *pos) |
| +{ |
| + struct ashmem_area *asma = file->private_data; |
| + int ret = 0; |
| + |
| + mutex_lock(&ashmem_mutex); |
| + |
| + /* If size is not set, or set to 0, always return EOF. */ |
| + if (asma->size == 0) { |
| + goto out; |
| + } |
| + |
| + if (!asma->file) { |
| + ret = -EBADF; |
| + goto out; |
| + } |
| + |
| + ret = asma->file->f_op->read(asma->file, buf, len, pos); |
| + |
| +out: |
| + mutex_unlock(&ashmem_mutex); |
| + return ret; |
| +} |
| + |
| + |
| static int ashmem_mmap(struct file *file, struct vm_area_struct *vma) |
| { |
| struct ashmem_area *asma = file->private_data; |
| @@ -612,6 +638,7 @@ static struct file_operations ashmem_fops = { |
| .owner = THIS_MODULE, |
| .open = ashmem_open, |
| .release = ashmem_release, |
| + .read = ashmem_read, |
| .mmap = ashmem_mmap, |
| .unlocked_ioctl = ashmem_ioctl, |
| .compat_ioctl = ashmem_ioctl, |