Skip to contentSkip to conversation

mm: do_generic_file_read() never gets a NULL 'filp' argument

PATCH In review Krishna Kumar 4 participants 6 messages Sep 22, 2008 – Sep 23, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mm: do_generic_file_read() never gets a NULL 'filp' argument

From: Krishna Kumar <[email protected]>

The 'filp' argument to do_generic_file_read() is never NULL.

---
 mm/filemap.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
mm/filemap.c +1 -2
diff -ruNp 2.6.27-rc7-org/mm/filemap.c 2.6.27-rc7-new/mm/filemap.c
@@ -1186,8 +1186,7 @@ out:
 	ra->prev_pos |= prev_offset;
 
 	*ppos = ((loff_t)index << PAGE_CACHE_SHIFT) + offset;
-	if (filp)
-		file_accessed(filp);
+	file_accessed(filp);
 }
 
 int file_read_actor(read_descriptor_t *desc, struct page *page,
maintainer
#1 lore raw
Quoted 4 lines · On Mon, 22 Sep 2008 11:46:10 +0530 Krishna Kumar <[email protected]> wrote:

From: Krishna Kumar <[email protected]>

The 'filp' argument to do_generic_file_read() is never NULL.

How did you verify this?

NFS used to like passing NULL file*'s into VFS functions. I don't recall whether it affected do_generic_file_read().

Quoted 16 lines
 mm/filemap.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff -ruNp 2.6.27-rc7-org/mm/filemap.c 2.6.27-rc7-new/mm/filemap.c

mm/filemap.c +1 -2
@@ -1186,8 +1186,7 @@ out:
 	ra->prev_pos |= prev_offset;
 
 	*ppos = ((loff_t)index << PAGE_CACHE_SHIFT) + offset;
-	if (filp)
-		file_accessed(filp);
+	file_accessed(filp);
 }
 
 int file_read_actor(read_descriptor_t *desc, struct page *page,
#2 lore raw
Quoted 11 lines · Andrew Morton
Quoted 4 lines · On Mon, 22 Sep 2008 11:46:10 +0530 Krishna Kumar <[email protected]> wrote:

From: Krishna Kumar <[email protected]>

The 'filp' argument to do_generic_file_read() is never NULL.

How did you verify this?

NFS used to like passing NULL file*'s into VFS functions. I don't recall whether it affected do_generic_file_read().

The only thing nfsd passed a NULL file pointer in is ->fsync on directories. If anyone did pass a NULL file pointer into do_generic_file_read it would oops in it's very first line of code.

maintainer
#3 lore raw
Quoted 8 lines · On Mon, 22 Sep 2008 04:39:46 -0400 Christoph Hellwig <[email protected]> wrote:
Quoted 7 lines · Andrew Morton
Quoted 4 lines · On Mon, 22 Sep 2008 11:46:10 +0530 Krishna Kumar <[email protected]> wrote:

From: Krishna Kumar <[email protected]>

The 'filp' argument to do_generic_file_read() is never NULL.

Quoted 7 lines
Quoted 4 lines

How did you verify this?

NFS used to like passing NULL file*'s into VFS functions. I don't recall whether it affected do_generic_file_read().

The only thing nfsd passed a NULL file pointer in is ->fsync on directories.

NFS, not NFSD. It was page_cache_read(), iirc.

#4 lore raw

Hi Andrew,

Quoted 11 lines
Quoted 9 lines
Quoted 6 lines
Quoted 1 line

The 'filp' argument to do_generic_file_read() is never NULL.

How did you verify this?

NFS used to like passing NULL file*'s into VFS functions. I don't recall whether it affected do_generic_file_read().

The only thing nfsd passed a NULL file pointer in is ->fsync on directories.

NFS, not NFSD. It was page_cache_read(), iirc.

Is it important?
Cristoph wrote following decision reason at last mail. I believe he was right.

Quoted 2 lines

If anyone did pass a NULL file pointer into do_generic_file_read it would oops in it's very first line of code.

IOW, do_generic_file_read() has following calling hieralcy.

generic_file_aio_read()
+- do_generic_file_read()

and fs/nfs/file.c has

const struct file_operations nfs_file_operations = {
.llseek = nfs_file_llseek,
.read = do_sync_read,
.write = do_sync_write,
.aio_read = nfs_file_read,
.aio_write = nfs_file_write,

So, nfs doesn't use generic_file_aio_read.
it directly indicate nfs doesn't use do_generic_file_read().

in the other hand, page_cache_read() has following calling hieralcy.

filemap_fault()

  +- page_cache_read()
      +- a_ops->readpage()

So, page_cache_read is mmap() related helper function and do_generic_file_read is read() related helper function. they are independent IMHO.

#5 lore raw
In reply to Andrew Morton
Quoted 11 lines · On Mon, 22 Sep 2008 11:46:10 +0530 Krishna Kumar <[email protected]> wrote:
Quoted 5 lines

From: Krishna Kumar <[email protected]>

The 'filp' argument to do_generic_file_read() is never NULL.

How did you verify this?

NFS used to like passing NULL file*'s into VFS functions. I don't recall whether it affected do_generic_file_read().

Andrew, current do_generic_file_read have filp dereference at the beginning of function. So, I believe nobody pass to NULL.

static void do_generic_file_read(struct file *filp, loff_t *ppos,
read_descriptor_t *desc, read_actor_t actor)

{
        struct address_space *mapping = filp->f_mapping;  /* here */
        struct inode *inode = mapping->host;
        struct file_ra_state *ra = &filp->f_ra;          /* ditto */
        pgoff_t index;
        pgoff_t last_index;
        pgoff_t prev_index;
Quoted 22 lines
Quoted 8 lines
 mm/filemap.c |    3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff -ruNp 2.6.27-rc7-org/mm/filemap.c 2.6.27-rc7-new/mm/filemap.c

mm/filemap.c out: · line 1192

Quoted 9 lines
mm/filemap.c +1 -2
@@ -1186,8 +1186,7 @@ out:
 	ra->prev_pos |= prev_offset;
 
 	*ppos = ((loff_t)index << PAGE_CACHE_SHIFT) + offset;
-	if (filp)
-		file_accessed(filp);
+	file_accessed(filp);
 }
 
 int file_read_actor(read_descriptor_t *desc, struct page *page,

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/