Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

authored by

Baolin Liu and committed by
Konstantin Komarov
6b3c83df 27b75ca4

+27 -27
+27 -27
fs/ntfs3/fslog.c
··· 3031 3031 } 3032 3032 3033 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 + 3053 + /* 3034 3054 * do_action - Common routine for the Redo and Undo Passes. 3035 3055 * @rlsn: If it is NULL then undo. 3036 3056 */ ··· 3273 3253 le16_add_cpu(&rec->hard_links, 1); 3274 3254 3275 3255 oa2 = find_loaded_attr(log, attr, rno_base); 3276 - if (oa2) { 3277 - void *p2 = kmemdup(attr, le32_to_cpu(attr->size), 3278 - GFP_NOFS); 3279 - if (p2) { 3280 - // run_close(oa2->run1); 3281 - kfree(oa2->attr); 3282 - oa2->attr = p2; 3283 - } 3284 - } 3256 + if (oa2) 3257 + update_oa_attr(oa2, attr); 3285 3258 3286 3259 mi->dirty = true; 3287 3260 break; ··· 3333 3320 memmove(Add2Ptr(attr, aoff), data, dlen); 3334 3321 3335 3322 oa2 = find_loaded_attr(log, attr, rno_base); 3336 - if (oa2) { 3337 - void *p2 = kmemdup(attr, le32_to_cpu(attr->size), 3338 - GFP_NOFS); 3339 - if (p2) { 3340 - // run_close(&oa2->run0); 3341 - oa2->run1 = &oa2->run0; 3342 - kfree(oa2->attr); 3343 - oa2->attr = p2; 3344 - } 3345 - } 3323 + if (oa2 && update_oa_attr(oa2, attr)) 3324 + oa2->run1 = &oa2->run0; 3346 3325 3347 3326 mi->dirty = true; 3348 3327 break; ··· 3384 3379 attr->nres.total_size = new_sz->total_size; 3385 3380 3386 3381 oa2 = find_loaded_attr(log, attr, rno_base); 3387 - if (oa2) { 3388 - void *p2 = kmemdup(attr, le32_to_cpu(attr->size), 3389 - GFP_NOFS); 3390 - if (p2) { 3391 - kfree(oa2->attr); 3392 - oa2->attr = p2; 3393 - } 3394 - } 3382 + if (oa2) 3383 + update_oa_attr(oa2, attr); 3384 + 3395 3385 mi->dirty = true; 3396 3386 break; 3397 3387