Skip to content

Commit 6ee8928

Browse files
mitatorvalds
authored andcommitted
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>
1 parent 236b875 commit 6ee8928

1 file changed

Lines changed: 8 additions & 23 deletions

File tree

‎drivers/char/nwflash.c‎

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -122,35 +122,20 @@ static int flash_ioctl(struct inode *inodep, struct file *filep, unsigned int cm
122122
static ssize_t flash_read(struct file *file, char __user *buf, size_t size,
123123
loff_t *ppos)
124124
{
125-
unsigned long p = *ppos;
126-
unsigned int count = size;
127-
int ret = 0;
125+
ssize_t ret;
128126

129127
if (flashdebug)
130128
printk(KERN_DEBUG "flash_read: flash_read: offset=0x%lX, "
131129
"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;
132135

133-
if (count)
134-
ret = -ENXIO;
135-
136-
if (p < gbFlashSize) {
137-
if (count > gbFlashSize - p)
138-
count = gbFlashSize - p;
136+
ret = simple_read_from_buffer(buf, size, ppos, FLASH_BASE, gbFlashSize);
137+
mutex_unlock(&nwflash_mutex);
139138

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-
}
154139
return ret;
155140
}
156141

0 commit comments

Comments
 (0)