file_table.c

Louis-D. Dubeau (ldd@step.polymtl.ca)
Mon, 17 Jul 1995 15:50:21 -0400


Seems to me like there is unnecessary work done in
linux/fs/file_table.c (in kernel version 1.3.9). In get_empty_filp we
have a call to remove_file_free, a memset and then a put_last_free.
Now, in put_last_free a call is made to remove_file_free. Since
put_last_free and remove_file_free are declared static they cannot be
called from another module.

Here are the relevant pieces of code (all from linux/fs/file_table.c):

------------------------------------------------------------------------------
struct file * get_empty_filp(void)
{
int i;
struct file * f;

if (!first_file)
grow_files();
repeat:
for (f = first_file, i=0; i < nr_files; i++, f = f->f_next)
if (!f->f_count) {
remove_file_free(f);
memset(f,0,sizeof(*f));
put_last_free(f);
f->f_count = 1;
f->f_version = ++event;
return f;
}
if (nr_files < NR_FILE) {
grow_files();
goto repeat;
}
return NULL;
}

static void remove_file_free(struct file *file)
{
if (first_file == file)
first_file = first_file->f_next;
if (file->f_next)
file->f_next->f_prev = file->f_prev;
if (file->f_prev)
file->f_prev->f_next = file->f_next;
file->f_next = file->f_prev = NULL;
}

static void put_last_free(struct file *file)
{
remove_file_free(file);
file->f_prev = first_file->f_prev;
file->f_prev->f_next = file;
file->f_next = first_file;
file->f_next->f_prev = file;
}