Loading fs/file_table.c +13 −14 Original line number Diff line number Diff line Loading @@ -94,8 +94,8 @@ int proc_nr_files(ctl_table *table, int write, #endif /* Find an unused file structure and return a pointer to it. * Returns NULL, if there are no more free file structures or * we run out of memory. * Returns an error pointer if some error happend e.g. we over file * structures limit, run out of memory or operation is not permitted. * * Be very careful using this. You are responsible for * getting write access to any mount that you might assign Loading @@ -108,6 +108,7 @@ struct file *get_empty_filp(void) const struct cred *cred = current_cred(); static long old_max; struct file *f; int error; /* * Privileged users can go above max_files Loading @@ -122,13 +123,16 @@ struct file *get_empty_filp(void) } f = kmem_cache_zalloc(filp_cachep, GFP_KERNEL); if (f == NULL) goto fail; if (unlikely(!f)) return ERR_PTR(-ENOMEM); percpu_counter_inc(&nr_files); f->f_cred = get_cred(cred); if (security_file_alloc(f)) goto fail_sec; error = security_file_alloc(f); if (unlikely(error)) { file_free(f); return ERR_PTR(error); } INIT_LIST_HEAD(&f->f_u.fu_list); atomic_long_set(&f->f_count, 1); Loading @@ -144,12 +148,7 @@ struct file *get_empty_filp(void) pr_info("VFS: file-max limit %lu reached\n", get_max_files()); old_max = get_nr_files(); } goto fail; fail_sec: file_free(f); fail: return NULL; return ERR_PTR(-ENFILE); } /** Loading @@ -173,7 +172,7 @@ struct file *alloc_file(struct path *path, fmode_t mode, struct file *file; file = get_empty_filp(); if (!file) if (IS_ERR(file)) return NULL; file->f_path = *path; Loading fs/namei.c +2 −2 Original line number Diff line number Diff line Loading @@ -2941,8 +2941,8 @@ static struct file *path_openat(int dfd, struct filename *pathname, int error; file = get_empty_filp(); if (!file) return ERR_PTR(-ENFILE); if (IS_ERR(file)) return file; file->f_flags = op->open_flag; Loading fs/open.c +13 −14 Original line number Diff line number Diff line Loading @@ -810,15 +810,13 @@ struct file *dentry_open(const struct path *path, int flags, /* We must always pass in a valid mount pointer. */ BUG_ON(!path->mnt); error = -ENFILE; f = get_empty_filp(); if (f == NULL) return ERR_PTR(error); if (!IS_ERR(f)) { f->f_flags = flags; f->f_path = *path; error = do_dentry_open(f, NULL, cred); if (!error) { /* from now on we need fput() to dispose of f */ error = open_check_o_direct(f); if (error) { fput(f); Loading @@ -828,6 +826,7 @@ struct file *dentry_open(const struct path *path, int flags, put_filp(f); f = ERR_PTR(error); } } return f; } EXPORT_SYMBOL(dentry_open); Loading Loading
fs/file_table.c +13 −14 Original line number Diff line number Diff line Loading @@ -94,8 +94,8 @@ int proc_nr_files(ctl_table *table, int write, #endif /* Find an unused file structure and return a pointer to it. * Returns NULL, if there are no more free file structures or * we run out of memory. * Returns an error pointer if some error happend e.g. we over file * structures limit, run out of memory or operation is not permitted. * * Be very careful using this. You are responsible for * getting write access to any mount that you might assign Loading @@ -108,6 +108,7 @@ struct file *get_empty_filp(void) const struct cred *cred = current_cred(); static long old_max; struct file *f; int error; /* * Privileged users can go above max_files Loading @@ -122,13 +123,16 @@ struct file *get_empty_filp(void) } f = kmem_cache_zalloc(filp_cachep, GFP_KERNEL); if (f == NULL) goto fail; if (unlikely(!f)) return ERR_PTR(-ENOMEM); percpu_counter_inc(&nr_files); f->f_cred = get_cred(cred); if (security_file_alloc(f)) goto fail_sec; error = security_file_alloc(f); if (unlikely(error)) { file_free(f); return ERR_PTR(error); } INIT_LIST_HEAD(&f->f_u.fu_list); atomic_long_set(&f->f_count, 1); Loading @@ -144,12 +148,7 @@ struct file *get_empty_filp(void) pr_info("VFS: file-max limit %lu reached\n", get_max_files()); old_max = get_nr_files(); } goto fail; fail_sec: file_free(f); fail: return NULL; return ERR_PTR(-ENFILE); } /** Loading @@ -173,7 +172,7 @@ struct file *alloc_file(struct path *path, fmode_t mode, struct file *file; file = get_empty_filp(); if (!file) if (IS_ERR(file)) return NULL; file->f_path = *path; Loading
fs/namei.c +2 −2 Original line number Diff line number Diff line Loading @@ -2941,8 +2941,8 @@ static struct file *path_openat(int dfd, struct filename *pathname, int error; file = get_empty_filp(); if (!file) return ERR_PTR(-ENFILE); if (IS_ERR(file)) return file; file->f_flags = op->open_flag; Loading
fs/open.c +13 −14 Original line number Diff line number Diff line Loading @@ -810,15 +810,13 @@ struct file *dentry_open(const struct path *path, int flags, /* We must always pass in a valid mount pointer. */ BUG_ON(!path->mnt); error = -ENFILE; f = get_empty_filp(); if (f == NULL) return ERR_PTR(error); if (!IS_ERR(f)) { f->f_flags = flags; f->f_path = *path; error = do_dentry_open(f, NULL, cred); if (!error) { /* from now on we need fput() to dispose of f */ error = open_check_o_direct(f); if (error) { fput(f); Loading @@ -828,6 +826,7 @@ struct file *dentry_open(const struct path *path, int flags, put_filp(f); f = ERR_PTR(error); } } return f; } EXPORT_SYMBOL(dentry_open); Loading