mm/madvise: reduce code duplication in error handling paths
Subsystems (2)
PATCH 1/1 mm/madvise: reduce code duplication in error handling paths
The madvise_behavior() function converts -ENOMEM to -EAGAIN in several places using identical code.
Move that code to a common error handling path.
No functional changes.
Signed-off-by Mike Rapoport <[email protected]>
--- mm/madvise.c | 52 ++++++++++++++++------------------------------------ 1 file changed, 16 insertions(+), 36 deletions(-)
mm/madvise.c +16 -36
@@ -105,28 +105,14 @@ static long madvise_behavior(struct vm_area_struct *vma,case MADV_MERGEABLE :case MADV_UNMERGEABLE : error =ksm_madvise (vma, start, end, behavior, &new_flags); -if (error) { -/* -* madvise() returns EAGAIN if kernel resources, such as -* slab, are temporarily unavailable. -*/ -if (error == -ENOMEM ) - error = -EAGAIN ; - goto out; - } +if (error) + goto out_convert_errno;break ;case MADV_HUGEPAGE :case MADV_NOHUGEPAGE : error =hugepage_madvise (vma, &new_flags, behavior); -if (error) { -/* -* madvise() returns EAGAIN if kernel resources, such as -* slab, are temporarily unavailable. -*/ -if (error == -ENOMEM ) - error = -EAGAIN ; - goto out; - } +if (error) + goto out_convert_errno;break ; }
@@ -152,15 +138,8 @@ static long madvise_behavior(struct vm_area_struct *vma, goto out; } error =__split_vma (mm, vma, start,1 ); -if (error) { -/* -* madvise() returns EAGAIN if kernel resources, such as -* slab, are temporarily unavailable. -*/ -if (error == -ENOMEM ) - error = -EAGAIN ; - goto out; - } +if (error) + goto out_convert_errno; }if (end != vma->vm_end) {
@@ -169,15 +148,8 @@ static long madvise_behavior(struct vm_area_struct *vma, goto out; } error =__split_vma (mm, vma, end,0 ); -if (error) { -/* -* madvise() returns EAGAIN if kernel resources, such as -* slab, are temporarily unavailable. -*/ -if (error == -ENOMEM ) - error = -EAGAIN ; - goto out; - } +if (error) + goto out_convert_errno; } success:
@@ -185,6 +157,14 @@ static long madvise_behavior(struct vm_area_struct *vma,* vm_flags is protected by the mmap_sem held in write mode. */ vma->vm_flags = new_flags; + +out_convert_errno: +/* +* madvise() returns EAGAIN if kernel resources, such as +* slab, are temporarily unavailable. +*/ +if (error == -ENOMEM ) + error = -EAGAIN ; out:return error; }
Signature · 1 line
2.7.4
Quoted 93 lines
The
madvise_behavior()function converts-ENOMEMto-EAGAINin several places using identical code.Move that code to a common error handling path.
No functional changes.
Signed-off-by Mike Rapoport <[email protected]>--- mm/madvise.c | 52 ++++++++++++++++------------------------------------ 1 file changed, 16 insertions(+), 36 deletions(-)mm/madvise.c +9
-36@@ -105,28 +105,14 @@ static long madvise_behavior(struct vm_area_struct *vma, case MADV_MERGEABLE:case MADV_UNMERGEABLE : error =ksm_madvise (vma, start, end, behavior, &new_flags); -if (error) { -/* -* madvise() returns EAGAIN if kernel resources, such as -* slab, are temporarily unavailable. -*/ -if (error == -ENOMEM ) - error = -EAGAIN ; - goto out; - } +if (error) + goto out_convert_errno;break ;case MADV_HUGEPAGE :case MADV_NOHUGEPAGE : error =hugepage_madvise (vma, &new_flags, behavior); -if (error) { -/* -* madvise() returns EAGAIN if kernel resources, such as -* slab, are temporarily unavailable. -*/ -if (error == -ENOMEM ) - error = -EAGAIN ; - goto out; - } +if (error) + goto out_convert_errno;break ; }@@ -152,15 +138,8 @@ static long madvise_behavior(struct vm_area_struct *vma, goto out; } error =__split_vma (mm, vma, start,1 ); -if (error) { -/* -* madvise() returns EAGAIN if kernel resources, such as -* slab, are temporarily unavailable. -*/ -if (error == -ENOMEM ) - error = -EAGAIN ; - goto out; - } +if (error) + goto out_convert_errno; }if (end != vma->vm_end) {@@ -169,15 +148,8 @@ static long madvise_behavior(struct vm_area_struct *vma, goto out; } error =__split_vma (mm, vma, end,0 ); -if (error) { -/* -* madvise() returns EAGAIN if kernel resources, such as -* slab, are temporarily unavailable. -*/ -if (error == -ENOMEM ) - error = -EAGAIN ; - goto out; - } +if (error) + goto out_convert_errno; } success:@@ -185,6 +157,14 @@ static long madvise_behavior(struct vm_area_struct *vma,* vm_flags is protected by the mmap_sem held in write mode. */ vma->vm_flags = new_flags; +
mm/madvise.c static long madvise_behavior(struct vm_area_struct *vma, · line 170
Quoted 10 lines
mm/madvise.c +7
-0+out_convert_errno: +/* +* madvise() returns EAGAIN if kernel resources, such as +* slab, are temporarily unavailable. +*/ +if (error == -ENOMEM ) + error = -EAGAIN ; out:return error; }
looks good.
Acked-by Pankaj Gupta <[email protected]>
Quoted 4 lines
--
2.7.4
Quoted 8 lines · Mike Rapoport
The
madvise_behavior()function converts-ENOMEMto-EAGAINin several places using identical code.Move that code to a common error handling path.
No functional changes.
Signed-off-by Mike Rapoport <[email protected]>
Reviewed-by Anshuman Khandual <[email protected]>