@@ -227,7 +227,7 @@ static ssize_t dlmfs_file_read(struct file *filp,
227
227
loff_t * ppos )
228
228
{
229
229
int bytes_left ;
230
- ssize_t readlen , got ;
230
+ ssize_t got ;
231
231
char * lvb_buf ;
232
232
struct inode * inode = file_inode (filp );
233
233
@@ -237,36 +237,31 @@ static ssize_t dlmfs_file_read(struct file *filp,
237
237
if (* ppos >= i_size_read (inode ))
238
238
return 0 ;
239
239
240
+ /* don't read past the lvb */
241
+ if (count > i_size_read (inode ) - * ppos )
242
+ count = i_size_read (inode ) - * ppos ;
243
+
240
244
if (!count )
241
245
return 0 ;
242
246
243
- if (!access_ok (buf , count ))
244
- return - EFAULT ;
245
-
246
- /* don't read past the lvb */
247
- if ((count + * ppos ) > i_size_read (inode ))
248
- readlen = i_size_read (inode ) - * ppos ;
249
- else
250
- readlen = count ;
251
-
252
- lvb_buf = kmalloc (readlen , GFP_NOFS );
247
+ lvb_buf = kmalloc (count , GFP_NOFS );
253
248
if (!lvb_buf )
254
249
return - ENOMEM ;
255
250
256
- got = user_dlm_read_lvb (inode , lvb_buf , readlen );
251
+ got = user_dlm_read_lvb (inode , lvb_buf , count );
257
252
if (got ) {
258
- BUG_ON (got != readlen );
259
- bytes_left = __copy_to_user (buf , lvb_buf , readlen );
260
- readlen -= bytes_left ;
253
+ BUG_ON (got != count );
254
+ bytes_left = copy_to_user (buf , lvb_buf , count );
255
+ count -= bytes_left ;
261
256
} else
262
- readlen = 0 ;
257
+ count = 0 ;
263
258
264
259
kfree (lvb_buf );
265
260
266
- * ppos = * ppos + readlen ;
261
+ * ppos = * ppos + count ;
267
262
268
- mlog (0 , "read %zd bytes\n" , readlen );
269
- return readlen ;
263
+ mlog (0 , "read %zu bytes\n" , count );
264
+ return count ;
270
265
}
271
266
272
267
static ssize_t dlmfs_file_write (struct file * filp ,
0 commit comments