@@ -94,6 +94,21 @@ static int prop_label(enum prop_object_type type,
return ret;
}
+static char *alloc_xattr_name(const char *name)
+{
+ char *xattr_name;
+
+ xattr_name = malloc(XATTR_BTRFS_PREFIX_LEN + strlen(name) + 1);
+ if (!xattr_name)
+ ERR_PTR(-ENOMEM);
+
+ memcpy(xattr_name, XATTR_BTRFS_PREFIX, XATTR_BTRFS_PREFIX_LEN);
+ memcpy(xattr_name + XATTR_BTRFS_PREFIX_LEN, name, strlen(name));
+ xattr_name[XATTR_BTRFS_PREFIX_LEN + strlen(name)] = '\0';
+
+ return xattr_name;
+}
+
static int prop_compression(enum prop_object_type type,
const char *object,
const char *name,
@@ -114,14 +129,11 @@ static int prop_compression(enum prop_object_type type,
goto out;
}
- xattr_name = malloc(XATTR_BTRFS_PREFIX_LEN + strlen(name) + 1);
- if (!xattr_name) {
- ret = -ENOMEM;
- goto out;
+ xattr_name = alloc_xattr_name(name);
+ if (IS_ERR(xattr_name)) {
+ error("failed to alloc xattr_name %s: %m", object);
+ return PTR_ERR(xattr_name);
}
- memcpy(xattr_name, XATTR_BTRFS_PREFIX, XATTR_BTRFS_PREFIX_LEN);
- memcpy(xattr_name + XATTR_BTRFS_PREFIX_LEN, name, strlen(name));
- xattr_name[XATTR_BTRFS_PREFIX_LEN + strlen(name)] = '\0';
if (value) {
if (strcmp(value, "no") == 0 || strcmp(value, "none") == 0)
This is a preparatory patch to add more xattr attributes, care a helper function to alloc xattr name. Signed-off-by: Anand Jain <anand.jain@oracle.com> --- props.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)