]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
btrfs: send: always use fs_path_len() to determine a path's length
authorFilipe Manana <fdmanana@suse.com>
Wed, 5 Feb 2025 11:14:09 +0000 (11:14 +0000)
committerDavid Sterba <dsterba@suse.com>
Tue, 18 Mar 2025 19:35:45 +0000 (20:35 +0100)
Several places are hardcoding the path length calculation instead of using
the helper fs_path_len() for that. Update all those places to instead use
fs_path_len().

Signed-off-by: Filipe Manana <fdmanana@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/send.c

index 4e998bf8d379eaf7c589768b835d12ee01daeb99..9f9885dc1e10a0eadda423c57cd4fbf17777a42c 100644 (file)
@@ -489,7 +489,7 @@ static int fs_path_ensure_buf(struct fs_path *p, int len)
                return -ENOMEM;
        }
 
-       path_len = p->end - p->start;
+       path_len = fs_path_len(p);
        old_buf_len = p->buf_len;
 
        /*
@@ -530,7 +530,7 @@ static int fs_path_prepare_for_add(struct fs_path *p, int name_len,
        int ret;
        int new_len;
 
-       new_len = p->end - p->start + name_len;
+       new_len = fs_path_len(p) + name_len;
        if (p->start != p->end)
                new_len++;
        ret = fs_path_ensure_buf(p, new_len);
@@ -571,12 +571,13 @@ out:
 static int fs_path_add_path(struct fs_path *p, struct fs_path *p2)
 {
        int ret;
+       const int p2_len = fs_path_len(p2);
        char *prepared;
 
-       ret = fs_path_prepare_for_add(p, p2->end - p2->start, &prepared);
+       ret = fs_path_prepare_for_add(p, p2_len, &prepared);
        if (ret < 0)
                goto out;
-       memcpy(prepared, p2->start, p2->end - p2->start);
+       memcpy(prepared, p2->start, p2_len);
 
 out:
        return ret;
@@ -616,7 +617,7 @@ static void fs_path_unreverse(struct fs_path *p)
                return;
 
        tmp = p->start;
-       len = p->end - p->start;
+       len = fs_path_len(p);
        p->start = p->buf;
        p->end = p->start + len;
        memmove(p->start, tmp, len + 1);
@@ -737,7 +738,7 @@ static int tlv_put_btrfs_timespec(struct send_ctx *sctx, u16 attr,
 #define TLV_PUT_PATH(sctx, attrtype, p) \
        do { \
                ret = tlv_put_string(sctx, attrtype, p->start, \
-                       p->end - p->start); \
+                                    fs_path_len((p)));        \
                if (ret < 0) \
                        goto tlv_put_failure; \
        } while(0)
@@ -2364,7 +2365,7 @@ static int __get_cur_name_and_parent(struct send_ctx *sctx,
         * earlier. If yes, treat as orphan and return 1.
         */
        ret = did_overwrite_ref(sctx, *parent_ino, *parent_gen, ino, gen,
-                       dest->start, dest->end - dest->start);
+                               dest->start, fs_path_len(dest));
        if (ret < 0)
                goto out;
        if (ret) {