Commit d0c9c153 authored by Ondrej Mosnacek's avatar Ondrej Mosnacek Committed by Paul Moore

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: default avatarOndrej Mosnacek <omosnace@redhat.com>
Acked-by: default avatarCasey Schaufler <casey@schaufler-ca.com>
[PM: minor merge fixes]
Signed-off-by: default avatarPaul Moore <paul@paul-moore.com>
parent 05895219
...@@ -31,14 +31,14 @@ static const struct inode_operations kernfs_iops = { ...@@ -31,14 +31,14 @@ static const struct inode_operations kernfs_iops = {
.listxattr = kernfs_iop_listxattr, .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); static DEFINE_MUTEX(iattr_mutex);
struct kernfs_iattrs *ret; struct kernfs_iattrs *ret;
mutex_lock(&iattr_mutex); mutex_lock(&iattr_mutex);
if (kn->iattr) if (kn->iattr || !alloc)
goto out_unlock; goto out_unlock;
kn->iattr = kmem_cache_zalloc(kernfs_iattrs_cache, GFP_KERNEL); kn->iattr = kmem_cache_zalloc(kernfs_iattrs_cache, GFP_KERNEL);
...@@ -60,6 +60,16 @@ static struct kernfs_iattrs *kernfs_iattrs(struct kernfs_node *kn) ...@@ -60,6 +60,16 @@ static struct kernfs_iattrs *kernfs_iattrs(struct kernfs_node *kn)
return ret; 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) int __kernfs_setattr(struct kernfs_node *kn, const struct iattr *iattr)
{ {
struct kernfs_iattrs *attrs; struct kernfs_iattrs *attrs;
...@@ -306,9 +316,9 @@ static int kernfs_xattr_get(const struct xattr_handler *handler, ...@@ -306,9 +316,9 @@ static int kernfs_xattr_get(const struct xattr_handler *handler,
struct kernfs_node *kn = inode->i_private; struct kernfs_node *kn = inode->i_private;
struct kernfs_iattrs *attrs; struct kernfs_iattrs *attrs;
attrs = kernfs_iattrs(kn); attrs = kernfs_iattrs_noalloc(kn);
if (!attrs) if (!attrs)
return -ENOMEM; return -ENODATA;
return simple_xattr_get(&attrs->xattrs, name, value, size); return simple_xattr_get(&attrs->xattrs, name, value, size);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment