diff options
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/staging/android/binder.c | 59 |
1 files changed, 5 insertions, 54 deletions
diff --git a/drivers/staging/android/binder.c b/drivers/staging/android/binder.c index b9a534c46aa..4946d282a35 100644 --- a/drivers/staging/android/binder.c +++ b/drivers/staging/android/binder.c | |||
@@ -362,71 +362,22 @@ struct binder_transaction { | |||
362 | static void | 362 | static void |
363 | binder_defer_work(struct binder_proc *proc, enum binder_deferred_state defer); | 363 | binder_defer_work(struct binder_proc *proc, enum binder_deferred_state defer); |
364 | 364 | ||
365 | /* | ||
366 | * copied from get_unused_fd_flags | ||
367 | */ | ||
368 | int task_get_unused_fd_flags(struct binder_proc *proc, int flags) | 365 | int task_get_unused_fd_flags(struct binder_proc *proc, int flags) |
369 | { | 366 | { |
370 | struct files_struct *files = proc->files; | 367 | struct files_struct *files = proc->files; |
371 | int fd, error; | ||
372 | struct fdtable *fdt; | ||
373 | unsigned long rlim_cur; | 368 | unsigned long rlim_cur; |
374 | unsigned long irqs; | 369 | unsigned long irqs; |
375 | 370 | ||
376 | if (files == NULL) | 371 | if (files == NULL) |
377 | return -ESRCH; | 372 | return -ESRCH; |
378 | 373 | ||
379 | error = -EMFILE; | 374 | if (!lock_task_sighand(proc->tsk, &irqs)) |
380 | spin_lock(&files->file_lock); | 375 | return -EMFILE; |
381 | 376 | ||
382 | repeat: | 377 | rlim_cur = task_rlimit(proc->tsk, RLIMIT_NOFILE); |
383 | fdt = files_fdtable(files); | 378 | unlock_task_sighand(proc->tsk, &irqs); |
384 | fd = find_next_zero_bit(fdt->open_fds, fdt->max_fds, files->next_fd); | ||
385 | |||
386 | /* | ||
387 | * N.B. For clone tasks sharing a files structure, this test | ||
388 | * will limit the total number of files that can be opened. | ||
389 | */ | ||
390 | rlim_cur = 0; | ||
391 | if (lock_task_sighand(proc->tsk, &irqs)) { | ||
392 | rlim_cur = proc->tsk->signal->rlim[RLIMIT_NOFILE].rlim_cur; | ||
393 | unlock_task_sighand(proc->tsk, &irqs); | ||
394 | } | ||
395 | if (fd >= rlim_cur) | ||
396 | goto out; | ||
397 | |||
398 | /* Do we need to expand the fd array or fd set? */ | ||
399 | error = expand_files(files, fd); | ||
400 | if (error < 0) | ||
401 | goto out; | ||
402 | |||
403 | if (error) { | ||
404 | /* | ||
405 | * If we needed to expand the fs array we | ||
406 | * might have blocked - try again. | ||
407 | */ | ||
408 | error = -EMFILE; | ||
409 | goto repeat; | ||
410 | } | ||
411 | |||
412 | __set_open_fd(fd, fdt); | ||
413 | if (flags & O_CLOEXEC) | ||
414 | __set_close_on_exec(fd, fdt); | ||
415 | else | ||
416 | __clear_close_on_exec(fd, fdt); | ||
417 | files->next_fd = fd + 1; | ||
418 | #if 1 | ||
419 | /* Sanity check */ | ||
420 | if (fdt->fd[fd] != NULL) { | ||
421 | pr_warn("get_unused_fd: slot %d not NULL!\n", fd); | ||
422 | fdt->fd[fd] = NULL; | ||
423 | } | ||
424 | #endif | ||
425 | error = fd; | ||
426 | 379 | ||
427 | out: | 380 | return __alloc_fd(files, 0, rlim_cur, flags); |
428 | spin_unlock(&files->file_lock); | ||
429 | return error; | ||
430 | } | 381 | } |
431 | 382 | ||
432 | /* | 383 | /* |