Heh. This function already exists, and is already in use in various
places, notably read() and write() which are the most easily triggered
offenders of the close/use problem. See
include/linux/file.h
for fget() and fput()..
> When the operation is complete, a check needs to be made that the file
> is still installed for the original fd slot, and then the use count can be
> decremented. If the fd slot has been closed (and maybe reassigned), the file
> pointer must be closed to clean up potential lock files. This operation is
> provided by a fd_put(fd, file) routine.
Again, the only difference is the naming, and the fact that the way I
implemented it you don't actually need to remember the file descriptor (so
it's just a simple fput(file) in my routines).
> Note that the operations in fs/read_write.c were already using fget() to protect
> the file pointer, but there was a slight problem with using fput() to decrement
> the count. If the file had already been closed (by a clone task), this would
> have omitted to call to remove locks for the current process. I've replaced the
> fget/fputs with fd_get/fd_puts.
What was the problem? The locks should be removed when the last fput(file)
happens - if that doesn't work then _that_ is the bug rather than any
interface issues..
Linus