]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ntfs3: Refactor duplicate kmemdup pattern in do_action()
authorBaolin Liu <liubaolin@kylinos.cn>
Tue, 6 Jan 2026 06:34:25 +0000 (14:34 +0800)
committerKonstantin Komarov <almaz.alexandrovich@paragon-software.com>
Thu, 15 Jan 2026 04:58:02 +0000 (05:58 +0100)
Extract the repeated pattern of duplicating attribute and updating
OpenAttr into a helper function to reduce code duplication and improve
maintainability.

Signed-off-by: Baolin Liu <liubaolin@kylinos.cn>
Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
fs/ntfs3/fslog.c

index 464d661d9694a22adb0b0f7ad9581bf1f16dfabe..4ea94d53a8190742ea396e0216b1f9cf89182518 100644 (file)
@@ -3030,6 +3030,26 @@ static struct ATTRIB *attr_create_nonres_log(struct ntfs_sb_info *sbi,
        return attr;
 }
 
+/*
+ * update_oa_attr - Synchronize OpenAttr's attribute pointer with modified attribute
+ * @oa2: OpenAttr structure in memory that needs to be updated
+ * @attr: Modified attribute from MFT record to duplicate
+ *
+ * Returns true on success, false on allocation failure.
+ */
+static bool update_oa_attr(struct OpenAttr *oa2, struct ATTRIB *attr)
+{
+       void *p2;
+
+       p2 = kmemdup(attr, le32_to_cpu(attr->size), GFP_NOFS);
+       if (p2) {
+               kfree(oa2->attr);
+               oa2->attr = p2;
+               return true;
+       }
+       return false;
+}
+
 /*
  * do_action - Common routine for the Redo and Undo Passes.
  * @rlsn: If it is NULL then undo.
@@ -3253,15 +3273,8 @@ skip_load_parent:
                        le16_add_cpu(&rec->hard_links, 1);
 
                oa2 = find_loaded_attr(log, attr, rno_base);
-               if (oa2) {
-                       void *p2 = kmemdup(attr, le32_to_cpu(attr->size),
-                                          GFP_NOFS);
-                       if (p2) {
-                               // run_close(oa2->run1);
-                               kfree(oa2->attr);
-                               oa2->attr = p2;
-                       }
-               }
+               if (oa2)
+                       update_oa_attr(oa2, attr);
 
                mi->dirty = true;
                break;
@@ -3320,16 +3333,8 @@ move_data:
                        memmove(Add2Ptr(attr, aoff), data, dlen);
 
                oa2 = find_loaded_attr(log, attr, rno_base);
-               if (oa2) {
-                       void *p2 = kmemdup(attr, le32_to_cpu(attr->size),
-                                          GFP_NOFS);
-                       if (p2) {
-                               // run_close(&oa2->run0);
-                               oa2->run1 = &oa2->run0;
-                               kfree(oa2->attr);
-                               oa2->attr = p2;
-                       }
-               }
+               if (oa2 && update_oa_attr(oa2, attr))
+                       oa2->run1 = &oa2->run0;
 
                mi->dirty = true;
                break;
@@ -3379,14 +3384,9 @@ move_data:
                        attr->nres.total_size = new_sz->total_size;
 
                oa2 = find_loaded_attr(log, attr, rno_base);
-               if (oa2) {
-                       void *p2 = kmemdup(attr, le32_to_cpu(attr->size),
-                                          GFP_NOFS);
-                       if (p2) {
-                               kfree(oa2->attr);
-                               oa2->attr = p2;
-                       }
-               }
+               if (oa2)
+                       update_oa_attr(oa2, attr);
+
                mi->dirty = true;
                break;