diff options
author | David Howells <dhowells@redhat.com> | 2012-02-16 12:49:42 -0500 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2012-02-19 13:30:52 -0500 |
commit | 1dce27c5aa6770e9d195f2bb7db1db3d4dde5591 (patch) | |
tree | 4ad3ffeee95cb5b10e047b7cb9bdbb48cfc734e0 /drivers | |
parent | 8b3d1cda4f5ff0d7c2ae910ea8fd03493996912f (diff) |
Wrap accesses to the fd_sets in struct fdtable
Wrap accesses to the fd_sets in struct fdtable (for recording open files and
close-on-exec flags) so that we can move away from using fd_sets since we
abuse the fd_set structs by not allocating the full-sized structure under
normal circumstances and by non-core code looking at the internals of the
fd_sets.
The first abuse means that use of FD_ZERO() on these fd_sets is not permitted,
since that cannot be told about their abnormal lengths.
This introduces six wrapper functions for setting, clearing and testing
close-on-exec flags and fd-is-open flags:
void __set_close_on_exec(int fd, struct fdtable *fdt);
void __clear_close_on_exec(int fd, struct fdtable *fdt);
bool close_on_exec(int fd, const struct fdtable *fdt);
void __set_open_fd(int fd, struct fdtable *fdt);
void __clear_open_fd(int fd, struct fdtable *fdt);
bool fd_is_open(int fd, const struct fdtable *fdt);
Note that I've prepended '__' to the names of the set/clear functions because
they require the caller to hold a lock to use them.
Note also that I haven't added wrappers for looking behind the scenes at the
the array. Possibly that should exist too.
Signed-off-by: David Howells <dhowells@redhat.com>
Link: http://lkml.kernel.org/r/20120216174942.23314.1364.stgit@warthog.procyon.org.uk
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/staging/android/binder.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/drivers/staging/android/binder.c b/drivers/staging/android/binder.c index 7491801a661c..35dd9c370e55 100644 --- a/drivers/staging/android/binder.c +++ b/drivers/staging/android/binder.c | |||
@@ -408,11 +408,11 @@ repeat: | |||
408 | goto repeat; | 408 | goto repeat; |
409 | } | 409 | } |
410 | 410 | ||
411 | FD_SET(fd, fdt->open_fds); | 411 | __set_open_fd(fd, fdt); |
412 | if (flags & O_CLOEXEC) | 412 | if (flags & O_CLOEXEC) |
413 | FD_SET(fd, fdt->close_on_exec); | 413 | __set_close_on_exec(fd, fdt); |
414 | else | 414 | else |
415 | FD_CLR(fd, fdt->close_on_exec); | 415 | __clear_close_on_exec(fd, fdt); |
416 | files->next_fd = fd + 1; | 416 | files->next_fd = fd + 1; |
417 | #if 1 | 417 | #if 1 |
418 | /* Sanity check */ | 418 | /* Sanity check */ |
@@ -453,7 +453,7 @@ static void task_fd_install( | |||
453 | static void __put_unused_fd(struct files_struct *files, unsigned int fd) | 453 | static void __put_unused_fd(struct files_struct *files, unsigned int fd) |
454 | { | 454 | { |
455 | struct fdtable *fdt = files_fdtable(files); | 455 | struct fdtable *fdt = files_fdtable(files); |
456 | __FD_CLR(fd, fdt->open_fds); | 456 | __clear_open_fd(fd, fdt); |
457 | if (fd < files->next_fd) | 457 | if (fd < files->next_fd) |
458 | files->next_fd = fd; | 458 | files->next_fd = fd; |
459 | } | 459 | } |
@@ -479,7 +479,7 @@ static long task_close_fd(struct binder_proc *proc, unsigned int fd) | |||
479 | if (!filp) | 479 | if (!filp) |
480 | goto out_unlock; | 480 | goto out_unlock; |
481 | rcu_assign_pointer(fdt->fd[fd], NULL); | 481 | rcu_assign_pointer(fdt->fd[fd], NULL); |
482 | FD_CLR(fd, fdt->close_on_exec); | 482 | __clear_close_on_exec(fd, fdt); |
483 | __put_unused_fd(files, fd); | 483 | __put_unused_fd(files, fd); |
484 | spin_unlock(&files->file_lock); | 484 | spin_unlock(&files->file_lock); |
485 | retval = filp_close(filp, files); | 485 | retval = filp_close(filp, files); |