Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp6888460ybi; Wed, 31 Jul 2019 23:46:28 -0700 (PDT) X-Google-Smtp-Source: APXvYqyEitdefuKj75XN18Yx3NhP2T61h/nG/fHuBC9StH5nSEVpzAHTpHCFSLdS5p/5wMEG0Bho X-Received: by 2002:a17:90a:5288:: with SMTP id w8mr6923060pjh.61.1564641987959; Wed, 31 Jul 2019 23:46:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564641987; cv=none; d=google.com; s=arc-20160816; b=VXdrYUKhZu4sjd0P8LW76f5q369MOoPy6e6Vc/g6hqZQHAEcZh47pk2RVb2oazlHLC T3s0IB/bpibt5/kRAHWbJlOn21ShuNBIkdGhLEGoyIgEojQ6CsdcKOdHdhw4j7VPRsd9 ASdQApGSJVCq3z13P31+nrbzkG4di0U6JM6ikWIv9QkXRa0iOHa/Bx2EXqrGsoEhghYL ffuoeGMRfQzG1oSdyj/DfLALzZSrPrSiGJof38Emaaz6ZKLc0jiEYW+PM4oMDeS20nCp PSmbGdUfbDr703wHMIB/sVaY7sPF0q7khe4Sh/F0ksaPnQwCFw4HMYl89+tDRKxRDBme FcAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:thread-index:thread-topic :content-transfer-encoding:mime-version:subject:references :in-reply-to:message-id:cc:to:from:date; bh=a7uMtE+WKeMUwjpB1BJNmYTh2xrcyNJ4ICGUh31j624=; b=teBZYHpOWi9w15ICcbkCsctSqGIig2AkxD+sm2gekbHScwDJX0iAW6quOBQM1R7lgn zLp/gbLr5AgI5XJOVWelc+/K+DQsU2F693THDRexeWKC6H1+xsIaWCFx6h4QIrSDjDqD hU7iH8eH/gomIqAWgKs9Y8X1n9a4BYOMlBKw1JfLb+vkBM76pa84PGUDKmpAYA/eXqdY z1mUOQUOJIm+quFAvPR29+Db4bmfoIG6QsK7IiQ3mlk6g8gBFEIByiZ2vOBjjhfz8Ozj +Msl3CPdaN4DueOZcVmyPsqy/zVnqimLwxrYrBPBFpTh+Nc91I/U+Ae7hzJPd4enHq5y Wr8w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f18si33936996pfq.169.2019.07.31.23.46.12; Wed, 31 Jul 2019 23:46:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730113AbfHAGnj (ORCPT + 99 others); Thu, 1 Aug 2019 02:43:39 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34418 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725804AbfHAGnj (ORCPT ); Thu, 1 Aug 2019 02:43:39 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0872530833A5; Thu, 1 Aug 2019 06:43:39 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id F202860BE0; Thu, 1 Aug 2019 06:43:38 +0000 (UTC) Received: from zmail21.collab.prod.int.phx2.redhat.com (zmail21.collab.prod.int.phx2.redhat.com [10.5.83.24]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id E31C51800202; Thu, 1 Aug 2019 06:43:38 +0000 (UTC) Date: Thu, 1 Aug 2019 02:43:38 -0400 (EDT) From: Pankaj Gupta To: Mike Rapoport Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Message-ID: <1944499597.6210303.1564641818536.JavaMail.zimbra@redhat.com> In-Reply-To: <1564640896-1210-1-git-send-email-rppt@linux.ibm.com> References: <1564640896-1210-1-git-send-email-rppt@linux.ibm.com> Subject: Re: [PATCH] mm/madvise: reduce code duplication in error handling paths MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.116.181, 10.4.195.4] Thread-Topic: mm/madvise: reduce code duplication in error handling paths Thread-Index: epQ2HTIRhoW+wkIZZblxwj+pESe04w== X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Thu, 01 Aug 2019 06:43:39 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > > 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 > --- > 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 > -- > 2.7.4 > >