From patchwork Wed May 16 05:43:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 10402647 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1D55E601D2 for ; Wed, 16 May 2018 05:45:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0C0FA28733 for ; Wed, 16 May 2018 05:45:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F1ED528761; Wed, 16 May 2018 05:45:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8BF3528733 for ; Wed, 16 May 2018 05:45:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4CE216B02F2; Wed, 16 May 2018 01:44:56 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 427AE6B02F5; Wed, 16 May 2018 01:44:56 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2A1556B02F6; Wed, 16 May 2018 01:44:56 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pg0-f72.google.com (mail-pg0-f72.google.com [74.125.83.72]) by kanga.kvack.org (Postfix) with ESMTP id D891C6B02F2 for ; Wed, 16 May 2018 01:44:55 -0400 (EDT) Received: by mail-pg0-f72.google.com with SMTP id m4-v6so1318317pgu.5 for ; Tue, 15 May 2018 22:44:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references; bh=SheFcqGfvk/YxMRUbgKBwrFwjOkmf851m/OvKfa2+sA=; b=EUSDjmmjqa9QIJ7skY5TXpARVRb8yAzLPMxlZKUatX/MHTFLJbIav0bsm8Qq63W3Wj UAbCg8LPhlFtaRy8os9zQTKPXx8edD6PyJw0D2G425Fe+kA4dYsOu1R2ysrtsz2bVqM1 XUte9f1wxkgZUF4ZRj8VTS6g1YiGJZ/1xdLSDnjIffFZt+uzeHRV12e7vogAwHDfJXTn btGz1s9Qs2Ve25DUGo1kGSUXpOSkLn+vQF1nDWwjT8XTvbKW4+Zl+bgUVOUHCjDrbU/d 5kcbWuGiJzJJKReb0exernWV4KL5GSUBpTbHcQB+lqpPHwlyCWC79kf9P+2wyOgBQIs3 oSlg== X-Gm-Message-State: ALKqPwc0qPcLsN1IXYRTjnhn7qs8oLFWWQ0M4FBgRM/SjFJZyzIpzbIK k231vZbS+t++VTsWVs3c5MU3RezTIsxpkwuVueorWqT0aPx0OCbMLXS36xCQp1uqbF39uYA7MTd SGr/e5Ysit+a9NTsGJQLqVSUruTHf0eK/d33kGnLKaPYLThVUP+C2QzY5iWVWZCY= X-Received: by 2002:a17:902:5409:: with SMTP id d9-v6mr17512987pli.1.1526449495581; Tue, 15 May 2018 22:44:55 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrK8MjLnuCcZmEvxKqssgSjlV+3cmXeYeckEB3Zl42JSJp4GpmAaVGN/E/tTqaCi/LMGbxi X-Received: by 2002:a17:902:5409:: with SMTP id d9-v6mr17512955pli.1.1526449494912; Tue, 15 May 2018 22:44:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526449494; cv=none; d=google.com; s=arc-20160816; b=vJuFVUGh7aBnCxNlu7XOdr4tpyR8V3jespJmVwynWPJHd1iaxNAaDzXVdkADlPKhZU PYQlJiKVITd3PJtluN2OEzeOhaDMGDGeeyKvUCjCsASjo8pzKtQ3SofT12V/fTgck6TB zTJgqeBRWRXlej5NtL3zMHbJxkFlPPaCiKyT+/FcV3HwXQ08pYFz1JOm8+OGQL1k/xUr o5XY9RJYzPJWZba5UJJLLEiRPnok4U7PF92GaQ8N0jJqQHdaOxUgym2gGRxHgl7VDzd8 eTEVGci7D1mIu/fxrL0DxdWCx3/IttNm7NmlZ0IOaXwLxHOA1BQqLm5TbYtIGFIvgyy1 Qjig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=SheFcqGfvk/YxMRUbgKBwrFwjOkmf851m/OvKfa2+sA=; b=mQ1SArlXNy1S+UYDtBhHJ3ahP5wgHrzHL7Hol2kvBs94T0/+MNPzE0ybn1FSFIUxlD CZCgLQZ+pEmPghBhJ7N1YFVpws5+kDuMqL8rPbKG2prd1Muib+r4x5kHuBzq0tfebC73 CRbWDmqTZ02niRGzWCmVGIrVP8uMRqI37kNiS9rXs9k0atFzM1KNkrunbMdFicLoM5LG rceAue2ISZ5acpnHHLuoGQPxZ9TMNg0kf4iYrEw1pZcenndq6ynl8QmU72Rl0m/juHT5 JHWD4bc5WcWUBL/RRyy+/PkIRn7M5XA4orW47BPu8pb2AGbrV7FRtEPYzW8cBDtwu7+k 7jdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=Qs4iInHn; spf=pass (google.com: best guess record for domain of batv+8c5add14d4fec8f33fc9+5379+infradead.org+hch@bombadil.srs.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=BATV+8c5add14d4fec8f33fc9+5379+infradead.org+hch@bombadil.srs.infradead.org Received: from bombadil.infradead.org (bombadil.infradead.org. [2607:7c80:54:e::133]) by mx.google.com with ESMTPS id q28-v6si1908275pfl.317.2018.05.15.22.44.54 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 15 May 2018 22:44:54 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of batv+8c5add14d4fec8f33fc9+5379+infradead.org+hch@bombadil.srs.infradead.org designates 2607:7c80:54:e::133 as permitted sender) client-ip=2607:7c80:54:e::133; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=bombadil.20170209 header.b=Qs4iInHn; spf=pass (google.com: best guess record for domain of batv+8c5add14d4fec8f33fc9+5379+infradead.org+hch@bombadil.srs.infradead.org designates 2607:7c80:54:e::133 as permitted sender) smtp.mailfrom=BATV+8c5add14d4fec8f33fc9+5379+infradead.org+hch@bombadil.srs.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=References:In-Reply-To:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=SheFcqGfvk/YxMRUbgKBwrFwjOkmf851m/OvKfa2+sA=; b=Qs4iInHnKeEVYR/LHZA5u+aTV xikTmEBnkb6U688POi0VgJ6mcqM0oCbXFf/7E2IpxE+7sE1u6elFViVCtWXNzWg3HbjWLfccZC3RW bqKbo/Ptw7rPQ8CNFyP2QX+VwrjSFLMd5F4EIS/YNVNLnE+3olJzq5JtRQ3TGTz8n2uTxuhSvwbES s86tqE+Fc6pBVOClU09ssu7R9xV5/AIHJQhjc7itOOGhuIYjRIf/V0AyBV7nfyEfMOArMX3bCWhWW zfhlhvSsgKUjs+LyaKKHB92qxIlTEEFvyAGcWV3VYgFIk4tD6qcmYPHdDFpJpfQ+kR8BCrdR3VrfV SVI0qfp/Q==; Received: from [93.83.86.253] (helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1fIpEf-0008Bu-UZ; Wed, 16 May 2018 05:44:26 +0000 From: Christoph Hellwig To: Souptick Joarder , Matthew Wilcox Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, devel@lists.orangefs.org, ceph-devel@vger.kernel.org, linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org, ocfs2-devel@oss.oracle.com, linux-mtd@lists.infradead.org, dri-devel@lists.freedesktop.org, lustre-devel@lists.lustre.org, linux-arm-kernel@lists.infradead.org, linux-s390@vger.kernel.org Subject: [PATCH 10/14] vgem: separate errno from VM_FAULT_* values Date: Wed, 16 May 2018 07:43:44 +0200 Message-Id: <20180516054348.15950-11-hch@lst.de> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180516054348.15950-1-hch@lst.de> References: <20180516054348.15950-1-hch@lst.de> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: X-Virus-Scanned: ClamAV using ClamSMTP And streamline the code in vgem_fault with early returns so that it is a little bit more readable. Signed-off-by: Christoph Hellwig Reviewed-by: Daniel Vetter --- drivers/gpu/drm/vgem/vgem_drv.c | 51 +++++++++++++++------------------ 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/drivers/gpu/drm/vgem/vgem_drv.c b/drivers/gpu/drm/vgem/vgem_drv.c index 2524ff116f00..a261e0aab83a 100644 --- a/drivers/gpu/drm/vgem/vgem_drv.c +++ b/drivers/gpu/drm/vgem/vgem_drv.c @@ -61,12 +61,13 @@ static void vgem_gem_free_object(struct drm_gem_object *obj) kfree(vgem_obj); } -static int vgem_gem_fault(struct vm_fault *vmf) +static vm_fault_t vgem_gem_fault(struct vm_fault *vmf) { struct vm_area_struct *vma = vmf->vma; struct drm_vgem_gem_object *obj = vma->vm_private_data; /* We don't use vmf->pgoff since that has the fake offset */ unsigned long vaddr = vmf->address; + struct page *page; int ret; loff_t num_pages; pgoff_t page_offset; @@ -85,35 +86,29 @@ static int vgem_gem_fault(struct vm_fault *vmf) ret = 0; } mutex_unlock(&obj->pages_lock); - if (ret) { - struct page *page; - - page = shmem_read_mapping_page( - file_inode(obj->base.filp)->i_mapping, - page_offset); - if (!IS_ERR(page)) { - vmf->page = page; - ret = 0; - } else switch (PTR_ERR(page)) { - case -ENOSPC: - case -ENOMEM: - ret = VM_FAULT_OOM; - break; - case -EBUSY: - ret = VM_FAULT_RETRY; - break; - case -EFAULT: - case -EINVAL: - ret = VM_FAULT_SIGBUS; - break; - default: - WARN_ON(PTR_ERR(page)); - ret = VM_FAULT_SIGBUS; - break; - } + if (!ret) + return 0; + + page = shmem_read_mapping_page(file_inode(obj->base.filp)->i_mapping, + page_offset); + if (!IS_ERR(page)) { + vmf->page = page; + return 0; + } + switch (PTR_ERR(page)) { + case -ENOSPC: + case -ENOMEM: + return VM_FAULT_OOM; + case -EBUSY: + return VM_FAULT_RETRY; + case -EFAULT: + case -EINVAL: + return VM_FAULT_SIGBUS; + default: + WARN_ON(PTR_ERR(page)); + return VM_FAULT_SIGBUS; } - return ret; } static const struct vm_operations_struct vgem_gem_vm_ops = {