summaryrefslogtreecommitdiffstats
path: root/fs/kernfs/file.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/kernfs/file.c')
-rw-r--r--fs/kernfs/file.c55
1 files changed, 32 insertions, 23 deletions
diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
index dbf397bfdff2..ddcb471b9cc9 100644
--- a/fs/kernfs/file.c
+++ b/fs/kernfs/file.c
@@ -252,19 +252,9 @@ static ssize_t kernfs_fop_write(struct file *file, const char __user *user_buf,
size_t count, loff_t *ppos)
{
struct kernfs_open_file *of = kernfs_of(file);
- ssize_t len = min_t(size_t, count, PAGE_SIZE);
const struct kernfs_ops *ops;
- char *buf;
-
- buf = kmalloc(len + 1, GFP_KERNEL);
- if (!buf)
- return -ENOMEM;
-
- if (copy_from_user(buf, user_buf, len)) {
- len = -EFAULT;
- goto out_free;
- }
- buf[len] = '\0'; /* guarantee string termination */
+ char *buf = NULL;
+ ssize_t len;
/*
* @of->mutex nests outside active ref and is just to ensure that
@@ -273,22 +263,45 @@ static ssize_t kernfs_fop_write(struct file *file, const char __user *user_buf,
mutex_lock(&of->mutex);
if (!kernfs_get_active(of->kn)) {
mutex_unlock(&of->mutex);
- len = -ENODEV;
- goto out_free;
+ return -ENODEV;
}
ops = kernfs_ops(of->kn);
- if (ops->write)
- len = ops->write(of, buf, len, *ppos);
- else
+ if (!ops->write) {
len = -EINVAL;
+ goto out_unlock;
+ }
+ if (ops->atomic_write_len) {
+ len = count;
+ if (len > ops->atomic_write_len) {
+ len = -E2BIG;
+ goto out_unlock;
+ }
+ } else {
+ len = min_t(size_t, count, PAGE_SIZE);
+ }
+
+ buf = kmalloc(len + 1, GFP_KERNEL);
+ if (!buf) {
+ len = -ENOMEM;
+ goto out_unlock;
+ }
+
+ if (copy_from_user(buf, user_buf, len)) {
+ len = -EFAULT;
+ goto out_unlock;
+ }
+ buf[len] = '\0'; /* guarantee string termination */
+
+ len = ops->write(of, buf, len, *ppos);
+out_unlock:
kernfs_put_active(of->kn);
mutex_unlock(&of->mutex);
if (len > 0)
*ppos += len;
-out_free:
+
kfree(buf);
return len;
}
@@ -820,7 +833,6 @@ struct kernfs_node *__kernfs_create_file(struct kernfs_node *parent,
bool name_is_static,
struct lock_class_key *key)
{
- struct kernfs_addrm_cxt acxt;
struct kernfs_node *kn;
unsigned flags;
int rc;
@@ -855,10 +867,7 @@ struct kernfs_node *__kernfs_create_file(struct kernfs_node *parent,
if (ops->mmap)
kn->flags |= KERNFS_HAS_MMAP;
- kernfs_addrm_start(&acxt);
- rc = kernfs_add_one(&acxt, kn);
- kernfs_addrm_finish(&acxt);
-
+ rc = kernfs_add_one(kn);
if (rc) {
kernfs_put(kn);
return ERR_PTR(rc);