Skip to content

Commit 3815f1b

Browse files
author
Al Viro
committed
dlmfs_file_write(): fix the bogosity in handling non-zero *ppos
'count' is how much you want written, not the final position. Moreover, it can legitimately be less than the current position... Cc: [email protected] Signed-off-by: Al Viro <[email protected]>
1 parent 8f3d9f3 commit 3815f1b

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

fs/ocfs2/dlmfs/dlmfs.c

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,6 @@ static ssize_t dlmfs_file_write(struct file *filp,
275275
loff_t *ppos)
276276
{
277277
int bytes_left;
278-
ssize_t writelen;
279278
char *lvb_buf;
280279
struct inode *inode = file_inode(filp);
281280

@@ -285,32 +284,30 @@ static ssize_t dlmfs_file_write(struct file *filp,
285284
if (*ppos >= i_size_read(inode))
286285
return -ENOSPC;
287286

287+
/* don't write past the lvb */
288+
if (count > i_size_read(inode) - *ppos)
289+
count = i_size_read(inode) - *ppos;
290+
288291
if (!count)
289292
return 0;
290293

291294
if (!access_ok(buf, count))
292295
return -EFAULT;
293296

294-
/* don't write past the lvb */
295-
if ((count + *ppos) > i_size_read(inode))
296-
writelen = i_size_read(inode) - *ppos;
297-
else
298-
writelen = count - *ppos;
299-
300-
lvb_buf = kmalloc(writelen, GFP_NOFS);
297+
lvb_buf = kmalloc(count, GFP_NOFS);
301298
if (!lvb_buf)
302299
return -ENOMEM;
303300

304-
bytes_left = copy_from_user(lvb_buf, buf, writelen);
305-
writelen -= bytes_left;
306-
if (writelen)
307-
user_dlm_write_lvb(inode, lvb_buf, writelen);
301+
bytes_left = copy_from_user(lvb_buf, buf, count);
302+
count -= bytes_left;
303+
if (count)
304+
user_dlm_write_lvb(inode, lvb_buf, count);
308305

309306
kfree(lvb_buf);
310307

311-
*ppos = *ppos + writelen;
312-
mlog(0, "wrote %zd bytes\n", writelen);
313-
return writelen;
308+
*ppos = *ppos + count;
309+
mlog(0, "wrote %zu bytes\n", count);
310+
return count;
314311
}
315312

316313
static void dlmfs_init_once(void *foo)

0 commit comments

Comments
 (0)