summaryrefslogtreecommitdiff
path: root/fs/bcachefs/xattr.c
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2019-06-13 11:01:14 -0400
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-22 17:08:23 -0400
commit2a488aaac1d4a7f5b48bce687adf430d24e0beb5 (patch)
tree817ebb140e5bce3425331d080f3ee9af6a9cb96c /fs/bcachefs/xattr.c
parente0dfc08bc2f509de9fda0371b46988247f711a12 (diff)
bcachefs: fix __bch2_xattr_bcachefs_get()
We were returning -ERANGE when the size of the buffer passed in was exactly the size of the xattr val Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
Diffstat (limited to 'fs/bcachefs/xattr.c')
-rw-r--r--fs/bcachefs/xattr.c24
1 files changed, 10 insertions, 14 deletions
diff --git a/fs/bcachefs/xattr.c b/fs/bcachefs/xattr.c
index 2ccf64db8147..5aeff1012f8b 100644
--- a/fs/bcachefs/xattr.c
+++ b/fs/bcachefs/xattr.c
@@ -387,6 +387,9 @@ static int __bch2_xattr_bcachefs_get(const struct xattr_handler *handler,
bch2_inode_opts_to_opts(bch2_inode_opts_get(&inode->ei_inode));
const struct bch_option *opt;
int id, inode_opt_id;
+ char buf[512];
+ struct printbuf out = PBUF(buf);
+ unsigned val_len;
u64 v;
id = bch2_opt_lookup(name);
@@ -407,23 +410,16 @@ static int __bch2_xattr_bcachefs_get(const struct xattr_handler *handler,
return -ENODATA;
v = bch2_opt_get_by_id(&opts, id);
+ bch2_opt_to_text(&out, c, opt, v, 0);
- if (!buffer) {
- char buf[512];
- struct printbuf out = PBUF(buf);
+ val_len = out.pos - buf;
- bch2_opt_to_text(&out, c, opt, v, 0);
+ if (buffer && val_len > size)
+ return -ERANGE;
- return out.pos - buf;
- } else {
- struct printbuf out = _PBUF(buffer, size);
-
- bch2_opt_to_text(&out, c, opt, v, 0);
-
- return printbuf_remaining(&out)
- ? (void *) out.pos - buffer
- : -ERANGE;
- }
+ if (buffer)
+ memcpy(buffer, buf, val_len);
+ return val_len;
}
static int bch2_xattr_bcachefs_get(const struct xattr_handler *handler,