From patchwork Sat Jun 6 15:02:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Machek X-Patchwork-Id: 11591221 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 948FF912 for ; Sat, 6 Jun 2020 15:02:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7AD192086A for ; Sat, 6 Jun 2020 15:02:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727770AbgFFPCP (ORCPT ); Sat, 6 Jun 2020 11:02:15 -0400 Received: from jabberwock.ucw.cz ([46.255.230.98]:55040 "EHLO jabberwock.ucw.cz" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726089AbgFFPCP (ORCPT ); Sat, 6 Jun 2020 11:02:15 -0400 Received: by jabberwock.ucw.cz (Postfix, from userid 1017) id 8D9E81C0BD2; Sat, 6 Jun 2020 17:02:13 +0200 (CEST) Date: Sat, 6 Jun 2020 17:02:12 +0200 From: Pavel Machek To: viro@zeniv.linux.org.uk, linux-fsdevel@vger.kernel.org, kernel list , trivial@kernel.org Subject: [PATCH] fs/userfaultfd: No need for gotos Message-ID: <20200606150212.GA10177@amd> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org No need for gotos when all the target does is return. In this case it also avoids redundant variable assignments. Signed-off-by: Pavel Machek (CIP) diff --git a/fs/userfaultfd.c b/fs/userfaultfd.c index e39fdec8a0b0..860db4fd28dc 100644 --- a/fs/userfaultfd.c +++ b/fs/userfaultfd.c @@ -1883,12 +1883,10 @@ static int userfaultfd_api(struct userfaultfd_ctx *ctx, int ret; __u64 features; - ret = -EINVAL; if (ctx->state != UFFD_STATE_WAIT_API) - goto out; - ret = -EFAULT; + return -EINVAL; if (copy_from_user(&uffdio_api, buf, sizeof(uffdio_api))) - goto out; + return -EFAULT; features = uffdio_api.features; ret = -EINVAL; if (uffdio_api.api != UFFD_API || (features & ~UFFD_API_FEATURES)) @@ -1899,20 +1897,18 @@ static int userfaultfd_api(struct userfaultfd_ctx *ctx, /* report all available features and ioctls to userland */ uffdio_api.features = UFFD_API_FEATURES; uffdio_api.ioctls = UFFD_API_IOCTLS; - ret = -EFAULT; if (copy_to_user(buf, &uffdio_api, sizeof(uffdio_api))) - goto out; + return -EFAULT; ctx->state = UFFD_STATE_RUNNING; /* only enable the requested features for this uffd context */ ctx->features = uffd_ctx_features(features); - ret = 0; -out: - return ret; + return 0; + err_out: memset(&uffdio_api, 0, sizeof(uffdio_api)); if (copy_to_user(buf, &uffdio_api, sizeof(uffdio_api))) - ret = -EFAULT; - goto out; + return -EFAULT; + return ret; } static long userfaultfd_ioctl(struct file *file, unsigned cmd,