Skip to contentSkip to conversation

ocfs2: question about dlmfs_file_read()

Ocfs2-devel Dan Carpenter 3 participants 4 messages Apr 18, 2010 – Apr 23, 2010 OCFS2

lore
Share & tools
lore
#0 lore raw

Hello list,

I was looking through the code for something unrelated and I got confused by this.

fs/ocfs2/dlmfs/dlmfs.c dlmfs_file_read()
261 /* don't read past the lvb */
262 if ((count + *ppos) > i_size_read(inode))
263 readlen = i_size_read(inode) - *ppos;
264 else
265 readlen = count - *ppos;

Shouldn't "readlen" just be "count" here? What prevents it from being a negative number?

   266
   267          lvb_buf = kmalloc(readlen, GFP_NOFS);

Anyway, this code has been around for a long time so I'm probably missing something. I was just curious.

regards,
dan carpenter

#1 lore raw
Quoted 18 lines · Dan Carpenter

Hello list,

I was looking through the code for something unrelated and I got confused by this.

fs/ocfs2/dlmfs/dlmfs.c dlmfs_file_read()
261 /* don't read past the lvb */
262 if ((count + *ppos) > i_size_read(inode))

   263                  readlen = i_size_read(inode) - *ppos;
   264          else
   265                  readlen = count - *ppos;

	Shouldn't "readlen" just be "count" here?  What prevents it from 
	being a negative number?

   266
   267          lvb_buf = kmalloc(readlen, GFP_NOFS);
Quoted 2 lines

Anyway, this code has been around for a long time so I'm probably missing something. I was just curious.

No, I think you're right. Mark, Sunil, anyone?

Joel

Signature · 9 lines
Life's Little Instruction Book #510

	"Count your blessings."

Joel Becker
Principal Software Developer
Oracle
E-mail: joel.becker at oracle.com
Phone: (650) 506-8127
#2 lore raw
Quoted 17 lines · Joel Becker
Quoted 15 lines · Dan Carpenter

Hello list,

I was looking through the code for something unrelated and I got confused by this.

fs/ocfs2/dlmfs/dlmfs.c dlmfs_file_read()
261 /* don't read past the lvb */
262 if ((count + *ppos) > i_size_read(inode))
263 readlen = i_size_read(inode) - *ppos;
264 else
265 readlen = count - *ppos;

Shouldn't "readlen" just be "count" here? What prevents it from being a negative number?

Quoted 8 lines
Quoted 6 lines
   266
   267          lvb_buf = kmalloc(readlen, GFP_NOFS);

Anyway, this code has been around for a long time so I'm probably missing something. I was just curious.

No, I think you're right. Mark, Sunil, anyone?

Nod.

#3 lore raw
Quoted 21 lines · Sunil Mushran
Quoted 20 lines · Joel Becker
Quoted 18 lines · Dan Carpenter

Hello list,

I was looking through the code for something unrelated and I got confused by this.

fs/ocfs2/dlmfs/dlmfs.c dlmfs_file_read()
261 /* don't read past the lvb */
262 if ((count + *ppos) > i_size_read(inode))

   263                  readlen = i_size_read(inode) - *ppos;
   264          else
   265                  readlen = count - *ppos;

	Shouldn't "readlen" just be "count" here?  What prevents it from 
	being a negative number?

   266
   267          lvb_buf = kmalloc(readlen, GFP_NOFS);
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Anyway, this code has been around for a long time so I'm probably missing something. I was just curious.

No, I think you're right. Mark, Sunil, anyone?

Nod.

Ok, I've pushed this fix to the 'fixes' branch of ocfs2.git.

Joel

From a36d515c7a2dfacebcf41729f6812dbc424ebcf0 Mon Sep 17 00:00:00 2001
From: Joel Becker <[email protected]>
Date: Fri, 23 Apr 2010 15:24:59 -0700
Subject: [PATCH] ocfs2_dlmfs: Fix math error when reading LVB.

When asked for a partial read of the LVB in a dlmfs file, we can accidentally calculate a negative count.

---
 fs/ocfs2/dlmfs/dlmfs.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
fs/ocfs2/dlmfs/dlmfs.c +1 -1
index a99d1ea..b83d610 100644
@@ -262,7 +262,7 @@ static ssize_t dlmfs_file_read(struct file *filp,
 	if ((count + *ppos) > i_size_read(inode))
 		readlen = i_size_read(inode) - *ppos;
 	else
-		readlen = count - *ppos;
+		readlen = count;
 
 	lvb_buf = kmalloc(readlen, GFP_NOFS);
 	if (!lvb_buf)
Signature · 13 lines
1.7.0.4

-- 

Life's Little Instruction Book #139

	"Never deprive someone of hope; it might be all they have."

Joel Becker
Principal Software Developer
Oracle
E-mail: joel.becker at oracle.com
Phone: (650) 506-8127