summaryrefslogtreecommitdiffstats
path: root/fs/kernfs/inode.c
diff options
context:
space:
mode:
authorOndrej Mosnacek <omosnace@redhat.com>2019-02-22 15:57:13 +0100
committerPaul Moore <paul@paul-moore.com>2019-03-21 02:47:36 +0100
commitd0c9c153b4bd6963c8fcccbc0caa12e8fa8d971d (patch)
treeefb7a76003b4cd0708bc62de789a503072bb5e86 /fs/kernfs/inode.c
parentkernfs: clean up struct kernfs_iattrs (diff)
downloadlinux-d0c9c153b4bd6963c8fcccbc0caa12e8fa8d971d.tar.xz
linux-d0c9c153b4bd6963c8fcccbc0caa12e8fa8d971d.zip
kernfs: do not alloc iattrs in kernfs_xattr_get
This is a read-only operation, so we can simply return -ENODATA if kn->iattr is NULL. Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com> Acked-by: Casey Schaufler <casey@schaufler-ca.com> [PM: minor merge fixes] Signed-off-by: Paul Moore <paul@paul-moore.com>
Diffstat (limited to 'fs/kernfs/inode.c')
-rw-r--r--fs/kernfs/inode.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/fs/kernfs/inode.c b/fs/kernfs/inode.c
index 7d30b4949a84..5c5569fb2110 100644
--- a/fs/kernfs/inode.c
+++ b/fs/kernfs/inode.c
@@ -31,14 +31,14 @@ static const struct inode_operations kernfs_iops = {
.listxattr = kernfs_iop_listxattr,
};
-static struct kernfs_iattrs *kernfs_iattrs(struct kernfs_node *kn)
+static struct kernfs_iattrs *__kernfs_iattrs(struct kernfs_node *kn, int alloc)
{
static DEFINE_MUTEX(iattr_mutex);
struct kernfs_iattrs *ret;
mutex_lock(&iattr_mutex);
- if (kn->iattr)
+ if (kn->iattr || !alloc)
goto out_unlock;
kn->iattr = kmem_cache_zalloc(kernfs_iattrs_cache, GFP_KERNEL);
@@ -60,6 +60,16 @@ out_unlock:
return ret;
}
+static struct kernfs_iattrs *kernfs_iattrs(struct kernfs_node *kn)
+{
+ return __kernfs_iattrs(kn, 1);
+}
+
+static struct kernfs_iattrs *kernfs_iattrs_noalloc(struct kernfs_node *kn)
+{
+ return __kernfs_iattrs(kn, 0);
+}
+
int __kernfs_setattr(struct kernfs_node *kn, const struct iattr *iattr)
{
struct kernfs_iattrs *attrs;
@@ -306,9 +316,9 @@ static int kernfs_xattr_get(const struct xattr_handler *handler,
struct kernfs_node *kn = inode->i_private;
struct kernfs_iattrs *attrs;
- attrs = kernfs_iattrs(kn);
+ attrs = kernfs_iattrs_noalloc(kn);
if (!attrs)
- return -ENOMEM;
+ return -ENODATA;
return simple_xattr_get(&attrs->xattrs, name, value, size);
}