linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm/madvise: reduce code duplication in error handling paths
@ 2019-08-01  6:28 Mike Rapoport
  2019-08-01  6:43 ` Pankaj Gupta
  2019-08-02  3:37 ` Anshuman Khandual
  0 siblings, 2 replies; 3+ messages in thread
From: Mike Rapoport @ 2019-08-01  6:28 UTC (permalink / raw)
  To: Andrew Morton; +Cc: linux-mm, linux-kernel, Mike Rapoport

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 <rppt@linux.ibm.com>
---
 mm/madvise.c | 52 ++++++++++++++++------------------------------------
 1 file changed, 16 insertions(+), 36 deletions(-)

diff --git a/mm/madvise.c b/mm/madvise.c
index 968df3a..55d78fd 100644
--- a/mm/madvise.c
+++ b/mm/madvise.c
@@ -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;
 }
-- 
2.7.4


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm/madvise: reduce code duplication in error handling paths
  2019-08-01  6:28 [PATCH] mm/madvise: reduce code duplication in error handling paths Mike Rapoport
@ 2019-08-01  6:43 ` Pankaj Gupta
  2019-08-02  3:37 ` Anshuman Khandual
  1 sibling, 0 replies; 3+ messages in thread
From: Pankaj Gupta @ 2019-08-01  6:43 UTC (permalink / raw)
  To: Mike Rapoport; +Cc: Andrew Morton, linux-mm, linux-kernel


> 
> 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 <rppt@linux.ibm.com>
> ---
>  mm/madvise.c | 52 ++++++++++++++++------------------------------------
>  1 file changed, 16 insertions(+), 36 deletions(-)
> 
> diff --git a/mm/madvise.c b/mm/madvise.c
> index 968df3a..55d78fd 100644
> --- a/mm/madvise.c
> +++ b/mm/madvise.c
> @@ -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;
>  }

looks good.

Acked-by: Pankaj Gupta <pagupta@redhat.com>

> --
> 2.7.4
> 
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm/madvise: reduce code duplication in error handling paths
  2019-08-01  6:28 [PATCH] mm/madvise: reduce code duplication in error handling paths Mike Rapoport
  2019-08-01  6:43 ` Pankaj Gupta
@ 2019-08-02  3:37 ` Anshuman Khandual
  1 sibling, 0 replies; 3+ messages in thread
From: Anshuman Khandual @ 2019-08-02  3:37 UTC (permalink / raw)
  To: Mike Rapoport, Andrew Morton; +Cc: linux-mm, linux-kernel



On 08/01/2019 11:58 AM, Mike Rapoport wrote:
> 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 <rppt@linux.ibm.com>

Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-08-02  3:37 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-01  6:28 [PATCH] mm/madvise: reduce code duplication in error handling paths Mike Rapoport
2019-08-01  6:43 ` Pankaj Gupta
2019-08-02  3:37 ` Anshuman Khandual

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).