Commit 6ee8928d94841aa764aeaf645ad16daff811dc26
Committed by
Linus Torvalds
1 parent
236b8756a2
Exists in
master
and in
7 other branches
nwflash: use simple_read_from_buffer()
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com> Cc: Russell King <linux@arm.linux.org.uk> Cc: Tim Schmielau <tim@physik3.uni-rostock.de> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Showing 1 changed file with 8 additions and 23 deletions Side-by-side Diff
drivers/char/nwflash.c
... | ... | @@ -122,35 +122,20 @@ |
122 | 122 | static ssize_t flash_read(struct file *file, char __user *buf, size_t size, |
123 | 123 | loff_t *ppos) |
124 | 124 | { |
125 | - unsigned long p = *ppos; | |
126 | - unsigned int count = size; | |
127 | - int ret = 0; | |
125 | + ssize_t ret; | |
128 | 126 | |
129 | 127 | if (flashdebug) |
130 | 128 | printk(KERN_DEBUG "flash_read: flash_read: offset=0x%lX, " |
131 | 129 | "buffer=%p, count=0x%X.\n", p, buf, count); |
130 | + /* | |
131 | + * We now lock against reads and writes. --rmk | |
132 | + */ | |
133 | + if (mutex_lock_interruptible(&nwflash_mutex)) | |
134 | + return -ERESTARTSYS; | |
132 | 135 | |
133 | - if (count) | |
134 | - ret = -ENXIO; | |
136 | + ret = simple_read_from_buffer(buf, size, ppos, FLASH_BASE, gbFlashSize); | |
137 | + mutex_unlock(&nwflash_mutex); | |
135 | 138 | |
136 | - if (p < gbFlashSize) { | |
137 | - if (count > gbFlashSize - p) | |
138 | - count = gbFlashSize - p; | |
139 | - | |
140 | - /* | |
141 | - * We now lock against reads and writes. --rmk | |
142 | - */ | |
143 | - if (mutex_lock_interruptible(&nwflash_mutex)) | |
144 | - return -ERESTARTSYS; | |
145 | - | |
146 | - ret = copy_to_user(buf, (void *)(FLASH_BASE + p), count); | |
147 | - if (ret == 0) { | |
148 | - ret = count; | |
149 | - *ppos += count; | |
150 | - } else | |
151 | - ret = -EFAULT; | |
152 | - mutex_unlock(&nwflash_mutex); | |
153 | - } | |
154 | 139 | return ret; |
155 | 140 | } |
156 | 141 |