Unverified Commit 6b3c83df authored by Baolin Liu's avatar Baolin Liu Committed by Konstantin Komarov
Browse files

ntfs3: Refactor duplicate kmemdup pattern in do_action()



Extract the repeated pattern of duplicating attribute and updating
OpenAttr into a helper function to reduce code duplication and improve
maintainability.

Signed-off-by: default avatarBaolin Liu <liubaolin@kylinos.cn>
Signed-off-by: default avatarKonstantin Komarov <almaz.alexandrovich@paragon-software.com>
parent 27b75ca4
Loading
Loading
Loading
Loading
+27 −27
Original line number Diff line number Diff line
@@ -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 @@ static int do_action(struct ntfs_log *log, struct OPEN_ATTR_ENRTY *oe,
			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 @@ static int do_action(struct ntfs_log *log, struct OPEN_ATTR_ENRTY *oe,
			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);
		if (oa2 && update_oa_attr(oa2, attr))
			oa2->run1 = &oa2->run0;
				kfree(oa2->attr);
				oa2->attr = p2;
			}
		}

		mi->dirty = true;
		break;
@@ -3379,14 +3384,9 @@ static int do_action(struct ntfs_log *log, struct OPEN_ATTR_ENRTY *oe,
			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;