Skip to content

Commit 6b3c83d

Browse files
murphy12138aalexandrovich
authored andcommitted
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: Baolin Liu <liubaolin@kylinos.cn> Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
1 parent 27b75ca commit 6b3c83d

1 file changed

Lines changed: 27 additions & 27 deletions

File tree

fs/ntfs3/fslog.c

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3030,6 +3030,26 @@ static struct ATTRIB *attr_create_nonres_log(struct ntfs_sb_info *sbi,
30303030
return attr;
30313031
}
30323032

3033+
/*
3034+
* update_oa_attr - Synchronize OpenAttr's attribute pointer with modified attribute
3035+
* @oa2: OpenAttr structure in memory that needs to be updated
3036+
* @attr: Modified attribute from MFT record to duplicate
3037+
*
3038+
* Returns true on success, false on allocation failure.
3039+
*/
3040+
static bool update_oa_attr(struct OpenAttr *oa2, struct ATTRIB *attr)
3041+
{
3042+
void *p2;
3043+
3044+
p2 = kmemdup(attr, le32_to_cpu(attr->size), GFP_NOFS);
3045+
if (p2) {
3046+
kfree(oa2->attr);
3047+
oa2->attr = p2;
3048+
return true;
3049+
}
3050+
return false;
3051+
}
3052+
30333053
/*
30343054
* do_action - Common routine for the Redo and Undo Passes.
30353055
* @rlsn: If it is NULL then undo.
@@ -3253,15 +3273,8 @@ static int do_action(struct ntfs_log *log, struct OPEN_ATTR_ENRTY *oe,
32533273
le16_add_cpu(&rec->hard_links, 1);
32543274

32553275
oa2 = find_loaded_attr(log, attr, rno_base);
3256-
if (oa2) {
3257-
void *p2 = kmemdup(attr, le32_to_cpu(attr->size),
3258-
GFP_NOFS);
3259-
if (p2) {
3260-
// run_close(oa2->run1);
3261-
kfree(oa2->attr);
3262-
oa2->attr = p2;
3263-
}
3264-
}
3276+
if (oa2)
3277+
update_oa_attr(oa2, attr);
32653278

32663279
mi->dirty = true;
32673280
break;
@@ -3320,16 +3333,8 @@ static int do_action(struct ntfs_log *log, struct OPEN_ATTR_ENRTY *oe,
33203333
memmove(Add2Ptr(attr, aoff), data, dlen);
33213334

33223335
oa2 = find_loaded_attr(log, attr, rno_base);
3323-
if (oa2) {
3324-
void *p2 = kmemdup(attr, le32_to_cpu(attr->size),
3325-
GFP_NOFS);
3326-
if (p2) {
3327-
// run_close(&oa2->run0);
3328-
oa2->run1 = &oa2->run0;
3329-
kfree(oa2->attr);
3330-
oa2->attr = p2;
3331-
}
3332-
}
3336+
if (oa2 && update_oa_attr(oa2, attr))
3337+
oa2->run1 = &oa2->run0;
33333338

33343339
mi->dirty = true;
33353340
break;
@@ -3379,14 +3384,9 @@ static int do_action(struct ntfs_log *log, struct OPEN_ATTR_ENRTY *oe,
33793384
attr->nres.total_size = new_sz->total_size;
33803385

33813386
oa2 = find_loaded_attr(log, attr, rno_base);
3382-
if (oa2) {
3383-
void *p2 = kmemdup(attr, le32_to_cpu(attr->size),
3384-
GFP_NOFS);
3385-
if (p2) {
3386-
kfree(oa2->attr);
3387-
oa2->attr = p2;
3388-
}
3389-
}
3387+
if (oa2)
3388+
update_oa_attr(oa2, attr);
3389+
33903390
mi->dirty = true;
33913391
break;
33923392

0 commit comments

Comments
 (0)